Time Remaining

As discussed earlier in this chapter, the game will end when one of two things happen: either all the gallery items have been destroyed or three minutes have elapsed. In order to time the game, we need to create two timers—one outside the game loop that will start the timer and one inside the game loop that will indicate the current time in the game. When we subtract the current time from the start time, we’ll end up with how much time has elapsed. Start by creating a variable called starttime just before the game loop:

;Defining the starting time of the game
starttime=MilliSecs()
;The following code makes our program run
While Not KeyDown(ESC_KEY)

Now we’ll create two more variables within the game loop: one called currenttime that will indicate the current time in the game and will change with every loop of the game and then another one called timeleft.

UpdateWorld
RenderWorld
currenttime = MilliSecs()
timeleft= 180000 - ((currenttime - starttime))

Let’s take a closer look at the timeleft variable. Keep in mind that we want our game to be three minutes long, which is 180,000 milliseconds. So we subtract the starttime from the currenttime to see how many milliseconds have passed. We then subtract this from 180,000 to see how many milliseconds are left in the game.

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

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