public StateMachine() { ActiveState = MainMenu.GetInstance(); _eventBus = SpaceTaxiBus.GetBus(); _eventBus.Subscribe(GameEventType.InputEvent, this); _eventBus.Subscribe(GameEventType.GameStateEvent, this); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyValue) { case "KEY_Q": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; case "KEY_P": if (keyAction == "KEY_RELEASE") { SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "GAME_RUNNING", "", "")); } break; case "KEY_N": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "NEW_GAME", "CHANGE_STATE", "")); break; } }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyValue) { // create a playerEvent of the with keyValue = messege and KeyAction = Parameter1 // in case of the to cases belove. case "KEY_UP": case "KEY_LEFT": case "KEY_RIGHT": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, keyValue, keyAction, "")); break; case "KEY_ESCAPE": if (keyAction == "KEY_RELEASE") { SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_PAUSED", "")); } break; } }
public void ProcessEvent(GameEventType eventType, GameEvent <object> gameEvent) { switch (eventType) { // All key inputs are been handle by the active state. case GameEventType.InputEvent: ActiveState.HandleKeyEvent(gameEvent.Message, gameEvent.Parameter1); break; case GameEventType.GameStateEvent: switch (gameEvent.Message) { case "GAME_RUNNING": SwitchState(GameStateType.GameRunning); break; case "QUIT": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; case "GAME_PAUSED": SwitchState(GameStateType.GamePaused); break; case "NEXT_LEVEL": SwitchState(GameStateType.NextLevel); break; case "NEW_GAME": SwitchState(GameStateType.NewGame); break; case "MAIN_MENU": SwitchState(GameStateType.MainMenu); break; } break; } }
public void HandleKeyEvent(string keyValue, string keyAction) { if (keyAction == "KEY_RELEASE") { switch (keyValue) { case "KEY_UP": menuButtons[activeMenuButtons].SetColor(darkRed); if (activeMenuButtons == 0) { activeMenuButtons = maxMenuButtons; } else { activeMenuButtons--; } menuButtons[activeMenuButtons].SetColor(darkGreen); break; case "KEY_DOWN": menuButtons[activeMenuButtons].SetColor(darkRed); if (activeMenuButtons == maxMenuButtons) { activeMenuButtons = 0; } else { activeMenuButtons++; } menuButtons[activeMenuButtons].SetColor(darkGreen); break; case "KEY_ENTER": switch (activeMenuButtons) { case 0: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "NEW_GAME", "", "") ); break; case 1: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "QUIT", "", "") ); break; } break; } switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_UP": activeMenuButtons--; if (activeMenuButtons < 0) { activeMenuButtons = maxMenuButtons; } break; case "KEY_DOWN": activeMenuButtons++; activeMenuButtons %= 2; break; } break; } } }