aka "so, you want to write a game, do you?"
© 2008 PeeJay
© 2008 PeeJay
Warning: Undefined array key "keywords_en" 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 Warning: Undefined array key "commercials" in /mnt/web218/a3/28/510129628/htdocs/main.php on line 261
LOADSOUND "shot.wav",0,1 LOADSOUND "ow.wav",1,1Like 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.