Exercises


Exercise 30.1: Changing the sounds of Spacewar

First of all, get sound working on your computer so that you can hear the Pop Framework sounds. (You need to have a sound card with speakers, and the speakers need to be plugged in. If you double-click the little speaker icon on the upper right of your Windows taskbar, the Mute button needs to not be checked. Also don't forget to see if your speaker has a manual, physical control.) Now try removing the SND_ASYNC from the playSound calls in the gamespacewar.cpp. Rebuild the program and see how it sounds. See what happens if you OR in SND_LOOP .

Now find some other *.wav file and incorporate it into the program. Where to find a *.wav file? First you can use Start Find to look for them on your hard disk. Second, it's pretty easy to search the web for sites that have *.wav files for download. When picking sounds for effects in a game, avoid long sounds. For instance, once a student wrote a game where every time you shot something the game said 'Hasta la vista, baby,' and although that was funny the first few dozen times, it then got really old.

So get the *.wav, put it in the res subdirectory and add it to the resources. Give it a name like, say, 'Newsound.'

Now change the code so that when you shoot an asteroid it will make the 'Newsound' sound if the radius is bigger than some value, and it will make a 'Ding' sound if the radius is smaller than some value. What value? Look for some value that separates the big from the small asteroids .

Exercise 30.2: Using system sounds

Since the Ta-da sound usually lives in Windows\System directory you might get away with not including it as a resource and instead looking for the file externally with a call playSound("Tada.wav", SND_ASYNC) . See if this works.

Exercise 30.3: Encapsulating the playSound call

It's kind of a drag to have to write that stupid ((CPopApp*)::AfxGetApp())-> . all the time. Assuming that it's normally a cCritter that's going to make a call to make a sound, try adding a cCritter::playSound(CString soundname) method to the cCritter class. Let the method do the tedious fetching of CPopApp and also let it stick in the standard flags SND_RESOURCE SND_ASYNC as one of the arguments. Using this new method, add code to have the asteroids in the spacewar game make a little noise when they collide. Think of more sounds to add, too.



Software Engineering and Computer Games
Software Engineering and Computer Games
ISBN: B00406LVDU
EAN: N/A
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net