Empty Your Mind Tutorial 6

This tutorial will teach you how to use the SwinGameSDK to develop a simple danmaku game which looks cool. At the end of this tutorial you should be able to use pascal to implement your own space invaders or scrolling shooter style game which makes use of Vectors, animated Sprites, SoundEffects, and Music.

Playing A Music
Music playback can be done very easily. To load a music you will need to use the Game Resources. The loaded music data can be obtained by calling GameMusic routine.

The game's music should be contained in the GameData structure to simplify the data structure of our game. The following code is the new implementation of the GameData structure.

You will need to assign the music entry in your LoadGame routine so you can play the music when the game starts. The loaded music can b played by calling the PlayMusic routine.

To sptop the music you need to call the StopMusic routine. This routine does not take any parameters.

The PlayMusic routine must be called before the game loop. The StopMusic routine must be called after the game loop. Thefore, your MainGame routine should look like something similar to this…

Playing A Sound Effect
Sound effect can be played easily like the music. Sound effect should also be loaded from the Game Resources. To manage the sound effect, we will need to expand the GameData structure again. This can be done by creating an array of sound effect. You will need to initialise the array and assign the sound effects to the array. The new GameData structure should look something similar to this…

Sound effect can be played very easily by calling PlaySoundEffect routine. You will need to pass the sound effect you have loaded from the Game Resources by calling GameSound routine. Therefore, you will need to insert the following code into your ShootPlayerBullet to play the bullet sound. The example sound effect data can be found [[Media:Shoot.wav.zip|here]].

Summary
In this tutorial, I have gone through: The current project files can be downloaded from [[Media:EYM_11_04.zip|here]].
 * Playing a music
 * Playing a sound effect