Sounds

Before we’re ready to sit down and play our game for hours, let’s add just a few sound effects. In particular, we’ll create sounds when a bullet is fired and when a gallery target is hit. If you remember Chapter 12, “Sounds,” you’ll know that we need to start by loading our sounds, which we’ll do right after the Welcome function at the beginning of the game:

Return
EndIf
Wend
End Function
; Loading the sounds phaser=LoadSound("phaser.wav")
explosion=LoadSound("explode.wav")

Next we need to associate the sound whenever a bullet is fired:

;Firing bullets
      If KeyHit (SPACE_BAR) And reload=0
      PlaySound phaser
      PositionEntity bullet(t),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1)

We also need to add a sound whenever a gallery item is destroyed, also in the “Firing bullets” section:

For q = 0 To maxbull
    MoveEntity bullet(q), 0,0.8,3
    If CountCollisions (bullet(q))
      crash=CollisionEntity (bullet(q),1)
      HideEntity crash
      score#=score#+1
      PlaySound explosion
    EndIf

That’s it! Your game is complete. Congratulations. Now . . . enjoy!

Note: Not Working?

If for any reason your game isn’t working, open the file called shootinggallery.bb, which contains a working version of the final game. Compare your code to the code in the final version to see where things went wrong.


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

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