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 11

Tutorial 11

GL (very) Basic Tutorial

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

Lesson 11 - Breaking the Silence

Let's get some sounds in this game then! I have only used a couple of sounds to preserve bandwidth, but obviously your game could use something far more impressive!
First of all, let's load the files in, like this:
LOADSOUND "shot.wav",0,1
LOADSOUND "ow.wav",1,1
Like when loading the graphics, this will load sounds into memory ready to play. The first number is the identifier (note, this can be the same number that you have already used for graphics - GL Basic is clever enough to know the difference between the two!). The second number relates to how many times a sound can be played without being cut off - this is best kept as low as possible to preserve memory.
Having a look in the AddBullet function, we can now see the lines
	LOCAL soundpan=(px-320)/2000
	PLAYSOUND(0,soundpan,1)
have been added. That will obviously play the sound we have preloaded, but what is slightly less obvious are the numbers involved. Look at the help for the PLAYSOUND command, and you will see it has settings for pan and volume. Here, we are panning the sound from the left and right speaker dependent on the position of the player on the screen.
There is a new function - IsPlayerHit. Take a look - it is collision detection for our player this time - for each enemy it tests whether it is in collision with our player - if so, it will play the "ow" sound (using panning again) and delete the enemy. Note, we are also taking into account the image that is being used for our player, to ensure pixel perfect collision detection.

https://www.glbasic.com/files/tutorial/ImgLesson11.png
Well, that is nearly the end of this simple introduction to GL Basic - I hope you're enjoying it so far!
Download the Source Code and Media Files
Previous Lession
Next Lession