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

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