home *** CD-ROM | disk | FTP | other *** search
/ Global Amiga Experience / globalamigaexperience.iso / compressed / development / heliosdemodisk3.dms / heliosdemodisk3.adf / Source / Demo6_SimpleAnim.src < prev    next >
Text File  |  1995-01-24  |  28KB  |  964 lines

  1.  
  2.   \ ***********************************************************
  3.   \
  4.   \                    SIMPLE ANIMATION DEMO
  5.   \
  6.   \ ***********************************************************
  7.   \
  8.   \ This code demonstrates how to create a simple animation
  9.   \ in HeliOS.
  10.   \
  11.   \ This builds upon the following Demos:
  12.   \
  13.   \ Demo1_SinglePF.src
  14.   \ Demo2_SinglePFCopper.src
  15.   \ Demo3_SimpleSprite.src
  16.   \ Demo4_MultiSprites.src
  17.   \ Demo5_MultiSptCollide.src
  18.   \
  19.   \ This code is then expanded in the following Demos:
  20.   \
  21.   \ Demo7_MultiAnim.src
  22.   \
  23.   \ ***********************************************************
  24.  
  25.  
  26.  
  27.   \ ***********************************************************
  28.   \ Re-initialise HeliOS dictionary to standard CORE vocabulary
  29.   \ ***********************************************************
  30.  
  31.   \ This should always be used at the start of any program which
  32.   \ is to be repeatedly recompiled.
  33.  
  34.   FORGET **CORE**
  35.  
  36.   \ *************************
  37.   \ Load include symbol files
  38.   \ *************************
  39.   \
  40.   \ These "include files" are pre-compiled (for speed) versions of the
  41.   \ Amiga includes and the Helios system includes.
  42.   \
  43.   \ Uncomment the lines below for standalone compilation, but otherwise
  44.   \ it is better to set these include files from the Helios Forth menus
  45.  
  46.   AMIGAINCLUDE Helios:Amiga_Include
  47.   USERINCLUDE  Helios:Helios_Include
  48.  
  49.   \ ****************************************
  50.   \ Create display imagery file name strings
  51.   \ ****************************************
  52.  
  53.   \ These files are ordinary IFF's (and may be "PowerPacked" if required)
  54.   \
  55.   \ The pictures here will be loaded into each of the display BitMaps.
  56.   \
  57.  
  58.   $CONSTANTL Slice1Pic $Helios:Source/Data/Pic1$
  59.  
  60.   \ **************************************
  61.   \ Create display configuration constants
  62.   \ **************************************
  63.   \
  64.   \ Collect all "display-specific" parameters here and generate "named"
  65.   \ constants which make references easier than using numeric values.
  66.   \
  67.   \ Collecting these together here makes it easier to adjust things at any
  68.   \ time without having to search source code to replace values individually.
  69.   \
  70.  
  71.  
  72.   256                      CONSTANT DisplayHeight      \ Full PAL display
  73.   320                      CONSTANT DisplayWidth       \ Lores display
  74.   44                       CONSTANT DisplayTopLine     \ Display start
  75.  
  76.   DisplayWidth             CONSTANT Slice1Width        \ Lores width
  77.   DisplayWidth 32 +        CONSTANT Slice1RasterWidth  \ Raster=SWidth+32
  78.   DisplayHeight            CONSTANT Slice1Height       \ Slice height
  79.   DisplayHeight 32 +       CONSTANT Slice1RasterHeight \ Slice Raster=DHgt+32
  80.   0                        CONSTANT Slice1Mode         \ Lores
  81.   3                        CONSTANT Slice1Planes       \ Slice bitplanes
  82.  
  83.   \ The calculation below takes the number of bitplanes and calculates
  84.   \ how many colours this represents.
  85.   \
  86.   \ One bitplane gives two colours.
  87.   \
  88.   \ Each additional bitplane multiplies the number of colours by two.
  89.   \
  90.   \ Performing a single LSL operation on any number multipies by 2, so we
  91.   \ have a quick method of multiplying by two for our colour calculation.
  92.   \
  93.   \ In this case, we need "2 to the power 3", which is 2*2*2=8.
  94.   \
  95.   \ e.g.                              2*2*2
  96.   \                                   ^ ^ ^
  97.   \                                   Total number of planes = 3
  98.   \
  99.   \
  100.   \ So, we take the first value two
  101.   \
  102.   \ e.g.                              2*2*2
  103.   \                                   ^
  104.   \                                  Initial start value of 2
  105.   \
  106.   \ and we now need to multiply it by two "the_number_of_planes minus_one"
  107.   \ more times.
  108.   \
  109.   \ e.g.                              2*2*2
  110.   \                                     ^ ^
  111.   \                                     Total planes minus one
  112.   \
  113.   \
  114.   \ So, Number of colours = 2 operated on by LSL NumberOfPlanes-1 times.
  115.   \
  116.  
  117.   2 Slice1Planes 1- LSL    CONSTANT Slice1Colours      \ A-slice colours
  118.  
  119.   \ ***********************
  120.   \ Error handling routines
  121.   \ ***********************
  122.  
  123.   \ This error handler allows all errors to be routed via a comprehensive
  124.   \ sequential closedown routine, which is associated with the HeliOS
  125.   \ system error handler word ERROR".
  126.   \
  127.   \ When ERROR" senses an error, it prints an associated error message
  128.   \ delimited by '"' characters, and then closes everything down using the
  129.   \ routine CLOSEDOWN below which you have supplied.
  130.   \
  131.   \ This simplifies errors checks to the use of a single word, ERROR", which
  132.   \ displays a text message and closes eveything down.
  133.   \
  134.  
  135.   0 VARIABLE (CLOSEDOWN)
  136.  
  137.   : ?CLOSEDOWNERROR
  138.  
  139.   IF
  140.     CR
  141.     CR
  142.     TYPE
  143.     CR
  144.     CR
  145.     ." Press <Space> to quit!"
  146.     CR
  147.     CR
  148.     WAITSPACE
  149.     (CLOSEDOWN) @EXECUTE
  150.     QUIT
  151.   ELSE
  152.     DDROP
  153.   THEN
  154.   ;
  155.  
  156.   LATESTCFA VARIABLE ERROR1
  157.  
  158.   \ ****************************************
  159.   \ Create display pointer storage variables
  160.   \ ****************************************
  161.  
  162.   \ Here we create a set of "pointers", initially set to a "null" value.
  163.   \
  164.   \ These "pointers" are set up as "long addresses" when various components
  165.   \ of the display system are allocated and initialised.
  166.   \
  167.   \ Note that initially these are all set to zero, and we clear them back
  168.   \ to zero when we de-allocate the associated resource.
  169.   \
  170.   \ These DPOINTERs are all initially set to "null" by using 'D0'.
  171.   \
  172.   \ When we allocate memory or Amiga system resources in the program at
  173.   \ run-time, these pointers are updated to contain the 32-bit address
  174.   \ of the newly allocated resource.
  175.   \
  176.   \ Subsequently the symbolic DPOINTER name can be used in your code to
  177.   \ represent the associated address.
  178.  
  179.   D0 DPOINTER Display1             \ Main Display structure pointer
  180.   D0 DPOINTER Slice1               \ Slice 1 Slice structure pointer
  181.  
  182.   D0 DPOINTER Slice1_ColorMap      \ Slice 1 ColourMap structure pointer
  183.  
  184.   D0 DPOINTER Slice1_RasInfo       \ Slice 1 RasInfo structure pointer
  185.  
  186.   D0 DPOINTER Slice1_BMap          \ Slice 1 BitMap structure pointer
  187.  
  188.   D0 DPOINTER Slice1_SliceControl  \ Slice 1 SliceControl structure pointer
  189.  
  190.   \ *************
  191.   \ Colour tables
  192.   \ *************
  193.  
  194.   \ Each colour entry requies 2 bytes of storage space
  195.  
  196.   CREATEL Slice1_ColorTable        \ Create longword pointer to table
  197.   Slice1Colours 2* 0 ALLOTFILL     \ Allocate Slice1 colours * 2 bytes
  198.  
  199.  
  200.   \ *************************************
  201.   \ Copper strip for graduated background
  202.   \ *************************************
  203.  
  204.   D0 DVARIABLE Copper              \ 32-bit CopperList pointer store
  205.   D0 DVARIABLE CopperLength        \ 32-bit CopperList length store
  206.  
  207.   : AddCopper                      \ Add custom copper list to display
  208.  
  209.   Display1                         \ We are adding CopperList to Display1
  210.   Copper D@
  211.   ADDCOPPERSTRIP
  212.   SORTSTRIPTABLE
  213.   LINKSTRIPS
  214.   DDROP
  215.   ;
  216.  
  217.   : RemCopper                      \ Remove custom copper list from display
  218.  
  219.   Display1                         \ We are removing CopperList from Display1
  220.   Copper D@
  221.   REMCOPPERSTRIP
  222.   LINKSTRIPS
  223.   DDROP
  224.   ;
  225.  
  226.   : Create_Copper
  227.  
  228.   COPPERSTART
  229.   Copper D!
  230.   0 [ DECIMAL ]  45 [ HEX ] FFFE COPPERWAIT  DROP   0100 18E COPPERMOVE  DROP
  231.   0 [ DECIMAL ]  60 [ HEX ] FFFE COPPERWAIT  DROP   0200 18E COPPERMOVE  DROP
  232.   0 [ DECIMAL ]  75 [ HEX ] FFFE COPPERWAIT  DROP   0300 18E COPPERMOVE  DROP
  233.   0 [ DECIMAL ]  90 [ HEX ] FFFE COPPERWAIT  DROP   0400 18E COPPERMOVE  DROP
  234.   0 [ DECIMAL ] 105 [ HEX ] FFFE COPPERWAIT  DROP   0500 18E COPPERMOVE  DROP
  235.   0 [ DECIMAL ] 120 [ HEX ] FFFE COPPERWAIT  DROP   0600 18E COPPERMOVE  DROP
  236.   0 [ DECIMAL ] 135 [ HEX ] FFFE COPPERWAIT  DROP   0700 18E COPPERMOVE  DROP
  237.   0 [ DECIMAL ] 150 [ HEX ] FFFE COPPERWAIT  DROP   0800 18E COPPERMOVE  DROP
  238.   0 [ DECIMAL ] 165 [ HEX ] FFFE COPPERWAIT  DROP   0900 18E COPPERMOVE  DROP
  239.   0 [ DECIMAL ] 180 [ HEX ] FFFE COPPERWAIT  DROP   0A00 18E COPPERMOVE  DROP
  240.   0 [ DECIMAL ] 195 [ HEX ] FFFE COPPERWAIT  DROP   0B00 18E COPPERMOVE  DROP
  241.   0 [ DECIMAL ] 210 [ HEX ] FFFE COPPERWAIT  DROP   0C00 18E COPPERMOVE  DROP
  242.   0 [ DECIMAL ] 225 [ HEX ] FFFE COPPERWAIT  DROP   0D00 18E COPPERMOVE  DROP
  243.   0 [ DECIMAL ] 240 [ HEX ] FFFE COPPERWAIT  DROP   0E00 18E COPPERMOVE  DROP
  244.   0 [ DECIMAL ] 255 [ HEX ] FFFE COPPERWAIT  DROP   0F00 18E COPPERMOVE  DROP
  245.   [ DECIMAL ]
  246.   COPPEREND
  247.   CopperLength D!   Copper D!
  248.   ADDCOPPER
  249.   ;
  250.  
  251.   : Free_Copper                  \ Closes down and frees copperlist memory
  252.  
  253.   RemCopper
  254.   Copper D@ FREEMEMORY
  255.   ;
  256.  
  257.   \ ***********************************
  258.   \ Create Display and Slice structures
  259.   \ ***********************************
  260.  
  261.   \ This routine simply makes blank structures, which then need to be
  262.   \ initialised later (in the CREATE_DISPLAY routine).
  263.  
  264.   : CREATE_DSLICES
  265.  
  266.   DS_SIZEOF MAKESTRUCTURE Display1 MAKEPOINTER  \ Main "Display" structure
  267.  
  268.   SL_SIZEOF MAKESTRUCTURE Slice1   MAKEPOINTER  \ Display "Slice" structure
  269.   ;
  270.  
  271.   : FREE_DSLICES
  272.  
  273.   Slice1    DDUP FREEMEMORY   CLEARPOINTER
  274.   Display1  DDUP FREEMEMORY   CLEARPOINTER
  275.   ;
  276.  
  277.   \ ******************************
  278.   \ Create RasInfo structures etc.
  279.   \ ******************************
  280.  
  281.   : CREATE_RASINFO
  282.  
  283.   \ First allocate and initialise complete RasInfo structures.
  284.   \
  285.   \ This routine automatically allocates all BitMaps etc.
  286.   \
  287.  
  288.   Slice1RasterWidth Slice1RasterHeight Slice1Planes  OPENRASINFO
  289.   DFLAG0= ERROR" Fail: RasInfo1"
  290.   Slice1_RasInfo MAKEPOINTER
  291.  
  292.   \ Set invisible area "sprite margins" for slice RasInfo
  293.  
  294.   16              Slice1_RasInfo         ri_RxOffset    INDEX!L
  295.   16              Slice1_RasInfo         ri_RyOffset    INDEX!L
  296.  
  297.   \ Store BitMap pointer - often useful for later reference
  298.  
  299.   Slice1_RasInfo  ri_BitMap INDEXD@L Slice1_BMap MAKEPOINTER
  300.   ;
  301.  
  302.   : FREE_RASINFO
  303.  
  304.   Slice1_RasInfo   DDUP CLOSERASINFO   CLEARPOINTER
  305.   ;
  306.  
  307.   \ ********************************
  308.   \ Create Display/Slice Copperlists
  309.   \ ********************************
  310.  
  311.   \ This function builds the main display copperlist by:
  312.   \
  313.   \ 1. Initialising the Slice data structure
  314.   \ 2. Calling MAKECOPSTRIP for the slice, to build a copperlist
  315.   \ 3. Calling MAKEDISPLAY to build the master Display copperlist
  316.   \
  317.  
  318.   : CREATE_DISPLAY
  319.  
  320.   \ First initialise main display structures
  321.  
  322.   Slice1                           Display1  DS_Slice     INDEXD!L
  323.  
  324.   Slice1Width                      Slice1    SL_DWidth    INDEX!L
  325.   Slice1Height                     Slice1    SL_DHeight   INDEX!L
  326.   DisplayTopLine                   Slice1    SL_DyOffset  INDEX!L
  327.   Slice1_RasInfo                   Slice1    SL_RasInfo   INDEXD!L
  328.   Slice1_ColorMap                  Slice1    SL_ColorMap  INDEXD!L
  329.   Slice1Mode                       Slice1    SL_Modes     INDEX!L
  330.  
  331.   \ Generate copper list information for each of the display slices
  332.  
  333.   Slice1 MAKECOPSTRIP
  334.   D0= ERROR" Fail: Slice1CopStrip"
  335.  
  336.   \ Make display
  337.  
  338.   Display1 MAKEDISPLAY
  339.   D0= ERROR" Fail: Display1"
  340.   ;
  341.  
  342.   : FREE_DISPLAY
  343.  
  344.   Display1                 FREEDISPLAY
  345.   Slice1                   FREECOPSTRIP
  346.   ;
  347.  
  348.   \ ********************************************************
  349.   \ Create SliceControl structures for double buffered slice
  350.   \ ********************************************************
  351.  
  352.   \ SliceControl structures are used to control any slices which perform
  353.   \ mapping or scrolling functions, or which require double or triple
  354.   \ playfield buffering.
  355.   \
  356.   \ In this case we have one slice which does not scroll, is not mapped,
  357.   \ but IS double buffered.
  358.   \
  359.  
  360.   : CREATE_SLICECONTROL
  361.  
  362.   \ Make SliceControl for double buffered bitmap display
  363.  
  364.   Slice1  0 0 MAKESLICECONTROL
  365.   DFLAG0= ERROR" Fail: SliceControl1"
  366.   Slice1_SliceControl MAKEPOINTER
  367.  
  368.   \ Install slice controls into HeliOS display control system
  369.  
  370.   Slice1_SliceControl  INSTALLSLICECONTROL
  371.   ;
  372.  
  373.   : FREE_SLICECONTROL
  374.  
  375.   CLEARSLICECONTROLS
  376.   Slice1_SliceControl  CLOSESLICECONTROL
  377.   ;
  378.  
  379.   \ These routines load an IFF picture into supplied BitMap, and correctly
  380.   \ initialises the supplied ColorTable.
  381.   \
  382.   \ The ColorTable is then used to create an initialised ColorMap structure.
  383.   \
  384.  
  385.   : CREATE_IMAGERY
  386.  
  387.   Slice1_BMap
  388.   Slice1_ColorTable
  389.   Slice1Pic
  390.   10 2 DOSLIB                        \ Call to internal HeliOS library
  391.   10 <> ERROR" Fail: Slice1Pic"
  392.  
  393.   Slice1_ColorTable  Slice1Colours MAKECOLORMAP  \ Allocate ColourMap
  394.   DFLAG0= ERROR" Fail: Slice1ColorMap"
  395.   Slice1_ColorMap MAKEPOINTER
  396.   ;
  397.  
  398.   : FREE_IMAGERY
  399.  
  400.   Slice1_ColorMap  DDUP FREECOLORMAP  CLEARPOINTER
  401.   ;
  402.  
  403.   \ **************
  404.   \ Animation Demo
  405.   \ **************
  406.  
  407.   \ ************************
  408.   \ Animation Demo constants
  409.   \ ************************
  410.  
  411.   \ Set up a number of constants which determine various aspects of the
  412.   \ demo, e.g. How many Bullets required
  413.   \
  414.   \ Change these values as required
  415.   \
  416.  
  417.   25 CONSTANT Bullet#           \ Number of Bullets available
  418.   8  CONSTANT BulletSpeed       \ Speed of Bullet
  419.   6  CONSTANT FiringRate        \ Speed of gun reload
  420.   4  CONSTANT GunSpeed          \ Speed of Gun movement
  421.   8  CONSTANT AlienMaxXSpeed    \ Maximum speed of Alien movement
  422.   4  CONSTANT AlienMaxYSpeed    \ Maximum speed of Alien movement
  423.  
  424.   \ ****************************************************
  425.   \ Create animation demo pointers and storage variables
  426.   \ ****************************************************
  427.  
  428.   D0 DPOINTER GunSpriteSet         \ Gun sprite image
  429.   D0 DPOINTER BulletSpriteSet      \ Bullet sprite image
  430.   D0 DPOINTER AlienSpriteSet       \ Alien sprite images
  431.   D0 DPOINTER AlienAnim            \ Alien animation
  432.  
  433.   CREATE BulletTable               \ Bullet sprite pointer storage table.
  434.   Bullet# 4* 0 ALLOTFILL           \ Space allocated = Number_of_Bullets*4
  435.                                    \ This table has to hold a number of
  436.                                    \ 32-bit (4-byte) numbers, because
  437.                                    \ each Bullet sprite is a 32-bit pointer
  438.  
  439.   CREATE  BulletCollHandlerTable   \ Bullet collision handler table
  440.   Bullet# 4* 0 ALLOTFILL
  441.  
  442.   D0  DVARIABLE  AlienCollHandler  \ Alien collision handler pointer
  443.   0 VARIABLE     FireTimer         \ Gun reload rate store
  444.  
  445.  \ **************************************************
  446.  \ This routine is called to delay the Alien's return
  447.  \ **************************************************
  448.  
  449.   : AlienDelay
  450.  
  451.   DDROP                                            \ Drop Alien pointer
  452.   50  SpriteAnim_CountDown   AlienAnim INDEX!L     \ Wait 50 VBlanks
  453.   0   SpriteAnim_CDForth     AlienAnim INDEX!L     \ Remove CD action word
  454.   -3  SpriteAnim_CDFlags     AlienAnim INDEX!L     \ -3 = Remove
  455.   ;
  456.  
  457.   \ *************************
  458.   \ Sprite collision routines
  459.   \ *************************
  460.  
  461.   \ This routine is called when a Bullet collides.
  462.  
  463.   : BulletHit
  464.  
  465.   2 DDROPS                        \ Drop collisionmask and hit-object pointer
  466.  
  467.   DDUP SpriteCtrl_CollFlag D+ 0!L \ Disable further collisions
  468.   REMOVESPRITE                    \ Remove Bullet
  469.   ;
  470.  
  471.   \ This routine is called when the Alien collides.
  472.  
  473.   : AlienHit
  474.  
  475.   3 DDROPS     \ Drop collisionmask, "hitting" object, and object pointers
  476.  
  477.   0   SpriteAnim_CollFlag    AlienAnim INDEX!L  \ Disable further collisions
  478.   0   SpriteAnim_UserData1   AlienAnim INDEX!L  \ Stop X-movement (inc = 0)
  479.   0   SpriteAnim_UserData2   AlienAnim INDEX!L  \ Stop Y-movement (inc = 0)
  480.   2   SpriteAnim_Speed       AlienAnim INDEX!L  \ Set explosion anim speed
  481.   9   SpriteAnim_Frames      AlienAnim INDEX!L  \ Number of frames
  482.   0   SpriteAnim_Current     AlienAnim INDEX!L  \ Start at frame 0
  483.   20  SpriteAnim_CountDown   AlienAnim INDEX!L  \ Run for 20 VBlanks
  484.   -2  SpriteAnim_CDFlags     AlienAnim INDEX!L  \ Flags set after CountDown
  485.                                                 \ -2 = Go invisible
  486.  
  487.   ' AlienDelay  CFA                             \ Get pointer to delay code
  488.       SpriteAnim_CDForth     AlienAnim INDEX!L  \ Countdown code
  489.   ;
  490.  
  491.   \ ***************************
  492.   \ Create HitMasks and MeMasks
  493.   \ ***************************
  494.  
  495.   \ Collisions can only occur between objects which have coincident bits
  496.   \ set in HitMask-MeMask or MeMask-HitMask pairs
  497.   \
  498.   \ Each bit of the HitMask/MeMask pair have a corresponding position in
  499.   \ a collision table which stores an array of collision routines.
  500.   \
  501.   \ In the event of a collision, the routine in an object's Collision Table
  502.   \ corresponding to the HitMask-MeMask bit coincidence will be called
  503.   \ with 3 parameters: the two colliding objects and the collision HitMask
  504.   \
  505.   \ The stack on a collision call looks like this:
  506.   \
  507.   \ CollisionHitMask(l) = Top 32-bit value on stack
  508.   \ CollidingObject(l)  = 2nd 32-bit value on stack
  509.   \ This Object(l)      = 3rd 32-bit value on stack
  510.   \
  511.   \ Here are two examples:
  512.   \
  513.   \   00000000000000000000000000000010.  = Object A HitMask
  514.   \   00000000000000000000000000000000.  = Object B HitMask
  515.   \   00000000000000000000000000000001.  = Object C HitMask
  516.   \
  517.   \   00000000000000000000000000000000.  = Object A MeMask
  518.   \   00000000000000000000000000000011.  = Object B MeMask
  519.   \   00000000000000000000000000000000.  = Object C MeMask
  520.   \
  521.   \ Would allow A and B to collide, B and C to collide, but not A and C.
  522.   \
  523.   \ B and C would run the routine at position 1 in the collision table
  524.   \ A and B would run the routine at position 2 in the collision table
  525.   \
  526.   \ -----------------------------------------------------------
  527.   \
  528.   \   00000000000000000000000000000011.  = Object A HitMask
  529.   \   00000000000000000000000000000001.  = Object B HitMask
  530.   \   00000000000000000000000000000001.  = Object C HitMask
  531.   \
  532.   \   00000000000000000000000000000000.  = Object A MeMask
  533.   \   00000000000000000000000000000000.  = Object B MeMask
  534.   \   00000000000000000000000000000010.  = Object C MeMask
  535.   \
  536.   \ Would allow just A and C to collide
  537.   \
  538.   \ A and C would run the routine at position 2 in the collision table
  539.   \
  540.  
  541.   BIN
  542.  
  543.   00000000000000000000000000000001.  DCONSTANT  BulletHitMask
  544.   00000000000000000000000000000000.  DCONSTANT  AlienHitMask
  545.  
  546.   00000000000000000000000000000000.  DCONSTANT  BulletMeMask
  547.   00000000000000000000000000000001.  DCONSTANT  AlienMeMask
  548.  
  549.   DECIMAL
  550.  
  551.  
  552.   CREATEL BulletCollTable
  553.   -1 ,                        \ -1 = The "1" means there is 1 entry in table
  554.                               \      The "-" signifies that it is a HeliOS
  555.                               \      word rather than machine code
  556.  
  557.   FIND BulletHit ,            \ Find BulletHit and store HeliOS word CFA
  558.  
  559.   CREATEL AlienCollTable
  560.   -1 ,                        \ -1 = The "1" means there is 1 entry in table
  561.                               \      The "-" signifies that it is a HeliOS
  562.                               \      word rather than machine code
  563.  
  564.   FIND AlienHit ,             \ Find AlienHit and store HeliOS word CFA
  565.  
  566.  
  567.   \ *************************
  568.   \ Set up collision handlers
  569.   \ *************************
  570.  
  571.   : CREATE_COLLISIONS
  572.  
  573.   Bullet# 0
  574.   DO
  575.     GETCOLLHANDLER
  576.     DFLAG0= ERROR" Fail: Bullet CollHandler"
  577.     DDUP BulletCollHandlerTable I 4* + D!
  578.     BulletTable I 4* + D@  SpriteCtrl_CollHandler  INDEXD!L
  579.   LOOP
  580.  
  581.   GETCOLLHANDLER
  582.   DFLAG0= ERROR" Fail: Alien CollHandler"
  583.   DDUP AlienCollHandler D!
  584.   AlienAnim SpriteAnim_CollHandler  INDEXD!L
  585.   ;
  586.  
  587.   : FREE_COLLISIONS
  588.  
  589.   AlienCollHandler D@ FREECOLLHANDLER
  590.   Bullet# 0
  591.   DO
  592.     Bullet# 1- I - 4*
  593.     BulletCollHandlerTable +
  594.     D@ FREECOLLHANDLER
  595.   LOOP
  596.   ;
  597.  
  598.   \ *****************
  599.   \ Boundary routines
  600.   \ *****************
  601.  
  602.   \ Alien boundary sense routine
  603.  
  604.   : AlienBoundary
  605.  
  606.   SpriteCtrl_VisiHit INDEX@L                 \ Get boundary hit mask word
  607.   0 BTST                                     \ Did it hit left boundary
  608.   IF
  609.     AlienAnim SpriteAnim_UserData1 INDEX@L   \ Reverse X-motion
  610.     NEGATE
  611.     AlienAnim SpriteAnim_UserData1 INDEX!L
  612.   ELSE
  613.     1 BTST                                   \ Did it hit right boundary
  614.     IF
  615.       AlienAnim SpriteAnim_UserData1 INDEX@L \ Reverse X-motion
  616.       NEGATE
  617.       AlienAnim SpriteAnim_UserData1 INDEX!L
  618.     THEN
  619.   THEN
  620.  
  621.   2 BTST                                     \ Did it hit upper boundary
  622.   IF
  623.     DROP
  624.     AlienAnim SpriteAnim_UserData2 INDEX@L   \ Reverse Y-motion
  625.     NEGATE
  626.     AlienAnim SpriteAnim_UserData2 INDEX!L
  627.   ELSE
  628.     3 BTST                                   \ Did it hit lower boundary
  629.     IF
  630.       DROP
  631.       AlienAnim SpriteAnim_UserData2 INDEX@L \ Reverse Y-motion
  632.       NEGATE
  633.       AlienAnim SpriteAnim_UserData2 INDEX!L
  634.     ELSE
  635.       DROP
  636.     THEN
  637.   THEN
  638.   ;
  639.  
  640.   \ Remove Bullet - called when bullet hits boundary at edge of display
  641.  
  642.   : BulletRemove
  643.  
  644.   RemoveSprite
  645.   ;
  646.  
  647.   \ ****************************
  648.   \ User input response routines
  649.   \ ****************************
  650.  
  651.   : Fire
  652.  
  653.   RAWKEY @ 64 =
  654.   JOY1FIRE OR
  655.   IF
  656.     FireTimer @ 0<
  657.     IF
  658.       FiringRate FireTimer !
  659.       Bullet# 0
  660.       DO
  661.         BulletTable I 4* + D@ SETSTRUCTURE1
  662.         SpriteCtrl_Running STRUCTURE1 @L 0=
  663.         IF
  664.           1 SpriteCtrl_Running STRUCTURE1 !L
  665.           GunSpriteSet 8. D+ D@L SETSTRUCTURE2
  666.  
  667.           SpriteCtrl_XPos STRUCTURE2 @L 5 +
  668.           SpriteCtrl_XPos STRUCTURE1 !L
  669.  
  670.           SpriteCtrl_YPos STRUCTURE2 @L 2 -
  671.           SpriteCtrl_YPos STRUCTURE1 !L
  672.  
  673.           SpriteCtrl_UserData1 STRUCTURE1
  674.           SpriteCtrl_YAdd STRUCTURE1 D!L
  675.  
  676.           BulletSpeed NEGATE SpriteCtrl_UserData1 STRUCTURE1 !L
  677.  
  678.           1 SpriteCtrl_CollFlag STRUCTURE1 !L
  679.           1 SpriteCtrl_Flags STRUCTURE1 !L
  680.  
  681.           D0 STRUCTURE1 INSTALLSPRITE
  682.           LEAVE
  683.         THEN
  684.       LOOP
  685.     ELSE
  686.       FireTimer DEC
  687.     THEN
  688.   THEN
  689.   ;
  690.  
  691.   : MoveGun
  692.  
  693.   RAWKEY @ 78 =
  694.   JOY1LEFTRIGHT 0>
  695.   OR
  696.   IF
  697.      GunSpeed
  698.      19 320
  699.      GunSpriteSet 8. D+ D@L SpriteCtrl_XPos D+
  700.      LIMIT+!L
  701.   ELSE
  702.     RAWKEY @ 79 =
  703.     JOY1LEFTRIGHT 0<
  704.     OR
  705.     IF
  706.      GunSpeed NEGATE
  707.      19 320
  708.      GunSpriteSet 8. D+ D@L SpriteCtrl_XPos D+
  709.      LIMIT+!L
  710.     THEN
  711.   THEN
  712.   ;
  713.  
  714.   \ ***********************************
  715.   \ Create sprite and animation objects
  716.   \ ***********************************
  717.  
  718.   : CREATE_SPRITES
  719.  
  720.   \ ----------
  721.   \ Gun sprite
  722.   \ ----------
  723.  
  724.   Slice1_BMap
  725.   154 272
  726.   13 15
  727.   1
  728.   MAKESPRITESET
  729.   DFLAG0= ERROR" Fail: Gun SpriteSet"
  730.   GunSpriteSet MAKEPOINTER
  731.  
  732.   GunSpriteSet 8. D+ D@L
  733.   DDUP  SpriteCtrl_XPos D+       170 -ROT !L
  734.         SpriteCtrl_YPos D+       239 -ROT !L
  735.  
  736.   Slice1_SliceControl   GunSpriteSet    INITSPRITESET
  737.  
  738.   \ -------------
  739.   \ Bullet sprite
  740.   \ -------------
  741.  
  742.   Slice1_BMap
  743.   159 279
  744.   3 7
  745.   1
  746.   MAKESPRITESET
  747.   DFLAG0= ERROR" Fail: Bullet SpriteSet"
  748.   BulletSpriteSet MAKEPOINTER
  749.  
  750.   Slice1_SliceControl   BulletSpriteSet    INITSPRITESET
  751.  
  752.   Bullet# 0
  753.   DO
  754.     BulletSpriteSet 8. D+ D@L CLONESPRITE
  755.     DFLAG0= ERROR" Fail: Bullet Sprite"
  756.     DDUP BulletTable I 4* + D!
  757.     SETSTRUCTURE1
  758.  
  759.     BulletCollTable        SpriteCtrl_CollTable      STRUCTURE1 D!L
  760.     BulletHitMask          SpriteCtrl_HitMask        STRUCTURE1 D!L
  761.     BulletMeMask           SpriteCtrl_MeMask         STRUCTURE1 D!L
  762.     -2                     SpriteCtrl_VisiZone       STRUCTURE1 !L
  763.     4                      SpriteCtrl_LeftZone       STRUCTURE1 !L
  764.     4                      SpriteCtrl_RightZone      STRUCTURE1 !L
  765.     4                      SpriteCtrl_UpZone         STRUCTURE1 !L
  766.     10                     SpriteCtrl_DownZone       STRUCTURE1 !L
  767.     ' BulletRemove CFA     SpriteCtrl_VisiForth      STRUCTURE1 !L
  768.   LOOP
  769.  
  770.   \ -------------
  771.   \ Alien sprites
  772.   \ -------------
  773.  
  774.   Slice1_BMap
  775.   24 276
  776.   14 9
  777.   9
  778.   MAKESPRITESET
  779.   DFLAG0= ERROR" Fail: Alien SpriteSet"
  780.   AlienSpriteSet MAKEPOINTER
  781.  
  782.   Slice1_SliceControl   AlienSpriteSet    INITSPRITESET
  783.  
  784.   \ ---------------
  785.   \ Alien animation
  786.   \ ---------------
  787.  
  788.   SpriteAnim_SIZEOF MAKESTRUCTURE
  789.   DFLAG0= ERROR" Fail: AlienAnim"
  790.   AlienAnim MAKEPOINTER
  791.  
  792.   AlienSpriteSet 8. D+  SpriteAnim_Image          AlienAnim    INDEXD!L
  793.   AlienCollTable        SpriteAnim_CollTable      AlienAnim    INDEXD!L
  794.   AlienHitMask          SpriteAnim_HitMask        AlienAnim    INDEXD!L
  795.   AlienMeMask           SpriteAnim_MeMask         AlienAnim    INDEXD!L
  796.   6                     SpriteAnim_AnimControl    AlienAnim    INDEX!L
  797.   1                     SpriteAnim_Skip           AlienAnim    INDEX!L
  798.   1                     SpriteAnim_VisiZone       AlienAnim    INDEX!L
  799.   4                     SpriteAnim_LeftZone       AlienAnim    INDEX!L
  800.   4                     SpriteAnim_RightZone      AlienAnim    INDEX!L
  801.   4                     SpriteAnim_UpZone         AlienAnim    INDEX!L
  802.   25                    SpriteAnim_DownZone       AlienAnim    INDEX!L
  803.   ' AlienBoundary CFA   SpriteAnim_VisiForth      AlienAnim    INDEX!L
  804.   SpriteAnim_UserData1 AlienAnim D+ SpriteAnim_XAdd  AlienAnim INDEXD!L
  805.   SpriteAnim_UserData2 AlienAnim D+ SpriteAnim_YAdd  AlienAnim INDEXD!L
  806.   ;
  807.  
  808.   : FREE_SPRITES
  809.  
  810.   AlienAnim       DDUP FREEMEMORY    CLEARPOINTER
  811.   AlienSpriteSet  DDUP FREESPRITESET CLEARPOINTER
  812.  
  813.   Bullet# 0
  814.   DO
  815.     Bullet# 1- I - 4* BulletTable + D@
  816.     DDUP FREESPRITE  CLEARPOINTER
  817.   LOOP
  818.  
  819.   BulletSpriteSet DDUP FREESPRITESET CLEARPOINTER
  820.   GunSpriteSet    DDUP FREESPRITESET CLEARPOINTER
  821.   ;
  822.  
  823.   \ ****************
  824.   \ Re-Install Alien
  825.   \ ****************
  826.  
  827.   : ?Install_Alien
  828.  
  829.   SpriteAnim_Running AlienAnim INDEX@L 0=
  830.   IF
  831.     0                           SpriteAnim_CDForth     AlienAnim INDEX!L
  832.     0                           SpriteAnim_CountDown   AlienAnim INDEX!L
  833.     1                           SpriteAnim_Running     AlienAnim INDEX!L
  834.     1                           SpriteAnim_Flags       AlienAnim INDEX!L
  835.     1                           SpriteAnim_CollFlag    AlienAnim INDEX!L
  836.     280 RND 26 +                SpriteAnim_XPos        AlienAnim INDEX!L
  837.     36                          SpriteAnim_YPos        AlienAnim INDEX!L
  838.     0                           SpriteAnim_Current     AlienAnim INDEX!L
  839.     2                           SpriteAnim_Speed       AlienAnim INDEX!L
  840.     4                           SpriteAnim_Frames      AlienAnim INDEX!L
  841.     AlienMaxXSpeed RND 2 MAX 1 RND IF NEGATE THEN
  842.                                 SpriteAnim_UserData1   AlienAnim INDEX!L
  843.     AlienMaxYSpeed RND 1 MAX 1 RND IF NEGATE THEN
  844.                                 SpriteAnim_UserData2   AlienAnim INDEX!L
  845.     AlienAnim INSTALLSPRITEANIM
  846.   THEN
  847.   ;
  848.  
  849.   \ *********************
  850.   \ Close down everything
  851.   \ *********************
  852.  
  853.   : CLOSEDOWN
  854.  
  855.   FREE_COLLISIONS
  856.   FREE_SPRITES
  857.   FREE_COPPER
  858.   FREE_SLICECONTROL
  859.   FREE_DISPLAY
  860.   FREE_IMAGERY
  861.   FREE_RASINFO
  862.   FREE_DSLICES
  863.   RESETERROR"
  864.   ;
  865.  
  866.   LATESTCFA (CLOSEDOWN) !
  867.  
  868.   : TestDisplay          \ Start of program
  869.  
  870.   SCRCLR
  871.   CR
  872.  
  873.   ."        ********************************************************* "
  874.   CR 6 FPENSET
  875.   ."                         SIMPLE ANIMATION DEMO"
  876.   CR 1 FPENSET
  877.   ."        ********************************************************* "
  878.   CR
  879.   ."        This code demonstrates how to create a simple animation   "
  880.   CR
  881.   ."        in HeliOS."
  882.   CR
  883.   CR
  884.   ."        This builds upon the following Demos:"
  885.   CR
  886.   CR
  887.   ."        Demo1_SinglePF.src"
  888.   CR
  889.   ."        Demo2_SinglePFCopper.src"
  890.   CR
  891.   ."        Demo3_SimpleSprite.src"
  892.   CR
  893.   ."        Demo4_MultiSprites.src"
  894.   CR
  895.   ."        Demo5_MultiSptCollide.src"
  896.   CR
  897.   CR
  898.   ."        This code is then expanded in the following Demos:"
  899.   CR
  900.   CR
  901.   ."        Demo7_MultiAnim.src"
  902.   CR
  903.   ."        **********************************************************"
  904.   CR 6 FPENSET
  905.   ."                  Press <Space> or <L-Mouse> to see Demo"
  906.   CR 3 FPENSET
  907.   ."          Use a Joystick to move the gun turret and fire bullets"
  908.   CR
  909.   ."        **********************************************************"
  910.   CR
  911.  
  912.   WAITSPACE
  913.  
  914.   SCRCLR
  915.  
  916.   ERROR1 SETERROR"       \ Redirect system errors to our routine ERROR1
  917.  
  918.   CREATE_DSLICES
  919.   CREATE_RASINFO
  920.   CREATE_IMAGERY
  921.   CREATE_DISPLAY
  922.   CREATE_SLICECONTROL
  923.   CREATE_COPPER
  924.   CREATE_SPRITES
  925.   CREATE_COLLISIONS
  926.  
  927.   HeliOS_On
  928.  
  929.   GunSpriteSet 8. D+ D@L INSTALLSPRITE
  930.  
  931.   1 FrameRate !L
  932.  
  933.   Display1 SHOWDISPLAY
  934.  
  935.   BEGIN
  936.     WAITFRAME
  937.  
  938.     ?Install_Alien
  939.  
  940.     Fire
  941.  
  942.     MoveGun
  943.  
  944.     ?TERMINAL 27 =
  945.   UNTIL
  946.  
  947.   -3 AlienAnim SpriteAnim_Flags INDEX!L
  948.  
  949.   -3 GunSpriteSet 8. D+ D@L SpriteCtrl_Flags INDEX!L
  950.  
  951.   Bullet# 0
  952.   DO
  953.     -3 BulletTable I 4* + D@ SpriteCtrl_Flags INDEX!L
  954.   LOOP
  955.  
  956.   5 DELAY
  957.  
  958.   HeliOS_Off
  959.  
  960.   CLOSEDOWN
  961.   ;
  962.  
  963.   TestDisplay
  964.