#include "Game.h" #include "Controller.h" #include "AsteroidsEvents.h" #include "Model.h" namespace asteroids { int Controller::OnInit (int argc, char *argv[]) { Engine::ControllerBase::OnInit (argc, argv); mBindings[SDLK_q] = "quit"; mBindings[SDLK_UP] = "+forward"; mBindings[SDLK_LEFT] = "+turnleft"; mBindings[SDLK_RIGHT] = "+turnright"; mBindings[SDLK_SPACE] = "attack"; mBindings[SDLK_F8] = "toggleconsole"; mBindings[SDLK_F9] = "set playerspeed 5.0"; Engine::RegisterListener (this, EventChangeViewState); return 0; } bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) { if (event->mEventType == EventChangeViewState) { IMGUIClear(); } return false; } void Controller::ResetPlayerEntity () { Engine::HaltSoundLoop(Engine::GetResourceFullPath("/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); } void Controller::ResetLevel() { Engine::LogMessage ("Resetting level"); GetModel()->ClearEntities(); GetModel()->mAsteroids.clear(); ResetPlayerEntity(); } }