Remake (partial) Fruity Frank ... 25 - Adding sound effects
We will add sound to the game, to have "something more than life. " To achieve this, create a new class "Sound", which will rely on "SDL_mixer" hiding the details of this library.
For example, the constructor will load a music file:
Thursday, January 8, 2009
/ / / Constructor from a file name
also need another function to stop playing sounds:
/ / / Stop any audio playback
public void Pause () {
Thus, each level will have a background music. This music class is declared in the "Level" generic:
Level {public class Sound miMusicaFondo
ReproducirMusica () {if (miMusicaFondo! = Null) Level const byte {byte i; In the game, we will have an additional music for the level change (still no sound when picking fruit or the characters die), and then, when the level change, we stop the music the previous level, play the sound level change, and then start playing the background music of the new level as well:
SiguienteNivel public void () { miNivel.PararMusica ();
public Sound (string filename) {
punteroInterno = SdlMixer.Mix_LoadMUS (filename );}
and functions will play a sound once (for example, when an enemy dies, or our character, or when pick a fruit) and to play a sound continuously (for background music):
/ / / Play once
Reproducir1 public void () {
SdlMixer.Mix_PlayMusic (punteroInterno, 1 );} / / / Play continuous (background music)
ReproducirFondo public void () {
SdlMixer.Mix_PlayMusic (punteroInterno, -1);} and functions will play a sound once (for example, when an enemy dies, or our character, or when pick a fruit) and to play a sound continuously (for background music):
/ / / Play once
Reproducir1 public void () {
SdlMixer.Mix_PlayMusic (punteroInterno, 1 );} / / / Play continuous (background music)
ReproducirFondo public void () {
also need another function to stop playing sounds:
/ / / Stop any audio playback
public void Pause () {
- SdlMixer.Mix_HaltMusic ();}
Thus, each level will have a background music. This music class is declared in the "Level" generic:
protected;
...
...
In Class "Level" also prepare their roles to play background music or to stop it, both based on the possibilities of the class "Sound" Public void
miMusicaFondo.ReproducirFondo ();}
PararMusica public void ()
{if (miMusicaFondo! = Null)
miMusicaFondo.Interrumpir () ;}
miMusicaFondo.Interrumpir () ;}
And the music is loaded into the constructor of each "child class" (because each particular level will have its own background music): public class
Level1: {
NUMENEMIGOS = 3;
public
Level1 ()
public MIMAP
map1 = new ();
miMusicaFondo = new Sound ("Sound \\ \\ fruity-nivel1.mp3"); enemy = new Enemy [NUMENEMIGOS]
...
...
musicaNuevoNivel.Reproducir1 ();
...
if (numeroNivel% 3 == 1) ...
miNivel Level1 = new ();
... miNivel.ReproducirMusica ();
only need to create the sounds folder, and save it the sounds that interest us, we will have previously captured the original game, or we will have created ourselves. We must also modify the files "BAT" responsible for collecting all sources, to include the new class "Sound."
As always, the entire project's source is: code.google.com / p / fruityfrank
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment