home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 63 / CDACTUAL63.iso / Aplicaciones / DarkBasic / DemoDarkBasic.exe / myproj / swarm / swarm.dba < prev    next >
Encoding:
Text File  |  2000-05-21  |  24.5 KB  |  1,162 lines

  1. Rem * Title  : DarkSWARM
  2. Rem * Author : DBS-LB
  3. Rem * Date   : 13th Feb 2000
  4. rem ********************************************
  5. rem *                DarkSWARM                 *
  6. rem ********************************************
  7. rem * AUTHOR: Lee Bamber   DATE: 13th Feb 2000 *
  8. rem ********************************************
  9.  
  10. rem Declare global arrays
  11. dim hiscore(1)
  12. dim enemy#(40,5)
  13. dim bullet#(40,5)
  14. dim explode#(10,5)
  15.  
  16. rem Initialise program
  17. sync rate 30
  18. hide mouse
  19. sync on
  20.  
  21. rem Load and play music
  22. load music "swarm.mid",1 : loop music 1
  23.  
  24. rem Load images, sounds and create game elements
  25. gosub _load_images
  26. gosub _load_sounds
  27. gosub _create_decals
  28. gosub _create_numbers
  29. gosub _create_backdrop
  30. gosub _create_player
  31. gosub _create_aliens
  32. gosub _create_bullets
  33. gosub _create_explosions
  34. gosub _create_mothership
  35.  
  36. rem Setup camera and lighting
  37. position camera 0,-40,-200
  38. set ambient light 40
  39. point camera 0,0,0
  40.  
  41. rem Load old hiscore if available
  42. load array "hiscore.dat",hiscore(0)
  43.  
  44. rem Prepare start of game message
  45. message$="GET READY"
  46. gosub _new_message
  47.  
  48. rem New game at level one
  49. level=1 : gosub _form_aliens
  50.  
  51. rem Main game loop
  52. do
  53.  
  54. rem Control message delay
  55. if messagedelay>0
  56.  
  57.     rem Decrement message delay counter
  58.     dec messagedelay
  59.  
  60.     rem When message over, reactivate game
  61.     if messagedelay=0
  62.  
  63.         rem Hide message decal
  64.         hide object 31 : position object 31,0,0,0
  65.  
  66.         rem Activate game
  67.         gameactive=1
  68.  
  69.     endif
  70.  
  71. endif
  72.  
  73. rem Control main game elements
  74. gosub _control_decals
  75. gosub _control_backdrop
  76. gosub _control_player
  77. gosub _control_aliens
  78. gosub _control_mothership    
  79. gosub _control_bullets
  80. gosub _control_explosions
  81.  
  82. rem Update screen
  83. sync
  84.  
  85. rem End of game loop
  86. loop
  87.  
  88.  
  89. rem ***********************
  90. rem * Control Subroutines *
  91. rem ***********************
  92.  
  93. _control_decals:
  94.  
  95. rem Update score and hiscore decals
  96. texture_digits(score,20,21,22,23)
  97. texture_digits(hiscore(0),24,25,26,27)
  98.  
  99. rem Control message decal
  100. if messagedelay>0
  101.  
  102.     rem Play standard message sound
  103.     if messagedelay=50
  104.         if message$="GET READY" then play sound 6 else play sound 7
  105.     endif
  106.  
  107.     rem Control angle of message decal
  108.     if messagedelay<50
  109.         ma#=0.0
  110.     else
  111.         ma#=(messagedelay-50)*2
  112.     endif
  113.  
  114.     rem Position and rotate message decal
  115.     position object 31,0,-50+sin(wrapvalue(ma#))*500,cos(wrapvalue(ma#))*500
  116.     xrotate object 31,45+(ma#*3)
  117.  
  118. endif
  119.  
  120. return
  121.  
  122. _control_backdrop:
  123.  
  124. rem Scroll star backdrop
  125. inc starscrolly#,1.0
  126. scroll backdrop 0,0-starscrolly#
  127.  
  128. rem Scroll stellar effect by sliding plain objects
  129. inc stellarscrolly#,2.9
  130. if stellarscrolly#>=300 then dec stellarscrolly#,300
  131. position object 15,0,0-stellarscrolly#,0
  132. position object 16,0,300-stellarscrolly#,0
  133.  
  134. rem Show stellar effect
  135. show object 15 : show object 16
  136.  
  137. return
  138.  
  139. _control_player:
  140.  
  141. rem Handle movement keys
  142. if leftkey()=1 then speedx#=speedx#-6.0
  143. if rightkey()=1 then speedx#=speedx#+6.0
  144.  
  145. rem If game is active, handle bullet firing
  146. if gameactive=1
  147.  
  148.     rem If spacebar pressed and gun ready
  149.     if spacekey()=1 and gunready=0
  150.  
  151.         rem Fire bullet from ship position
  152.         if fire_bullet(1,shipx#,-90.0)>0
  153.  
  154.             rem Start gun delay countdown if bullet fired successfully
  155.             gunready=10
  156.     
  157.             rem Play gun sound
  158.             play sound 1
  159.  
  160.         endif
  161.  
  162.     endif
  163.  
  164.     rem Decrement gun ready counter
  165.     if gunready>0 then dec gunready
  166.  
  167. endif
  168.  
  169. rem Handle inertia of the ship
  170. speedx#=speedx#/2.5
  171. shipx#=shipx#+speedx#
  172.  
  173. rem Prevent ship leaving the screen
  174. if shipx#<-130.0 then shipx#=-130.0
  175. if shipx#>130.0 then shipx#=130.0
  176.  
  177. rem Rotate the ship based on its X coordinate
  178. yrotate object 50,wrapvalue(180-(shipx#/2.0))
  179.  
  180. rem Position the ship
  181. position object 50,shipx#,-90,-10
  182.  
  183. rem Handle protective shield of ship
  184. if playershield>0
  185.  
  186.     rem Fade player in and out while ghosted
  187.     fade object 50,abs(cos(wrapvalue(playershield*10.0))*100)
  188.  
  189.     rem Decrement shield counter until it wears off
  190.     dec playershield
  191.     if playershield=0
  192.  
  193.         rem Make ship solid again
  194.         ghost object off 50
  195.         fade object 50,200
  196.  
  197.     endif
  198.  
  199. endif
  200.  
  201. return
  202.  
  203. _destroy_player:
  204.  
  205. rem Play player destroyed sound
  206. play sound 2
  207.  
  208. rem Reposition player randomly
  209. shipx#=rnd(200)-100.0
  210.  
  211. rem Activate protective shield for ship
  212. ghost object on 50
  213. playershield=100
  214.  
  215. rem Decrement lives
  216. dec lives
  217.  
  218. rem Change the lives icon based on number of lives left
  219. if lives=2 then hide limb 30,2
  220. if lives=1 then hide limb 30,1
  221. if lives=0 then hide limb 30,0
  222.  
  223. rem When player has no more lives
  224. if lives=-1
  225.  
  226.     rem Return to level one
  227.     level=1
  228.  
  229.     rem Destroy all bullets
  230.     gosub _destroy_bullets
  231.  
  232.     rem Restore player
  233.     gosub _restore_player
  234.  
  235.     rem Restore aliens
  236.     gosub _restore_aliens
  237.  
  238.     rem Prompt new game message
  239.     message$="GET READY"
  240.     gosub _new_message
  241.  
  242. endif
  243.  
  244. return
  245.  
  246. _restore_player:
  247.  
  248. rem Restore lives icon to show all ships
  249. show limb 30,0 : show limb 30,1 : show limb 30,2
  250.  
  251. rem Restore lives
  252. lives=3
  253.  
  254. rem If score higher than hiscore, set a new hiscore
  255. if score>hiscore(0) then hiscore(0)=score
  256.  
  257. rem Save hiscore to a file
  258. if hiscore(0)>0 then save array "hiscore.dat",hiscore(0)
  259.  
  260. rem Reset score
  261. score=0
  262.  
  263. return
  264.  
  265. _control_aliens:
  266.  
  267. rem If game is active, handle alien shifting
  268. if gameactive=1
  269.  
  270.     rem Slowly increase speed of aliens as each one is destroyed
  271.     alienspeed#=1.0+((enemymax-visiblealiens)/20.0)
  272.  
  273.     rem Stage 0 : Move aliens right
  274.     if alienshiftdirection=0
  275.  
  276.         rem Move alien shift position to the right
  277.         inc alienshiftx#,alienspeed#
  278.  
  279.         rem When they have shifted all the way right, trigger stage 1
  280.         if alienshiftx#>50.0 then alienshiftdirection=1 : aliendrop=8
  281.  
  282.     endif
  283.  
  284.     rem Stage 1 : Move aliens down
  285.     if alienshiftdirection=1
  286.  
  287.         rem Move alien shift position down
  288.         dec aliendrop
  289.         dec alienshifty#,1.0
  290.  
  291.         rem When they have completely shifted down, trigger stage 2
  292.         if aliendrop=0 then alienshiftdirection=2
  293.  
  294.     endif
  295.  
  296.     rem Stage 2 : Move aliens left
  297.     if alienshiftdirection=2
  298.  
  299.         rem Move alien shift position to the left
  300.         dec alienshiftx#,alienspeed#
  301.  
  302.         rem When they have shifted all the way left, trigger stage 3
  303.         if alienshiftx#<-50.0 then alienshiftdirection=3 : aliendrop=8
  304.  
  305.     endif    
  306.  
  307.     rem Stage 3 : Forthly move aliens down again
  308.     if alienshiftdirection=3
  309.  
  310.         rem Move alien shift position down
  311.         dec aliendrop
  312.         dec alienshifty#,1.0
  313.  
  314.         rem When they have completely shifted down, return to stage 0
  315.         if aliendrop=0 then alienshiftdirection=0
  316.  
  317.     endif
  318.  
  319. endif
  320.  
  321. rem Update each alien object
  322. for e=1 to enemymax
  323.  
  324.     rem Get the object identity of the alien
  325.     objid=enemy#(e,1)
  326.  
  327.     rem Position the alien based on the shift and formation coordinates
  328.     position object objid,alienshiftx#+enemy#(e,2),alienshifty#+enemy#(e,3),-10
  329.  
  330.     rem Make the alien wobble
  331.     yrotate object objid,wrapvalue(180-(cos(enemy#(e,4))*10.0))
  332.     enemy#(e,4)=wrapvalue(enemy#(e,4)+16)
  333.  
  334.     rem Store the current position of alien object
  335.     ax#=object position x(enemy#(e,1))
  336.     ay#=object position y(enemy#(e,1))
  337.  
  338.     rem Reset player lost flag
  339.     playerlost=0
  340.  
  341.     rem Check whether alien is alive
  342.     if object visible(objid)=1
  343.  
  344.         rem Find distance between player and alien
  345.         dx#=shipx#-ax# : dy#=(-90)-ay#
  346.         dist#=sqrt(abs(dx#*dx#)+abs(dy#*dy#))
  347.         if dist#<=10.0
  348.     
  349.             rem If player and alien close, make explosions
  350.             hide object enemy#(e,1)
  351.             trigger_explosion(ax#,ay#)
  352.  
  353.             rem Set player lost flag
  354.             playerlost=1
  355.         
  356.         endif
  357.  
  358.         rem Check whether alien reaches bottom of screen
  359.         if ay#<-105.0 then playerlost=1
  360.  
  361.     endif    
  362.  
  363.     rem If player lost flag is set, destroy player
  364.     if playerlost=1
  365.  
  366.         rem Make player explode
  367.         trigger_explosion(shipx#,-90.0)
  368.         
  369.         rem Destroy player
  370.         gosub _destroy_player
  371.  
  372.         rem Restore aliens
  373.         gosub _restore_aliens
  374.  
  375.     endif
  376.  
  377. next e
  378.  
  379. rem Randomly pick an alien to fire
  380. e=1+rnd(enemymax-1) : objid=enemy#(e,1)
  381.  
  382. rem If alien is alive and scores a probability of 1/5
  383. if object visible(objid)=1 and rnd(5)=0 and gameactive=1
  384.  
  385.     rem Find position of alien
  386.     ax#=object position x(objid)
  387.     ay#=object position y(objid)
  388.  
  389.     rem Fire bullet from the alien position
  390.     fire_bullet(2,ax#,ay#)
  391.  
  392. endif
  393.  
  394. return
  395.  
  396. _restore_aliens:
  397.  
  398. rem Reset aliens for new level
  399. for e=1 to enemymax
  400.  
  401.     rem Find object identity of alien
  402.     objid=enemy#(e,1)
  403.  
  404.     rem Reposition the object off screen to hide old alien positions
  405.     position object objid,-500,-500,0
  406.  
  407.     rem Show alien object
  408.     show object objid
  409.  
  410. next e
  411.  
  412. rem Reset the alien shift variables
  413. alienshiftdirection=0
  414. alienshiftx#=0.0
  415. alienshifty#=0.0
  416. aliendrop=0
  417.  
  418. rem Put aliens into formation for this level
  419. gosub _form_aliens
  420.  
  421. return
  422.  
  423. _form_aliens:
  424.  
  425. rem If level established
  426. if level>0
  427.  
  428.     rem Get alien formation data
  429.     restore : maxlevel=level
  430.     if maxlevel>6 then maxlevel=6
  431.     for l=1 to maxlevel
  432.         read a,b,c,d
  433.     next l
  434.     
  435.     rem Prepare to count visible aliens
  436.     visiblealiens=0
  437.  
  438.     rem Loop through all aliens
  439.     currentalien=1
  440.     for row=0 to 3
  441.         for x=0 to 7
  442.     
  443.             rem Determine how many aliens per row
  444.             if row=0 then hf=a/2
  445.             if row=1 then hf=b/2
  446.             if row=2 then hf=c/2
  447.             if row=3 then hf=d/2
  448.         
  449.             rem If alien outside formation for this row
  450.             if x<4-hf or x>3+hf
  451.  
  452.                 rem Find object identity of this alien
  453.                 objid=enemy#(currentalien,1)
  454.  
  455.                 rem Hide alien that is not part of formation
  456.                 hide object objid
  457.             
  458.             else
  459.             
  460.                 rem Count aliens that remain visible
  461.                 inc visiblealiens
  462.             
  463.             endif
  464.             
  465.             rem Increment index for next alien
  466.             inc currentalien
  467.  
  468.         next x
  469.     next row
  470.  
  471. endif
  472.  
  473. return
  474.  
  475. _control_bullets:
  476.  
  477. rem Update bullets
  478. for b=1 to bulletmax
  479.  
  480.     rem Find object identity for this bullet
  481.     objid=bullet#(b,1)
  482.  
  483.     rem Is the bullet visible
  484.     if object visible(objid)=1
  485.  
  486.         rem Move bullet up if it belongs to player
  487.         if bullet#(b,4)=1 then bullet#(b,3)=bullet#(b,3)+10.0
  488.  
  489.         rem Move bullet down if it belongs to alien
  490.         if bullet#(b,4)=2 then bullet#(b,3)=bullet#(b,3)-5.0
  491.  
  492.         rem Position bullet
  493.         position object objid,bullet#(b,2),bullet#(b,3),-10
  494.  
  495.         rem Destroy bullet if it leaves screen
  496.         if bullet#(b,3)<-130.0 then hide object objid
  497.         if bullet#(b,3)>130.0 then hide object objid
  498.  
  499.         rem Check whether this player bullet..
  500.         if bullet#(b,4)=1
  501.     
  502.             rem ..has hit an alien
  503.             for e=1 to enemymax
  504.             
  505.                 rem If alien is visible
  506.                 if object visible(enemy#(e,1))=1
  507.     
  508.                     rem Find distance between bullet and alien
  509.                     ax#=object position x(enemy#(e,1))
  510.                     ay#=object position y(enemy#(e,1))
  511.                     dx#=bullet#(b,2)-ax#
  512.                     dy#=bullet#(b,3)-ay#
  513.                     dist#=sqrt(abs(dx#*dx#)+abs(dy#*dy#))
  514.                     
  515.                     rem If distance less than size of alien
  516.                     if dist#<=10.0
  517.         
  518.                         rem Play alien destroyed sound
  519.                         play sound 3
  520.     
  521.                         rem Destroy alien and make explosions
  522.                         hide object enemy#(e,1)
  523.                         hide object bullet#(b,1)
  524.                         trigger_explosion(ax#,ay#)
  525.                         trigger_explosion(bullet#(b,2),bullet#(b,3))
  526.         
  527.                         rem Decrement alien counter
  528.                         dec visiblealiens
  529.     
  530.                         rem Increment score for destroying this alien
  531.                         if enemy#(e,5)=0 then inc score,5
  532.                         if enemy#(e,5)=1 then inc score,10
  533.                         if enemy#(e,5)=2 then inc score,15
  534.     
  535.                         rem When no more aliens visible
  536.                         if visiblealiens=0
  537.     
  538.                             rem Increase level
  539.                             inc level
  540.     
  541.                             rem Restore aliens
  542.                             gosub _restore_aliens
  543.     
  544.                             rem Prompt next level message
  545.                             message$="LEVEL "+str$(level)
  546.                             gosub _new_message
  547.     
  548.                         endif
  549.     
  550.                     endif
  551.     
  552.                 endif
  553.             
  554.             next e
  555.     
  556.             rem ..has hit the mothership
  557.             dx#=bullet#(b,2)-mothx#
  558.             dy#=bullet#(b,3)-(115.0)
  559.             dist#=sqrt(abs(dx#*dx#)+abs(dy#*dy#))
  560.             if dist#<=15.0
  561.     
  562.                 rem Play mothership destroyed sound
  563.                 play sound 4
  564.     
  565.                 rem Destroy mothership and make explosions
  566.                 hide object bullet#(b,1)
  567.                 trigger_explosion(mothx#,115.0)
  568.                 trigger_explosion(bullet#(b,2),bullet#(b,3))
  569.     
  570.                 rem Reposition mothership to the far left
  571.                 mothx#=-2000.0
  572.     
  573.                 rem Increment score for destroying mothership
  574.                 inc score,100
  575.     
  576.             endif
  577.  
  578.         endif
  579.  
  580.         rem Check whether alien bullet..
  581.         if bullet#(b,4)=2
  582.     
  583.             rem ..has hit an unshielded player
  584.             if playershield=0
  585.     
  586.                 rem Find distance between bullet and player
  587.                 dx#=shipx#-bullet#(b,2)
  588.                 dy#=(-90)-bullet#(b,3)
  589.                 dist#=sqrt(abs(dx#*dx#)+abs(dy#*dy#))
  590.  
  591.                 rem If distance less than size of bullet
  592.                 if dist#<5.0
  593.         
  594.                     rem Destroy bullet and explode player ship
  595.                     hide object bullet#(b,1)
  596.                     trigger_explosion(shipx#,-90.0)
  597.                     trigger_explosion(bullet#(b,2),bullet#(b,3))
  598.  
  599.                     rem Destroy player
  600.                     gosub _destroy_player        
  601.  
  602.                 endif
  603.  
  604.             endif
  605.  
  606.         endif
  607.     
  608.     endif
  609.  
  610. next b
  611.  
  612. return
  613.  
  614. _destroy_bullets:
  615.  
  616. rem Hide all bullets
  617. for b=1 to bulletmax
  618.  
  619.     rem Find object identity of bullet
  620.     objid=bullet#(b,1)
  621.  
  622.     rem Hide bullet object
  623.     hide object objid
  624.  
  625. next b
  626.  
  627. return
  628.  
  629. _control_explosions:
  630.  
  631. rem Update all explosions
  632. for ex=1 to explosionmax
  633.  
  634.     rem Find object identity of explosion
  635.     objid=explode#(ex,1)
  636.  
  637.     rem If explosion visible
  638.     if object visible(objid)=1
  639.  
  640.         rem Position explosion
  641.         position object objid,explode#(ex,2),explode#(ex,3),-10
  642.  
  643.         rem Scale and rotate explosion for effect
  644.         scale object objid,explode#(ex,4)*2,explode#(ex,4)*2,explode#(ex,4)*4
  645.         fade object objid,explode#(ex,4)*2
  646.         zrotate object objid,explode#(ex,4)*3.0
  647.  
  648.         rem Decrease explosion counter
  649.         explode#(ex,4)=explode#(ex,4)-10.0
  650.  
  651.         rem Hide explosion when counter runs out
  652.         if explode#(ex,4)<=0.0 then hide object objid
  653.  
  654.     endif
  655.  
  656. next ex
  657.  
  658. return
  659.  
  660. _control_mothership:
  661.  
  662. rem When mothership is in view
  663. if mothx#>-200.0 and mothx#<200.0
  664.  
  665.     rem Play mothership sound if not already playing
  666.     if sound playing(5)=0 then play sound 5
  667.  
  668. endif
  669.  
  670. rem Move mothership across the screen
  671. inc mothx#,4.0
  672.  
  673. rem When mothership moves too far right, bring it back to the far left
  674. if mothx#>400.0 then mothx#=-400.0
  675.  
  676. rem Position mothership object
  677. position object 200,mothx#,115,0
  678.  
  679. rem Wobble mothership for effect
  680. wobble#=wrapvalue(wobble#+16)
  681. xrotate object 200,wrapvalue(315+(cos(wobble#)*20))
  682.  
  683. return
  684.  
  685.  
  686. rem ************************
  687. rem * Creation Subroutines *
  688. rem ************************
  689.  
  690. _load_images:
  691.  
  692. rem Load images for backdrop
  693. load image "bmp\stars.bmp",1
  694. load image "bmp\stellar.bmp",2
  695.  
  696. rem Load images for action
  697. load image "bmp\bullet.bmp",3
  698. load image "bmp\bolt.bmp",4
  699. load image "bmp\explode1.bmp",5
  700. load image "bmp\explode2.bmp",6
  701.  
  702. rem Load images for aliens
  703. load image "bmp\alien1.bmp",7
  704. load image "bmp\alien2.bmp",8
  705. load image "bmp\alien3.bmp",9
  706.  
  707. return
  708.  
  709. _load_sounds:
  710.  
  711. rem Load sound effects
  712. load sound "wav\lasergun.wav",1
  713. load sound "wav\edestroy.wav",2
  714. load sound "wav\pdestroy.wav",3
  715. load sound "wav\pdestroy.wav",4 : set sound speed 4,20000
  716. load sound "wav\moth.wav",5
  717. load sound "wav\getready.wav",6
  718. load sound "wav\ping.wav",7 : set sound speed 7,30000
  719.  
  720. return
  721.  
  722. _create_numbers:
  723.  
  724. rem Create a hidden bitmap to work on 
  725. create bitmap 1,40,60
  726.  
  727. rem Set the text font style
  728. set text font "Arial"
  729. set text size 64
  730.  
  731. rem Print numbers 0-9 and store as images
  732. for n=0 to 9
  733.     cls : text 0,0,str$(n) : get image 10+n,0,0,40,60
  734. next n
  735.  
  736. rem Delete work bitmap
  737. delete bitmap 1
  738.  
  739. rem Setup decal objects for number digits
  740. for n=20 to 27
  741.  
  742.     rem Create a single digit decal
  743.     make object plain n,40,60
  744.     scale object n,200,320,200
  745.     rotate object n,20,0,0
  746.     set object n,1,0,1
  747.     fade object n,200
  748.     lock object on n
  749.     hide object n
  750.  
  751.     rem Texture decal object with the image for the number '0'
  752.     texture object n,10
  753.  
  754.     rem Position the digit on screen
  755.     if n<24
  756.  
  757.         rem Digit position for score
  758.         position object n,((n-20)*65)-730,540,1000
  759.  
  760.     else
  761.  
  762.         rem Digit position for hiscore
  763.         position object n,((n-20)*65)+285,540,1000
  764.  
  765.     endif
  766.  
  767. next n
  768.  
  769. return
  770.  
  771. _create_decals:
  772.  
  773. rem Load the ship object for use as a mesh
  774. load object "obj\ship.x",1 : make mesh from object 1,1 : delete object 1
  775.  
  776. rem Make lives icon object out of ship meshes
  777. make object 30,1,0 : scale object 30,200,100,100
  778. add limb 30,1,1 : offset limb 30,1,20,0,0
  779. add limb 30,2,1 : offset limb 30,2,40,0,0
  780.  
  781. rem Lock lives object to screen
  782. lock object on 30
  783.  
  784. rem Position and colour the lives object
  785. position object 30,-375,-265,500
  786. color object 30,rgb(64,128,255)
  787. ghost object on 30
  788.  
  789. rem Create a message decal object
  790. make object plain 31,300,100
  791. scale object 31,200,100,100
  792. xrotate object 31,45
  793. ghost object on 31
  794. hide object 31
  795.  
  796. rem Lock message object to screen
  797. lock object on 31
  798.  
  799. rem Position the message object
  800. position object 31,0,0,0
  801.  
  802. return
  803.  
  804. _new_message:
  805.  
  806. rem Create a hidden work bitmap
  807. create bitmap 1,600,100
  808.  
  809. rem Print text message and store as image
  810. set text size 70
  811. set text font "Arial"
  812. center text 300,40,message$
  813. get image 20,0,0,600,100
  814.  
  815. rem Delete work bitmap
  816. delete bitmap 1
  817.  
  818. rem Texture message object with text image
  819. texture object 31,20
  820. show object 31
  821.  
  822. rem Set message to display
  823. messagedelay=100
  824.  
  825. rem Deactivate game action
  826. gameactive=0
  827.  
  828. return
  829.  
  830. _create_backdrop:
  831.  
  832. rem Texture backdrop with stars image
  833. texture backdrop 1
  834.  
  835. rem Make stellar plain using nebula cloud texture
  836. make object plain 15,400,300 : texture object 15,2
  837. make object plain 16,400,300 : texture object 16,2
  838. ghost object on 15 : ghost object on 16
  839. fade object 15,5 : fade object 16,5
  840.  
  841. rem Hide stellar effect
  842. hide object 15 : hide object 16
  843.  
  844. return
  845.  
  846. _create_player:
  847.  
  848. rem Create a mesh of the ship and cockpit
  849. load object "obj\ship.x",1 : make mesh from object 1,1 : delete object 1
  850. load object "obj\dome.x",2 : make mesh from object 2,2 : delete object 2
  851.  
  852. rem Make ship object from mesh
  853. make object 50,1,0 : scale object 50,75,50,75
  854. position object 50,0.0,-90,-10
  855.  
  856. rem Add cockpit mesh to ship object
  857. add limb 50,1,2 : offset limb 50,1,0,-5,-5
  858.  
  859. rem Colour ship and cockpit
  860. color limb 50,0,rgb(64,128,255)
  861. color limb 50,1,rgb(255,255,128)
  862.  
  863. rem Restore player
  864. gosub _restore_player
  865.  
  866. return
  867.  
  868. _create_aliens:
  869.  
  870. rem Reset total aliens counter
  871. enemymax=0
  872.  
  873. rem Loop through four rows of eight aliens
  874. for row=0 to 3
  875.     for x=0 to 7
  876.  
  877.         rem Calculate enemy object identity
  878.         objid=100+x+(row*8)
  879.  
  880.         rem Create a single alien based on row hierarchy
  881.         if row=3 then etype=2
  882.         if row=2 then etype=1
  883.         if row<2 then etype=0
  884.         make_single_alien(objid,etype)
  885.  
  886.         rem Scale alien based on height
  887.         scale object objid,50+(row*5),50+(row*5),50
  888.  
  889.         rem Add alien details to enemy array
  890.         inc enemymax
  891.         enemy#(enemymax,1)=objid
  892.         enemy#(enemymax,2)=(x-3.5)*25
  893.         enemy#(enemymax,3)=(row+1.0)*20
  894.         enemy#(enemymax,4)=0
  895.         enemy#(enemymax,5)=etype
  896.  
  897.     next x
  898. next row
  899.  
  900. rem Restore alien
  901. gosub _restore_aliens
  902.  
  903. return
  904.  
  905. _create_bullets:
  906.  
  907. rem Reset total bullets counter
  908. bulletmax=0
  909.  
  910. rem Create bullets for player and aliens
  911. for b=1 to 40
  912.  
  913.     rem Calculate object identity of bullet
  914.     objid=300+b
  915.  
  916.     rem Make only one bullet for player
  917.     if b=1 then bullettype=1
  918.  
  919.     rem Make the rest of the bullets for the aliens
  920.     if b>1 then bullettype=2
  921.  
  922.     rem Make bullet using object identity
  923.     make_single_bullet(objid,bullettype)
  924.  
  925.     rem Add bullet details to bullets array
  926.     inc bulletmax
  927.     bullet#(bulletmax,1)=objid
  928.     bullet#(bulletmax,2)=0
  929.     bullet#(bulletmax,3)=0
  930.     bullet#(bulletmax,4)=bullettype
  931.  
  932. next b
  933.  
  934. return
  935.  
  936. _create_explosions:
  937.  
  938. rem Reset total explosions counter
  939. explosionmax=0
  940.  
  941. rem Create explosions
  942. for ex=1 to 10
  943.  
  944.     rem Calculate object identity of explosion
  945.     objid=400+ex
  946.  
  947.     rem Make explosion using object identity
  948.     make_single_explosion(objid)
  949.  
  950.     rem Add explosion details to explosions array
  951.     inc explosionmax
  952.     explode#(explosionmax,1)=objid
  953.     explode#(explosionmax,2)=0
  954.     explode#(explosionmax,3)=0
  955.  
  956. next b
  957.  
  958. return
  959.  
  960. _create_mothership:
  961.  
  962. rem Create meshes from parts of mothership
  963. load object "obj\mothship.x",1 : make mesh from object 1,1 : delete object 1
  964. load object "obj\mothrim.x",2 : make mesh from object 2,2 : delete object 2
  965.  
  966. rem Make mothership from meshes
  967. make object 200,1,0 : add limb 200,1,2
  968. position object 200,0,115,-10
  969.  
  970. rem Colour the mothership body and rim
  971. color limb 200,0,rgb(250,250,200)
  972. color limb 200,1,rgb(255,0,0)
  973.  
  974. rem Set mothership position to the far left
  975. mothx#=-400.0 : position object 200,mothx#,115,0
  976.  
  977. return
  978.  
  979.  
  980. rem *************************
  981. rem * Function Declarations *
  982. rem *************************
  983.  
  984. rem ---------------------------------------------------------
  985. rem Function to texture decal objects with a four digit value
  986. rem ---------------------------------------------------------
  987. function texture_digits(value,th,hu,te,un)
  988.  
  989. rem Limit maximum size of value
  990. if value>9999 then value=9999
  991.  
  992. rem Calculate the thousands digit value
  993. valuethousands=value/1000
  994. dec value,(valuethousands*1000)
  995.  
  996. rem Calculate the hundreds digit value
  997. valuehundreds=value/100
  998. dec value,(valuehundreds*100)
  999.  
  1000. rem Calculate the tens digit value
  1001. valuetens=value/10
  1002. dec value,(valuetens*10)
  1003.  
  1004. rem Calculate the units digit value
  1005. valueunits=value
  1006.  
  1007. rem Texture decal objects with the correct digit value
  1008. texture object th,10+valuethousands
  1009. texture object hu,10+valuehundreds
  1010. texture object te,10+valuetens
  1011. texture object un,10+valueunits
  1012.  
  1013. rem Show decal object in the event that they're invisible
  1014. show object th : show object hu : show object te : show object un
  1015.  
  1016. endfunction
  1017.  
  1018. rem ----------------------------------------------
  1019. rem Function to create an alien of a specific type
  1020. rem ----------------------------------------------
  1021. function make_single_alien(objid,type)
  1022.  
  1023. rem Make a decal object for the alien
  1024. make object plain objid,50,40
  1025. set object objid,1,0,0
  1026. xrotate object objid,340
  1027. scale object objid,50,50,500
  1028.  
  1029. rem Texture the decal object with an alien image
  1030. texture object objid,7+type
  1031. fade object objid,200
  1032.  
  1033. endfunction
  1034.  
  1035. rem ----------------------------------------------
  1036. rem Function to create a bullet of a specific type
  1037. rem ----------------------------------------------
  1038. function make_single_bullet(objid,type)
  1039.  
  1040. rem Make a decal object for the alien or player bullet
  1041. if type=1 then make object plain objid,5,20
  1042. if type=2 then make object plain objid,10,10
  1043.  
  1044. rem Prepare the decal object to look like a bullet
  1045. texture object objid,2+type
  1046. scale object objid,100,100,200
  1047. set object objid,1,0,1
  1048. ghost object on objid
  1049. fade object objid,200
  1050.  
  1051. rem Hide decal object
  1052. hide object objid
  1053.  
  1054. endfunction
  1055.  
  1056. rem --------------------------------------------------------------
  1057. rem Function to fire a free bullet from either the player or alien
  1058. rem --------------------------------------------------------------
  1059. function fire_bullet(who,x#,y#)
  1060.  
  1061. rem Find a free bullet
  1062. freebullet=0
  1063. for b=1 to 40
  1064.  
  1065.     rem Find the object identity for this bullet
  1066.     objid=bullet#(b,1)
  1067.  
  1068.     rem If the bullet is invisible and belongs to the player or alien
  1069.     if object visible(objid)=0 and bullet#(b,4)=who
  1070.  
  1071.         rem Set the freebullet variable to the index of the bullet
  1072.         freebullet=b
  1073.  
  1074.     endif
  1075.  
  1076. next b
  1077.  
  1078. rem If the freebullet variable is holding a bullet index
  1079. if freebullet>0
  1080.  
  1081.     rem Show and position bullet
  1082.     show object bullet#(freebullet,1)
  1083.     bullet#(freebullet,2)=x#
  1084.     bullet#(freebullet,3)=y#
  1085.  
  1086. endif
  1087.  
  1088. endfunction freebullet
  1089.  
  1090. rem ------------------------------------------
  1091. rem Function to make a single explosion object
  1092. rem ------------------------------------------
  1093. function make_single_explosion(objid)
  1094.  
  1095. rem Make a decal object for the explosion
  1096. make object plain objid,30,30
  1097.  
  1098. rem Prepare the decal object to look like an explosion
  1099. texture object objid,5
  1100. scale object objid,100,100,200
  1101. set object objid,1,0,1
  1102. ghost object on objid
  1103. fade object objid,200
  1104.  
  1105. rem Hide the decal object
  1106. hide object objid
  1107.  
  1108. endfunction
  1109.  
  1110. rem -----------------------------------------------------
  1111. rem Function to detonate a free explosion at a coordinate
  1112. rem -----------------------------------------------------
  1113. function trigger_explosion(x#,y#)
  1114.  
  1115. rem Find a free explosion
  1116. freeexplosion=0
  1117. for ex=1 to 10
  1118.  
  1119.     rem Find the object identity of this explosion
  1120.     objid=explode#(ex,1)
  1121.  
  1122.     rem If explosion invisible
  1123.     if object visible(objid)=0
  1124.  
  1125.         rem Store the explosion index in the freeexplosion variable
  1126.         freeexplosion=ex
  1127.  
  1128.     endif
  1129.  
  1130. next ex
  1131.  
  1132. rem If the freeexplosion variable contains an explosion index
  1133. if freeexplosion>0
  1134.     
  1135.     rem Find the object identity of this explosion
  1136.     objid=explode#(freeexplosion,1)
  1137.  
  1138.     rem Show and position the explosion
  1139.     show object objid
  1140.     explode#(freeexplosion,2)=x#
  1141.     explode#(freeexplosion,3)=y#
  1142.     explode#(freeexplosion,4)=100.0
  1143.  
  1144.     rem Texture the decal object with a random explosion image
  1145.     texture object objid,5+rnd(1)
  1146.  
  1147. endif
  1148.  
  1149. endfunction
  1150.  
  1151.  
  1152. rem ********************************************
  1153. rem * Alien Formation Data (for upto 6 levels) *
  1154. rem ********************************************
  1155. data 6,6,4,2
  1156. data 8,6,4,2
  1157. data 8,8,6,4
  1158. data 8,8,8,4
  1159. data 8,8,8,6
  1160. data 8,8,8,8
  1161.  
  1162.