player sounds and controls get reset when player dies or the game ends
parent
083617ea64
commit
05b30a5b1d
|
@ -1,5 +1,8 @@
|
||||||
|
#include "Game.h"
|
||||||
|
|
||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#include "AsteroidsEvents.h"
|
#include "AsteroidsEvents.h"
|
||||||
|
#include "Model.h"
|
||||||
|
|
||||||
namespace asteroids {
|
namespace asteroids {
|
||||||
|
|
||||||
|
@ -29,4 +32,21 @@ bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ enum EntityControllerKeyState {
|
||||||
class Controller : public Engine::ControllerBase {
|
class Controller : public Engine::ControllerBase {
|
||||||
public:
|
public:
|
||||||
Controller () {};
|
Controller () {};
|
||||||
|
|
||||||
|
void ResetPlayerEntity ();
|
||||||
protected:
|
protected:
|
||||||
/** \brief Set up basic keybindings */
|
/** \brief Set up basic keybindings */
|
||||||
virtual int OnInit (int argc, char* argv[]);
|
virtual int OnInit (int argc, char* argv[]);
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||||
break;
|
break;
|
||||||
case EventLevelComplete:
|
case EventLevelComplete:
|
||||||
PushViewState(ViewStateLevelComplete);
|
PushViewState(ViewStateLevelComplete);
|
||||||
GetModel()->SetPlayerEntityId(Engine::NullEntityId);
|
GetController()->ResetPlayerEntity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EventGameOver:
|
case EventGameOver:
|
||||||
|
@ -108,15 +108,13 @@ bool View::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
||||||
|
|
||||||
PopViewState();
|
PopViewState();
|
||||||
PushViewState(ViewStateGameOver);
|
PushViewState(ViewStateGameOver);
|
||||||
|
GetController()->ResetPlayerEntity();
|
||||||
GetModel()->SetPlayerEntityId(Engine::NullEntityId);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventPlayerDied:
|
case EventPlayerDied:
|
||||||
mFadeTimerSecValue = 2.;
|
mFadeTimerSecValue = 2.;
|
||||||
PushViewState(ViewStatePlayerDied);
|
PushViewState(ViewStatePlayerDied);
|
||||||
|
GetController()->ResetPlayerEntity();
|
||||||
GetModel()->SetPlayerEntityId(Engine::NullEntityId);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case EventShipExplode: {
|
case EventShipExplode: {
|
||||||
|
|
|
@ -127,9 +127,19 @@ bool Sprite::LoadFromPNG (const char *filename) {
|
||||||
//Now generate the OpenGL texture object
|
//Now generate the OpenGL texture object
|
||||||
glGenTextures(1, &mGlTextureName);
|
glGenTextures(1, &mGlTextureName);
|
||||||
glBindTexture(GL_TEXTURE_2D, mGlTextureName);
|
glBindTexture(GL_TEXTURE_2D, mGlTextureName);
|
||||||
|
|
||||||
|
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,
|
glTexImage2D(GL_TEXTURE_2D,0, GL_RGBA, mWidth, mHeight, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*) image_data);
|
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
|
//clean up memory and close stuff
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
|
||||||
|
|
Loading…
Reference in New Issue