Ending the Game

For the game to end, all of the gallery items need to be destroyed (in other words, the score has to equal 35) or the time elapsed will need to equal zero. Whenever one of those two conditions is met, a graphic will appear allowing the user to exit the game or start over. If he elects to start over, we need to have the program jump back to the beginning. We’ll accomplish this by using a Goto command. Remember that with Goto commands we need to create a bookmark so the computer knows where to jump to. In this case, we’ll create a bookmark at the beginning of the program. Add the following bookmark in bold to the game code:

;Creating a bookmark
      .start
;Setting the graphics for the program
Graphics3D 1024,768
SetBuffer BackBuffer()

Now we need to create the code that will load the graphic and jump to the starting point if the space bar is pressed when the game is over or will end the program if the Esc key is pressed. Enter the following code in bold.

;Ending the game
If score# = 35 Or timeleft < 0 Then
Cls
End=LoadImage ("end.bmp")
DrawImage End,0,0
Flip
WaitKey()
If KeyDown(ESC_KEY) Then End
If KeyDown (SPACE_BAR) Then Goto start
EndIf
UpdateWorld
RenderWorld

Play the game now and wait three minutes. At the end, the end.bmp image should appear, as in Figure 14.15

Figure 14.15. When all the gallery items are destroyed or three minutes have elapsed, the end.bmp image will appear.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.119