// #include "Engine.h" #include "Controller.h" #include "Model.h" #include "EntityBase.h" #include "EventsBase.h" #include "Controller.h" #include "ShipEntity.h" #include "AsteroidsEvents.h" namespace asteroids { static Controller *ControllerInstance = NULL; /* +forward */ bool Cmd_ControllerForwardDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateForward); Engine::EventBasePtr forward_event (new Engine::EventBase()); forward_event->mEventType = EventAccelerateStart; QueueEvent (forward_event); return true; } return false; } /* -forward */ bool Cmd_ControllerForwardUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateForward); Engine::EventBasePtr forward_event (new Engine::EventBase()); forward_event->mEventType = EventAccelerateStop; QueueEvent (forward_event); return true; } return false; } /* +back */ bool Cmd_ControllerBackDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateBack); return true; } return false; } /* -back */ bool Cmd_ControllerBackUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateBack); return true; } return false; } /* +left */ bool Cmd_ControllerLeftDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateLeft); return true; } return false; } /* -left */ bool Cmd_ControllerLeftUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateLeft); return true; } return false; } /* +right */ bool Cmd_ControllerRightDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateRight); return true; } return false; } /* -right */ bool Cmd_ControllerRightUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateRight); return true; } return false; } /* +turnleft */ bool Cmd_ControllerTurnLeftDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateTurnLeft); return true; } return false; } /* -turnleft */ bool Cmd_ControllerTurnLeftUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateTurnLeft); return true; } return false; } /* +turnright */ bool Cmd_ControllerTurnRightDown (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->SetControllerKeyState (EntityKeyStateTurnRight); return true; } return false; } /* -turnright */ bool Cmd_ControllerTurnRightUp (std::vector args) { assert (ControllerInstance); Engine::EntityBase* player_entity = Engine::GetEntity (Engine::GetPlayerEntityId()); if (player_entity) { player_entity->UnsetControllerKeyState (EntityKeyStateTurnRight); return true; } return false; } /* attack */ bool Cmd_ControllerAttack (std::vector args) { assert (ControllerInstance); ShipEntity* player_entity = (ShipEntity*) Engine::GetEntity (Engine::GetPlayerEntityId ()); assert (player_entity); player_entity->Attack (); return true; } void Controller::OnRegisterCommands () { ControllerBase::OnRegisterCommands (); ControllerInstance = this; Engine::AddCommand ("+forward", Cmd_ControllerForwardDown); Engine::AddCommand ("-forward", Cmd_ControllerForwardUp); Engine::AddCommand ("+back", Cmd_ControllerBackDown); Engine::AddCommand ("-back", Cmd_ControllerBackUp); Engine::AddCommand ("+left", Cmd_ControllerLeftDown); Engine::AddCommand ("-left", Cmd_ControllerLeftUp); Engine::AddCommand ("+right", Cmd_ControllerRightDown); Engine::AddCommand ("-right", Cmd_ControllerRightUp); Engine::AddCommand ("+turnleft", Cmd_ControllerTurnLeftDown); Engine::AddCommand ("-turnleft", Cmd_ControllerTurnLeftUp); Engine::AddCommand ("+turnright", Cmd_ControllerTurnRightDown); Engine::AddCommand ("-turnright", Cmd_ControllerTurnRightUp); Engine::AddCommand ("attack", Cmd_ControllerAttack); } }