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 "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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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[]);
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -127,9 +127,19 @@ bool Sprite::LoadFromPNG (const char *filename) {
|
|||
//Now generate the OpenGL texture object
|
||||
glGenTextures(1, &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,
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue