Creating a complete game: Breakout
This document has been updated for use with GapiDraw 4.0 or later.
Step 12 : Sound
Previous step | Next step
In this last step we will add sound effects to our game. We will use the standard Win32 waveOut API for sound effects, and I will base my code upon an example project that was downloaded from the Pocket PC Developer Network.
Begin by downloading the file wavefile.h and save it in your Breakout\common folder. This file exposes a simple to use API to playback sounds. Using this API you can play multiple sounds simultaneously as well as loop sounds.
Then download the files reflect_brick.wav and reflect_bat.wav and save them in the same folder as Breakout.exe. Remember that if you run Breakout from the Visual Studio environment, the current folder when running the application will be the same folder as the solution file (.SLN), so place the wave files there if you want to run Breakout.exe with sounds from the Visual Studio environment. Also, if you plan to run Breakout.exe in the emulator or on a Windows Mobile device you will have to copy the wave files manually to the device.
Add the following code to myapplication.h:
Add the following code to myapplication.cpp:
That's it! You will now have audio playback in your game!
This was the last step in our Breakout tutorial, and we hope you enjoyed it! Now go and copy the Minimal application and create your own game!