Smalltalk Programming
Adding Sound

Below is code that you can use to play sound for when an enemy is destroyed in your game.

1. Type and save the code below. (Note: Provide the full path and filename for the HitSound.wav file. If you prefer to use just the filename, place the HitSound.wav file in the “shared” directory within the main directory of Squeak.)

Shot>>hitEnemy: enemy
    
owner points: 100.
    
self delete.
    
enemy delete.
    
(SampledSound fromWaveFileNamed: 'HitSound.wav') play

2. What a great addition to your game! What else might be nice to have for your shooter game?

3. Save and Quit your Smalltalk image.

Download the PDF version.