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 6

Tutorial 6

GL (very) Basic Tutorial

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

Lesson 6 - Bullet Time!

Now we are going to add the bullets. I am not doing to explain many commands in this lesson, since you have come across most of them all before - I am merely going to explain what is doing what.
We now have a new graphic loaded, bullet.bmp - we'll be using this as our bullet.
We have set up a new type to hold details on each of the bullets, with fields to hold the x and y location, and the difference in x and y between frames.
In our updateplayer function we add a test to see whether left or right control has been pressed - if so, we will create a new bullet.
This function will add a bullet, but add 13 pixels to the players x and y co-ordinates - this is simply to make the bullets start location the center of our character - our bullet graphic is much smaller than our player graphic.
It will then examine the direction the player is facing, and setup the amount to update the bullets x and y co-ordinates accordingly.
At this point, a new command is introduced -
	SELECT pldir
		CASE 0
			bull.buldifx=0
			bull.buldify=-8
		CASE 1
			bull.buldifx=-6
			bull.buldify=-6
		(etc)
	ENDSELECT
SELECT is a quick way of doing lots of IF - ENDIF's testing the same variable - in this case, pldir. I could have just as easily have been written:
	IF pldir=0
		bull.buldifx=0
		bull.buldify=-8
	ENDIF
	IF pldir=1
		bull.buldifx=-6
		bull.buldify=-6
	ENDIF
	(etc)
but using SELECT can save you quite a bit of typing!
Just as with the enemies, for every game loop we need to update the bullets, and when drawing the screen, we will need to draw the bullets.
Now, run the program - woohoo, we can fire! But, we have a problem - our character seems to have some sort of mega machine gun! This is because every time the player is updated, we have the capability of adding another bullet? Can you think of a way of slowing down the firing? This will be discussed in the next lesson, as well as using this system to add a firing graphic to our main character.
If you've understood everything we've done so far, well done! We've discussed some fairly difficult topics, and, although they are only used very simply in this game, a little imagination could produce something extremely complex. If you have an idea on how to slow down the firing, very well done indeed - programming is all about solving problems by logical thinking. If you haven't, again, don't worry - you'll see how I've chosen to do it in the next lesson, and hopefully you'll remember how to do it for your own games.

https://www.glbasic.com/files/tutorial/ImgLesson6.png