home *** CD-ROM | disk | FTP | other *** search
/ Game Programming for Teens / GameProgrammingForTeens.iso / Source / chapter13 / invaderz.bb < prev    next >
Encoding:
Text File  |  2003-04-06  |  17.3 KB  |  766 lines

  1. ;INVADERS!!!
  2. ;Developed by Maneesh Sethi on 7/22/02
  3. ;A Space invaders clone
  4.  
  5.  
  6. ;Set the graphics mode to 640x480
  7. Graphics 640,480 
  8.  
  9. ;Set up backbuffer and AutoMidHandle
  10. SetBuffer BackBuffer() 
  11. AutoMidHandle True
  12.  
  13. ;Set up random generator
  14. SeedRnd MilliSecs() 
  15.  
  16. ;IMAGES
  17. ;Player's images
  18. ;These images are related to the player
  19. Global playerimage = LoadAnimImage("player.bmp",35,32,0,13)   ;The player's appearance on screen
  20. Global bulletplayerimage = LoadAnimImage("playerbullet.bmp",40,19,0,10)    ;The player's bullet
  21. Global playerexplosionimage = LoadAnimImage("playerexplosion.bmp",64,64,0,8)
  22.  
  23. ;Enemies' image
  24. ;These images are related to the enemy
  25. Global enemyimage = LoadAnimImage("enemy.bmp",68,38, 0, 10) ;The enemies' appearance on screen
  26. Global bulletenemyimage = LoadAnimImage("enemybullet.bmp",40,19,0,5) ;The enemies' bullet
  27. Global enemyexplosionimage = LoadAnimImage("enemyexplosion.bmp",64,64,0,8)
  28.  
  29. ;Miscellaneous images
  30. Global healthimage = LoadAnimImage("health.bmp",33,21,0,10)    ;the health image
  31. Global backgroundimage = LoadImage("stars.bmp") ;the background image
  32. splashscreenimage = LoadImage("splashscreen.bmp")   ;the splash screen
  33.  
  34.  
  35.  
  36. ;SOUNDS/MUSIC
  37. ;Sounds
  38. Global explosionsound = LoadSound("explode.wav")
  39. Global bulletsound = LoadSound("zing.wav")
  40.  
  41. ;Play background music
  42. backgroundmusic = PlayMusic ("Interim Nation - Human Update.mp3")
  43.  
  44. ;CONSTANTS
  45.  
  46. ;Keycodes
  47. Const ESCKEY = 1, SPACEBAR = 57, LEFTKEY = 203, RIGHTKEY = 205 
  48.  
  49. ;The number of milliseconds between enemy direction changes
  50. Const CHANGEENEMYDIRECTION = 700 
  51.  
  52. ;Number of milliseconds between enemy bullet fires
  53. Const TIMEBETWEENENEMYBULLETS = 1200
  54.  
  55. ;GLOBALS
  56. ;Create global variables that will be used through the program
  57. Global numofenemies  ;the amount of enemies
  58.  
  59. Global directiontime ;counter between enemy direction changes
  60.  
  61. Global shotsfiredtime ;counter between enemy shots 
  62.  
  63. Global enemyhits ;How many times player has hit enemy ships
  64.  
  65. Global shotsfired ;How many shots player has fired
  66.  
  67. Global playerdamage ;How many times player has been hit
  68.  
  69. Global playerscore   ;The player's current score
  70.  
  71. Global scrolly   ;the scrolling variable for background
  72.  
  73. Global healthframe  ;the variable that keeps track of the spinning health box
  74.  
  75.  
  76. ;TYPES
  77.  
  78. ;The ship type: enemies are ships
  79. Type ship           
  80.     Field x,y  ;The x and y coords
  81.     Field hits  ;ship's hitpoints
  82.     Field xv,yv  ;the x and y direction velocities
  83.     Field frame ;the frame of the ship's image
  84. End Type
  85.  
  86.  
  87.  
  88. ;The user type: the player is a user
  89. Type user
  90.     Field x,y   ;the player's coordinates
  91.     Field hits  ;the player's hitpoints
  92.     Field frame ;the current frame of the player
  93.     Field draw  ;1 if player should be drawn, 0 if he shouldn't
  94. End Type
  95.  
  96. ;Set up player for beginning of game
  97. Global player.user = New user  ;Create a new player ship
  98. player\x = 640/2 ;Player is in the middle of scren
  99. player\y = 440    ;Player is near the bottom
  100. player\hits = 3
  101. player\draw = 1
  102.  
  103.  
  104. ;The bullet type: describes both player and enemy bullets
  105. Type bullet           
  106.     Field x,y   ;the bullet's coordinates
  107.     Field draw ;draw is 1 if the bullet should be drawn, 0 if it should be deleted
  108.     Field from  ;if from is 1, bullet is from player, if 2, its from enemy
  109.     Field frame   ;the frame of the image. There are 10 frames for player's bullet and 5 for enemy's
  110. End Type
  111.  
  112. ;The explosion type: describes explosions for players and enemies
  113. Type explosion
  114.     Field x,y    ;the x and y coordinate position
  115.     Field from   ;1 = player, 2 = enemy
  116.     Field frame  ;the frame of the image
  117. End Type
  118.  
  119. ;Set the level the player is on: beginning with level 1
  120. level = 1 
  121.  
  122. ;;;;;;;;;;;;;;;;;;;
  123. ;MAIN PROGRAM (first function)
  124. ;Only initializes players and calls other functions (utilizes input as well)
  125. ;;;;;;;;;;;;;;;;;;;
  126. ;Make the sound of the bullet fire not very loud
  127. ;It will be at 25% volume
  128. SoundVolume bulletsound, .25
  129.  
  130. ;Display the splash screen for 7 seconds
  131. DrawImage(splashscreenimage, 320,240)
  132. Flip
  133. Delay 7000
  134.  
  135.  
  136. ;Make the time of enemy direction changes and enemy bullets equal to the time
  137. directiontime = shotsfiredtime = MilliSecs()
  138.  
  139. ;Set up level
  140. InitializeLevel(level)
  141.  
  142.  
  143. ;MAIN LOOP
  144.  
  145. While Not KeyDown(ESCKEY) 
  146.  
  147.     ;Draw the background at its position
  148.     TileBlock backgroundImage,0,scrolly
  149.     
  150.     ;Scroll the background a little
  151.     scrolly=scrolly + 1
  152.     
  153.     ;If scrolly is too big, reset it
  154.     If scrolly=ImageHeight(backgroundImage) Then
  155.         scrolly=0
  156.     EndIf
  157.  
  158.     
  159.     ;If there are no enemies left on screen, player has beaten level. Thus, begin next level.
  160.     If numofenemies = 0 Then
  161.         
  162.         ;Make the player's level increment by one
  163.         level = level + 1
  164.         
  165.         ;Initalize the new level
  166.         InitializeLevel(level)
  167.     EndIf
  168.     
  169.     ;If the space bar is hit
  170.     If KeyHit(SPACEBAR) 
  171.             
  172.             ;Create a new bullet at the player's position ('1' signifies that the bullet is from the player, and not an enemy)
  173.             CreateBullet(player\x,player\y , 1) 
  174.         
  175.             ;Increment the variable that holds how many bullets have been fired
  176.             shotsfired = shotsfired + 1
  177.             ;play bullet sound
  178.             PlaySound(bulletsound)
  179.         EndIf
  180.         
  181.  
  182.     ;If left key is pressed, move player 10 pixels left
  183.     If KeyDown(LEFTKEY)
  184.         
  185.         player\x = player\x - 10
  186.         
  187.         
  188.         ;If player moves offscreen, keep him onscreen
  189.         If player\x <= 0
  190.             player\x = 10
  191.         EndIf
  192.  
  193.         ;tilt player left
  194.         player\frame = player\frame - 1
  195.         
  196.         ;dont let frame get too low
  197.         If player\frame <= 0
  198.             player\frame = 0
  199.         EndIf
  200.     EndIf
  201.     
  202.     ;If right key is pressed, move player right 10 pixel
  203.     If KeyDown(RIGHTKEY)
  204.         player\x = player\x + 10
  205.     
  206.         ;if player moves off screen, keep him on screen
  207.         If player\x >= 610
  208.             player\x = 610
  209.         EndIf
  210.         
  211.         
  212.         ;tilt player right
  213.         player\frame = player\frame + 1
  214.         
  215.         ;dont let frame get too high
  216.         If player\frame >= 12
  217.             player\frame = 12
  218.         EndIf
  219.     EndIf
  220.     
  221.     ;Begin resetting the player's frame
  222.     If (Not KeyDown(RIGHTKEY)) And (Not KeyDown(LEFTKEY))
  223.         If player\frame < 7
  224.             player\frame = player\frame + 1
  225.         ElseIf player\frame > 7
  226.             player\frame = player\frame - 1
  227.         EndIf
  228.     EndIf 
  229.     ;Call the necessary user-defined functions
  230.     ;Draw the information the player needs to see
  231.     DrawHUD()
  232.     ;Draw all of the ships, player and enemies
  233.     DrawShips()
  234.     ;Update enemy's movement and bullet fire
  235.     EnemyAI()
  236.     ;Move all of the bullets, and delete uncessary one
  237.     UpdateBullets() 
  238.     ;update all existing explosions
  239.     UpdateExplosions()
  240.  
  241.     Flip
  242.     
  243.     ;hold on for a fraction of a second
  244.     Delay 25
  245. Wend ;End of While Loop
  246.  
  247. GameOver()
  248. ;;;;;;;;;;;;;;;;;;;
  249. ;END OF MAIN PROGRAM
  250. ;
  251. ;;;;;;;;;;;;;;;;;;;
  252.  
  253.  
  254. ;;;;;;;;;;;;;;;;;;;
  255. ;CreateBullet(x,y)
  256. ;This function takes the x and y coords of the bullet and creates it
  257. ;;;;;;;;;;;;;;;;;;;
  258. Function CreateBullet(x,y, from)
  259.  
  260.  
  261.     ;Create a new bullet
  262.     bullets.bullet = New bullet 
  263.     
  264.     ;set the x and y coordinates to the position of the ship that fired it
  265.     bullets\x = x
  266.     bullets\y = y  
  267.     
  268.     ;Make sure the bullet should be drawable
  269.     bullets\draw = 1 
  270.     
  271.     ;Tell where the bullet originated from: a player or an enemy
  272.     bullets\from = from 
  273.  
  274.  
  275.  
  276. End Function ;End CreateBullet
  277.  
  278.  
  279. ;;;;;;;;;;;;;;;;;;;
  280. ;UpdateBullets()
  281. ;Updates each bullet and deletes them if they are no longer on the screen
  282. ;;;;;;;;;;;;;;;;;;;
  283.  
  284. Function UpdateBullets()
  285.  
  286.  
  287. ;Check every bullet. Depending on who fired it, move it in the corect direction. Then, draw the bullet. 
  288. ;Finally, check and see if the bullets have hit any other ships
  289. For i.bullet = Each bullet ;Check every bullet
  290.     
  291.     ;If shot by player, move bullet up
  292.     If i\from = 1 
  293.         i\y = i\y - 10 
  294.     
  295.     ;If shot by player, move bullet down
  296.     Else 
  297.         i\y = i\y + 10 ;move bullet down 
  298.     EndIf
  299.             
  300.     ;if bullet should be drawn (its on screen), draw it with the proper color
  301.     If i\draw = 1 
  302.         
  303.         ;If its from player, draw player bullet
  304.         If i\from = 1
  305.             DrawImage (bulletPlayerImage, i\x, i\y, i\frame) 
  306.         
  307.         ;If its from enemy, draw enemy bullet
  308.         Else
  309.             DrawImage (bulletEnemyImage, i\x, i\y, i\frame) 
  310.         EndIf
  311.     EndIf
  312.     
  313.     
  314.     
  315.     
  316.     ;We now test to see if the bullets have hit any ships
  317.     
  318.     ;Test the players bullets if it hit an enemy
  319.     If i\from = 1 
  320.     
  321.     ;For each enemy, if bullet has collided, subtract a hitpoint
  322.     For e.ship = Each ship ;check each enemy
  323.         
  324.         ;If the bullet has hit the enemy, remove one hitpoint
  325.         If ImagesCollide(bulletplayerimage, i\x,i\y,0, enemyimage, e\x, e\y, 0) 
  326.             
  327.             ;Subtract a hitpoin
  328.             e\hits = e\hits - 1 
  329.         
  330.         
  331.             ;increment the number of times an enemy has been hit by player
  332.             enemyhits = enemyhits + 1
  333.             
  334.             ;if the ship is out of hitpoints, remove the enemy
  335.             If e\hits <= 0
  336.             
  337.                 numofenemies = numofenemies - 1
  338.                 ;create an explosion with enemy's coordinates. "2" signifies it is from enemy. not player.
  339.                 CreateExplosion(e\x,e\y,2)
  340.             
  341.                 ;destroy the enemy ship
  342.                 Delete e 
  343.                 ;play explosion sound
  344.                 PlaySound(explosionsound)
  345.                 
  346.  
  347.             EndIf 
  348.         
  349.         ;Make sure the bullet is not drawn (it will be deleted next frame)
  350.         i\draw = 0
  351.         EndIf 
  352.         
  353.         
  354.     Next   ;check next enemy ship
  355.     
  356.     EndIf 
  357.     
  358.     ;check if the bullet is shot by enemy, check if it hit player
  359.     ;don't check if the player has already exploded
  360.     If i\from = 2 And playerexplosion = 0
  361.         ;if the bullet hit the player, decrease hitpoints and add damage
  362.         If ImagesCollide(bulletenemyimage,i\x, i\y, 0, playerimage, player\x, player\y, 0)
  363.             
  364.             ;decrease a hitpoint
  365.             player\hits = player\hits - 1
  366.         
  367.  
  368.             ;If player is out of hitpoints, call gameover()
  369.             If player\hits <= 0 
  370.                 ;play explosion sound
  371.                 PlaySound(explosionsound)
  372.                 CreateExplosion(player\x,player\y,1)
  373.                 ;don't draw player anymore
  374.                 player\draw = 0
  375.             EndIf
  376.         ;Make sure the bullet is not drawn anymore
  377.         i\draw = 0
  378.         
  379.         EndIf 
  380.         
  381.     EndIf
  382.     
  383.         
  384.         ;If from player, draw player explosion
  385.     If player\hits <= 0
  386.     
  387.         For ex.explosion = Each explosion
  388.             If ex\from = 1 And ex\frame >= 7
  389.     
  390.                 GameOver()
  391.     
  392.             EndIf
  393.         Next    
  394.     EndIf
  395.  
  396.  
  397.     ;increment frame
  398.     i\frame = i\frame + 1
  399.     ;if from player, there are 10 frames: dont let frame get too large
  400.     If i\from = 1 And i\frame >= 10
  401.         i\frame = 0
  402.     ;if from enemy there are 5 franes: don't let frame get too large
  403.     ElseIf i\from = 2 And i\frame >=5
  404.         i\frame = 0
  405.     EndIf
  406.         
  407.     ;If the bullet is offscreen or if it hit a ship, delete it    
  408.     If i\y < 0 Or i\draw = 0
  409.         Delete i 
  410.     EndIf 
  411.  
  412.     
  413.  
  414. Next ;Go to the next bullet
  415.  
  416. End Function
  417.  
  418. ;;;;;;;;;;;;;;;;;;;
  419. ;InitializeLevel(level)
  420. ;Sets up parameters for the current level
  421. ;;;;;;;;;;;;;;;;;;;
  422.  
  423. Function InitializeLevel(level)
  424.  
  425.  
  426. ;Delete each and every bullet
  427. For i.bullet = Each bullet
  428.     Delete i
  429. Next
  430.  
  431.  
  432. ;Display intro text
  433. Text 230,240,"NOW ENTERING Level " + level
  434. Flip
  435.  
  436. ;Delay for a few seconds
  437. Delay 2000
  438.  
  439.  
  440. ;Reset player's hitcounter
  441. player\hits = 3
  442.  
  443. ;reset player's frame
  444. player\frame = 7   ;(7 is the middle frame)
  445.  
  446. ;Make the total number of enemies a value between 3 and 5 + the current level
  447. numofenemies = level + Rand(3 , 5)    ;Level 1 will have 4-6 enemies, 2 will have 5-7, etc.
  448.  
  449. ;reset health boxes' frame
  450. healthframe = 0
  451.  
  452.  
  453. ;create the required number of enemies
  454. For e=1 To numofenemies
  455.  
  456.     CreateNewEnemy(level) 
  457. Next
  458.     
  459.     
  460. End Function 
  461. ;;;;;;;;;;;;;;;;;;;
  462. ;CreateNewEnemy(level)
  463. ;Create a new enemy
  464. ;;;;;;;;;;;;;;;;;;;
  465.  
  466. Function CreateNewEnemy(level)
  467.  
  468. ;Create a new enemy ship
  469. enemy.ship = New ship
  470.  
  471. ;release point determines if enemy will be released from top, left, or bottom of screen
  472. releasepoint = Rand(1,4) 
  473.  
  474. ;25% of enemies will be unleashed from left\right, 50% from top
  475. Select releasepoint
  476.  
  477.     Case 1   ;enemy released from left side
  478.         
  479.         ;set up enemy's coordinates
  480.         enemy\x = 5
  481.         enemy\y = Rand(0 , 420)   ;Enemy is released on a random point on the left side
  482.         
  483.         ;set up random velocities
  484.         enemy\xv = Rand(1 , 2)
  485.         enemy\yv = Rand(-2,2)
  486.         
  487.     Case 2   ;enemy released from top
  488.         ;set up enemy's coorinates
  489.         enemy\x = Rand(0,640)    ;Enemy is released on a random point on the top
  490.         enemy\y = 5
  491.         
  492.         ;set up random velocities
  493.         enemy\xv = Rand(-2, 2)
  494.         enemy\yv = Rand(1,2)
  495.         
  496.     Case 3 ;enemy released from top
  497.         ;set up enemy coordinates
  498.         enemy\x = Rand(0,640)   ;Enemy is released on a random point on the top
  499.         enemy\y = 5
  500.         
  501.         ;Set up random velocities
  502.         enemy\xv = Rand(-2, 2)
  503.         enemy\yv = Rand(1,2)
  504.         
  505.         
  506.     Case 4 ;enemy released from right side
  507.         ;set up enemy coordinates
  508.         enemy\x = 620
  509.         enemy\y = Rand(0 , 420) ;Enemy is released on a random point on the right side
  510.         
  511.         ;set up random velocities
  512.         enemy\xv = Rand(-2, -1)
  513.         enemy\yv = Rand(-2,2)
  514.         
  515.         
  516.     Default ;if there is a major error
  517.         Print "ERROR, Enemy unleashed in a nonexistant place!"
  518. End Select
  519.  
  520. enemy\hits = level
  521. End Function
  522.         
  523.  
  524.  
  525. ;;;;;;;;;;;;;;;;;;;
  526. ;DrawShips()
  527. ;Draw Players and enemies
  528. ;;;;;;;;;;;;;;;;;;;
  529. Function DrawShips()
  530.  
  531. ;Draw each ship, enemy and player
  532. ;For each enemy
  533. For i.ship = Each ship   
  534.     DrawImage(enemyImage, i\x, i\y, i\frame)
  535. Next
  536. ;For each player
  537. For j.user = Each user 
  538.     ;if user should be drawn
  539.     If j\draw = 1
  540.         DrawImage(playerImage, j\x, j\y, j\frame)
  541.     EndIf
  542. Next
  543.  
  544. End Function 
  545.  
  546.  
  547. ;;;;;;;;;;;;;;;;;;;
  548. ;EnemyAI()
  549. ;Update the enemies' stats and determine their movements
  550. ;;;;;;;;;;;;;;;;;;;
  551. Function EnemyAI()
  552.  
  553.  
  554. ;Check every enemy ship. Determine if they should change their velocities, make sure they dont hit any walls, and fire their bullets
  555. For i.ship = Each ship 
  556.  
  557.     ;if the directiontime timer has gone through, change the velocity of the ship
  558.         If directiontime <= MilliSecs() - CHANGEENEMYDIRECTION 
  559.         i\xv = i\xv+Rand(-2,2)   ;nudge the x velocity
  560.         i\yv = i\yv+Rand(-2,2)   ;nude the y velocity
  561.         
  562.         ;Reset the direction reset timer after the later
  563.         resetdirectiontime = 1 
  564.     EndIf
  565.     
  566.     ;If x velocity is too large, lower it
  567.     If ixv > 5 Then
  568.        i\xv = i\xv - 2
  569.     EndIf
  570.     
  571.     ;If y velocity is too large, lower it
  572.     If i\yv > 5 Then
  573.         i\yv = i\yv - 2
  574.     EndIf
  575.     
  576.     ;If x velocity is too low, raise it
  577.     If ixv < -5 Then
  578.        i\xv = i\xv + 2
  579.     EndIf
  580.     
  581.     ;If y velocity is too low, lower it
  582.     If i\yv < -5 Then
  583.         i\yv = i\yv +2
  584.     EndIf
  585.  
  586.     ;Update ship's velocities
  587.     i\x = i\x + i\xv 
  588.     i\y = i\y + i\yv
  589.     
  590.     ;Check walls with the ship
  591.     
  592.     ;If ship hits left wall, reverse its velocity
  593.     If i\x <= 0 
  594.         i\x = 5    ;keep it on screen
  595.         i\xv = -i\xv    ;fix velocity
  596.         
  597.     ;If ship hits right wall, reverse its velocity
  598.     Else If i\x >=620
  599.         i\x = 615    ;keep it on screen
  600.         i\xv = -i\xv   ;fix its velocity
  601.     
  602.     ;If ship hits upper wall, reverse its velocity
  603.     Else If i\y <= 0  
  604.         i\y = 5    ;keep it on screen
  605.         i\yv = -i\yv  ;fix its velocity
  606.     
  607.     ;If ship hits lower wall, reverse its velocity
  608.     Else If i\y >= 410 
  609.         i\y = 405   ;keep it on screen
  610.         i\yv = -i\yv  ;fix its velocity
  611.     End If
  612.     
  613.     ;If it is time for the enemy to fire another bullet, fire the bullet
  614.     If MilliSecs() >= shotsfiredtime + TIMEBETWEENENEMYBULLETS
  615.         
  616.         ;Create the new bullet
  617.         CreateBullet(i\x,i\y,2)
  618.  
  619.         ;reset the bullet fire timer
  620.         resetshotstime = 1
  621.     EndIf
  622.     
  623.     ;Update ship's frame
  624.     i\frame = i\frame + 1
  625.  
  626.     ;make sure frame isnt too large
  627.     If i\frame >= 9
  628.         i\frame = 0
  629.     EndIf
  630.  
  631.  
  632. Next ;next ship
  633.  
  634. ;If the directiontime counter should be reset, reset it
  635. If resetdirectiontime Then 
  636.     directiontime = MilliSecs() 
  637.     resetdirectiontime = 0
  638. EndIf
  639.  
  640. ;If the shotstime counter should be reset, reset it
  641. If resetshotstime Then
  642.     shotsfiredtime = MilliSecs()
  643.     resetshotstime = 0
  644. EndIf
  645.  
  646.  
  647. End Function
  648.  
  649.  
  650. ;;;;;;;;;;;;;;;;;;;
  651. ;DrawHUD()
  652. ;Draws the HUD - the displays, health, etc.
  653. ;;;;;;;;;;;;;;;;;;;
  654.  
  655. Function DrawHUD()
  656.  
  657. ;increment health's frame
  658. healthframe = healthframe + 1
  659.  
  660. ;don't let health frame get too large
  661. If healthframe >=10
  662.     healthframe = 0
  663. EndIf
  664.  
  665. ;Draw as many hitpoints on the HUD as hitpoints the player has remaining
  666. For i=1 To player\hits
  667.  
  668.     ;Draw healthimage in topleft
  669.     DrawImage healthimage,i*50 - 35,10,healthframe
  670.  
  671. Next
  672.  
  673. ;Display topright info
  674. Text 510, 10, "Enemy Hits:  " + enemyhits 
  675. Text 510, 30, "Shots Fired: " + shotsfired
  676.  
  677. End Function
  678.  
  679. ;;;;;;;;;;;;;;;;;;;
  680. ;CreateExplosions
  681. ;Creates an explosion. First parameter is x coordinate, second is y coord, and thrid is 1 if  the explosion is from a player, and 2 if from an enemy
  682. ;;;;;;;;;;;;;;;;;;;
  683.  
  684. Function CreateExplosion(x,y,from)
  685.  
  686. ex.explosion = New explosion
  687. ex\x = x
  688. ex\y = y
  689. ex\from = from
  690. ex\frame = 0
  691.  
  692. End Function
  693.  
  694. ;;;;;;;;;;;;;;;;;;;
  695. ;UpdateExposions()
  696. ;Updates all of the enemy explosions
  697. ;;;;;;;;;;;;;;;;;;;
  698.  
  699. Function UpdateExplosions()
  700.  
  701.  
  702. For ex.explosion = Each explosion
  703. ;If explosion is from enemy, draw it and update it
  704.  
  705.  
  706.     DrawImage enemyexplosionimage,ex\x,ex\y,ex\frame
  707.  
  708.  
  709.     ;Update explosion
  710.     ex\frame = ex\frame + 1
  711.  
  712.     ;if the enemy has exploded, delete the explosion
  713.     ;Don't delete player explosions, we need it to detect when the player has dies
  714.     If ex\from = 2
  715.     If ex\frame>=7    
  716.         Delete ex
  717.     EndIf
  718.     EndIf
  719. Next
  720. End Function
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727. ;;;;;;;;;;;;;;;;;;;
  728. ;GameOver()
  729. ;Deletes every object, quits game
  730. ;;;;;;;;;;;;;;;;;;;
  731.  
  732. Function GameOver()
  733.  
  734.  
  735.  
  736.  
  737. Text 320,270, "Press Any Key To Quit.",True,True
  738. Flip
  739.  
  740. ;Delay for 2 seconds
  741. Delay 2000
  742.  
  743. ;Clear the key buffer
  744. FlushKeys
  745.  
  746. ;Wait for user to press something
  747. WaitKey()
  748.  
  749. ;Delete all the bullets
  750. For i.bullet = Each bullet 
  751.     Delete i
  752. Next
  753.  
  754. ;Delete all the enemy ships
  755. For e.ship = Each ship 
  756.     Delete e
  757. Next
  758.  
  759. ;Delete the player
  760. For u.user = Each user ;Delete player
  761.     Delete u
  762. Next
  763.  
  764. ;End the game
  765. End
  766. End Function