fixed sound playback of ship destroyed

main
Martin Felis (berta) 2011-03-24 08:26:06 +01:00
parent 69c6e1aaef
commit b4c046bae2
6 changed files with 44 additions and 9 deletions

View File

@ -29,6 +29,7 @@ class Model : public Engine::ModelBase {
void ReloadLevel();
void ProceedToNextLevel ();
int GetPlayerLives () { return mPlayerLives; };
void SetPlayerLives (int lives) { mPlayerLives = lives; };
unsigned int GetPoints () { return mPoints; };
std::string GetPlayerName() { return mPlayerName; };
void SetPlayerName(const std::string &name) {

View File

@ -601,6 +601,7 @@ void View::DrawUiGameOver() {
// We do not want the background to show the remaining bits of the game
GetModel()->SetGameState(GameStatePaused);
PopViewState();
PopViewState();
PushViewState(ViewStateShowHighscore);
}
@ -609,6 +610,10 @@ void View::DrawUiGameOver() {
void View::DrawUiLevelIntro() {
SelectFont ("console.ttf size=23");
if (level_assemble_mode) {
GetModel()->SetPlayerLives(100);
}
stringstream level_info_stream;
level_info_stream << "Level " << GetModel()->GetCurrentLevelIndex() + 1;

View File

@ -165,6 +165,9 @@ int main (int argc, char* argv[]) {
Engine::RunCommand ("exec config.rc");
Engine::PlayMusic (Engine::GetResourceFullPath("/data/sounds/intro_music.ogg"));
Engine::LoadSound(Engine::GetResourceFullPath("/data/sounds/thrust.wav"));
Engine::LoadSound(Engine::GetResourceFullPath("/data/sounds/ship_destroyed.wav"));
Engine::LoadSound(Engine::GetResourceFullPath("/data/sounds/rock_destroyed.wav"));
// load highscore list (either remote or local, depending on settings)
asteroids::GetModel()->LoadHighscoreList();

View File

@ -48,7 +48,7 @@ int SoundBase::OnInit(int argc, char* argv[]) {
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers = 1024;
int audio_buffers = 2048;
LogDebug("Sound Init");
if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, audio_buffers)) {
@ -97,6 +97,8 @@ void SoundBase::PlaySound (const std::string &sound_name) {
iter = mSamples.find(sound_name);
}
LogDebug ("Playing sound %s", sound_name.c_str());
iter->second->Play();
}
@ -116,6 +118,8 @@ void SoundBase::PlaySoundLoop (const std::string &sound_name, int count) {
iter = mSamples.find(sound_name);
}
LogDebug ("Playing sound loop %s", sound_name.c_str());
iter->second->Loop(count);
}
@ -127,15 +131,24 @@ void SoundBase::HaltSoundLoop (const std::string &sound_name) {
SampleIter iter = mSamples.find(sound_name);
if (iter == mSamples.end()) {
// nothing to stop
return;
}
LogDebug ("Halting sound loop %s", sound_name.c_str());
iter->second->Stop();
}
void SoundBase::LoadSound (const std::string &sound_name) {
SampleIter iter = mSamples.find(sound_name);
if (iter == mSamples.end()) {
SoundSamplePtr sample (new SoundSample);
sample->Load(sound_name);
mSamples[sound_name] = sample;
iter = mSamples.find(sound_name);
}
iter->second->Stop();
}
void SoundBase::PlayMusic (const std::string &music_name) {
@ -233,17 +246,26 @@ void HaltSoundLoop (const std::string &sound_name) {
SoundInstance->HaltSoundLoop(sound_name);
}
void LoadSound (const std::string &sound_name) {
if (!SoundInstance) {
LogError("Could not music volume: sound system not initialized!");
}
SoundInstance->LoadSound (sound_name);
}
void SetMusicVolume (const float &music_volume) {
if (!SoundInstance) {
LogError("Could set music volume: sound system not initialized!");
LogError("Could not set music volume: sound system not initialized!");
}
SoundInstance->SetMusicVolume(music_volume);
}
float GetMusicVolume () {
if (!SoundInstance) {
LogError("Could get music volume: sound system not initialized!");
LogError("Could not get music volume: sound system not initialized!");
}
return SoundInstance->GetMusicVolume();
@ -251,7 +273,7 @@ float GetMusicVolume () {
void SetEffectsVolume (const float &effects_volume) {
if (!SoundInstance) {
LogError("Could set effects volume: sound system not initialized!");
LogError("Could not set effects volume: sound system not initialized!");
}
SoundInstance->SetEffectsVolume(effects_volume);
@ -259,7 +281,7 @@ void SetEffectsVolume (const float &effects_volume) {
float GetEffectsVolume () {
if (!SoundInstance) {
LogError("Could get effects volume: sound system not initialized!");
LogError("Could not get effects volume: sound system not initialized!");
}
return SoundInstance->GetEffectsVolume();

View File

@ -36,6 +36,7 @@ class SoundBase : public Module {
void PlaySound (const std::string &sound_name);
void PlaySoundLoop (const std::string &sound_name, int count);
void HaltSoundLoop (const std::string &sound_name);
void LoadSound (const std::string &sound_name);
void PlayMusic (const std::string &music_name);
void HaltMusic ();

View File

@ -8,6 +8,9 @@ void PlaySoundLoop (const std::string &sound_name, int count);
void HaltSoundLoop (const std::string &sound_name);
void PlayMusic (const std::string &music_name);
/** \brief Loads a sound effect for later use */
void LoadSound (const std::string &sound_name);
/** \brief Sets the volume of the music channel to the given value
*
* \param music_value is a value from 0. (no music) to 1. (maximum volume)