Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 110 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 118 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 123 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 173 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 175 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 175 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 208 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 292 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/main.php on line 292 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/config.php on line 36 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/config.php on line 37 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/lang.php on line 55 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/lang.php on line 55 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/lang.php on line 110 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/lang.php on line 110 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 201 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 201 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 216 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 216 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 231 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 232 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 232 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 233 Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /mnt/web218/a3/28/510129628/htdocs/border_html5.php on line 233 Warning: Undefined array key "keywords_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 234 Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /mnt/web218/a3/28/510129628/htdocs/main.php on line 234 Warning: Undefined array key "description_en" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 235 Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /mnt/web218/a3/28/510129628/htdocs/main.php on line 235 Warning: Undefined array key "commercials" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 261 Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /mnt/web218/a3/28/510129628/htdocs/main.php on line 285 Tutorial 7

Tutorial 7

GL (very) Basic Tutorial

aka "so, you want to write a game, do you?"
© 2008 PeeJay

Lesson 7 - Things can only get better!

As described in the last lesson, here we are looking at how we can limit the rate of firing, and how we can adjust the graphic shown according to firing. If you take a quick look at the player imagestrip, you will now notice 8 new images at the bottom, showing our player firing his weapon. We are only using one image to show firing in each direction - this is fairly crude, but will suffice for the object of the exercise.
So, first off, let's look at limiting the rate of firing. We have made 2 new global variables, bulletspeed and bulletfired. The first of these describes how fast we want to be able to fire our weapon, and the second is a count so we know when we are ready to fire again.
Now, take a look in the updateplayer function. Only if bulletfired is zero do we test for the keypress to fire the weapon, otherwise we just reduce the counter - thus acting as a limit to how quickly we can fire. Neat, eh?
Next we have edited the addbullet function, since when we fire a bullet we then want to start the counter off - so we set the counter to the value held in bulletspeed (in this case, 20). Why not just set it to value 20? Well, we could, but now imagine writing a space shooter. Think of collecting power-ups to increase your rate of fire. Using this method it can easily be achieved, by then just reducing the value held in bulletspeed.
Finally, we want to adjust the graphic if we have just fired a bullet. Look in the drawscreen function. We check to see whether the counter is within 4 cycles of the maximum the counter can be - if it is, we use the new graphic, if not, we use the normal graphic. Isn't that easy?

https://www.glbasic.com/files/tutorial/ImgLesson7.png
So, what comes next? Well, I suppose we need to check to see whether any of the bullets have hit any of the enemies. Otherwise the game is a little pointless! So, assuming you have understood everything so far, we'd better move on to the next lesson!
Download the Source Code and Media Files
Previous Lession
Next Lession