O'Reilly logo

3D Game Programming for Teens, Second Edition by Eric Grebler, Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required