2010-12-01 10:02:26 +01:00
|
|
|
#include "Game.h"
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
#include "Controller.h"
|
2010-09-11 02:28:50 +02:00
|
|
|
#include "AsteroidsEvents.h"
|
2010-12-01 10:02:26 +01:00
|
|
|
#include "Model.h"
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
namespace asteroids {
|
|
|
|
|
|
|
|
int Controller::OnInit (int argc, char *argv[]) {
|
|
|
|
Engine::ControllerBase::OnInit (argc, argv);
|
|
|
|
|
2010-12-02 19:56:55 +01:00
|
|
|
mBindings[SDLK_UP] = "+forward";
|
|
|
|
mBindings[SDLK_LEFT] = "+turnleft";
|
|
|
|
mBindings[SDLK_RIGHT] = "+turnright";
|
2010-04-05 23:38:59 +02:00
|
|
|
|
|
|
|
mBindings[SDLK_SPACE] = "attack";
|
|
|
|
|
|
|
|
mBindings[SDLK_F8] = "toggleconsole";
|
|
|
|
mBindings[SDLK_F9] = "set playerspeed 5.0";
|
|
|
|
|
2010-11-28 01:13:45 +01:00
|
|
|
Engine::RegisterListener (this, EventChangeViewState);
|
2010-09-11 02:28:50 +02:00
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-11 02:28:50 +02:00
|
|
|
bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) {
|
2010-11-28 01:13:45 +01:00
|
|
|
if (event->mEventType == EventChangeViewState) {
|
2010-09-11 02:28:50 +02:00
|
|
|
IMGUIClear();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-12-01 10:02:26 +01:00
|
|
|
void Controller::ResetPlayerEntity () {
|
2010-12-03 00:15:26 +01:00
|
|
|
Engine::HaltSoundLoop(Engine::GetResourceFullPath("/data/sounds/thrust.wav"));
|
2010-12-01 10:02:26 +01:00
|
|
|
|
2011-02-12 16:34:47 +01:00
|
|
|
// Reset the angular velocity of the player entity if one exists
|
|
|
|
if (GetModel()->GetPlayerEntityId() != Engine::NullEntityId) {
|
|
|
|
Engine::EntityBase *player_entity = GetModel()->GetEntity(GetModel()->GetPlayerEntityId());
|
|
|
|
player_entity->mPhysicState->mAngleVelocity = 0.;
|
2010-12-01 10:02:26 +01:00
|
|
|
|
2011-02-12 16:34:47 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < EntityControllerMaxKeyStates; i++)
|
|
|
|
player_entity->UnsetControllerKeyState(i);
|
2010-12-01 10:02:26 +01:00
|
|
|
|
2011-02-12 16:34:47 +01:00
|
|
|
}
|
2010-12-01 10:02:26 +01:00
|
|
|
|
2011-02-12 16:34:47 +01:00
|
|
|
// We definitely have to reset the player entity id
|
|
|
|
GetModel()->SetPlayerEntityId(Engine::NullEntityId);
|
2010-12-01 10:02:26 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 18:25:20 +01:00
|
|
|
void Controller::ResetLevel() {
|
|
|
|
Engine::LogMessage ("Resetting level");
|
|
|
|
|
|
|
|
GetModel()->ClearEntities();
|
|
|
|
GetModel()->mAsteroids.clear();
|
|
|
|
ResetPlayerEntity();
|
|
|
|
}
|
|
|
|
|
2010-04-05 23:38:59 +02:00
|
|
|
}
|