From 05b30a5b1d0771fcec337c0f388098f5794e63ee Mon Sep 17 00:00:00 2001 From: "Martin Felis (berta)" Date: Wed, 1 Dec 2010 10:02:26 +0100 Subject: [PATCH] player sounds and controls get reset when player dies or the game ends --- asteroids/Controller.cc | 20 ++++++++++++++++++++ asteroids/Controller.h | 2 ++ asteroids/View.cc | 8 +++----- engine/Sprite.cc | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/asteroids/Controller.cc b/asteroids/Controller.cc index f9166d8..c5ad7ab 100644 --- a/asteroids/Controller.cc +++ b/asteroids/Controller.cc @@ -1,5 +1,8 @@ +#include "Game.h" + #include "Controller.h" #include "AsteroidsEvents.h" +#include "Model.h" namespace asteroids { @@ -29,4 +32,21 @@ bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) { return false; } +void Controller::ResetPlayerEntity () { + Engine::HaltSoundLoop("./data/sounds/thrust.wav"); + + Engine::EntityBase *player_entity = GetModel()->GetEntity(GetModel()->GetPlayerEntityId()); + + // if we were unable to get the player then there is no need to invalidate + // the state + if (!player_entity) + return; + + int i; + for (i = 0; i < EntityControllerMaxKeyStates; i++) + player_entity->UnsetControllerKeyState(i); + + GetModel()->SetPlayerEntityId(Engine::NullEntityId); +} + } diff --git a/asteroids/Controller.h b/asteroids/Controller.h index 119a3e4..018bbb2 100644 --- a/asteroids/Controller.h +++ b/asteroids/Controller.h @@ -21,6 +21,8 @@ enum EntityControllerKeyState { class Controller : public Engine::ControllerBase { public: Controller () {}; + + void ResetPlayerEntity (); protected: /** \brief Set up basic keybindings */ virtual int OnInit (int argc, char* argv[]); diff --git a/asteroids/View.cc b/asteroids/View.cc index 909f891..044d4b7 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -100,7 +100,7 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) { break; case EventLevelComplete: PushViewState(ViewStateLevelComplete); - GetModel()->SetPlayerEntityId(Engine::NullEntityId); + GetController()->ResetPlayerEntity(); break; case EventGameOver: @@ -108,15 +108,13 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) { PopViewState(); PushViewState(ViewStateGameOver); - - GetModel()->SetPlayerEntityId(Engine::NullEntityId); + GetController()->ResetPlayerEntity(); break; case EventPlayerDied: mFadeTimerSecValue = 2.; PushViewState(ViewStatePlayerDied); - - GetModel()->SetPlayerEntityId(Engine::NullEntityId); + GetController()->ResetPlayerEntity(); break; case EventShipExplode: { diff --git a/engine/Sprite.cc b/engine/Sprite.cc index caf9dd3..3c30cd1 100644 --- a/engine/Sprite.cc +++ b/engine/Sprite.cc @@ -127,9 +127,19 @@ bool Sprite::LoadFromPNG (const char *filename) { //Now generate the OpenGL texture object glGenTextures(1, &mGlTextureName); glBindTexture(GL_TEXTURE_2D, mGlTextureName); - glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA, mWidth, mHeight, 0, + + bool mipmap = false; + + if (mipmap) { + gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, mWidth, mHeight, + GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) image_data); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + } else { + glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) image_data); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } + //clean up memory and close stuff png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);