private void Restart() { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_ESCAPE": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_PAUSED", "")); break; case "KEY_LEFT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "PLAYER_LEFT", "KEY_PRESS", "")); break; case "KEY_RIGHT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "PLAYER_RIGHT", "KEY_PRESS", "")); break; case "KEY_SPACE": AddProjectiles(); break; } break; case "KEY_RELEASE": switch (keyValue) { case "KEY_LEFT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "PLAYER_STOP", "KEY_RELEASE", "")); break; case "KEY_RIGHT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "PLAYER_STOP", "KEY_RELEASE", "")); break; } break; } }
public void InitiateStateMachine() { DIKUArcade.Window.CreateOpenGLContext(); GalagaBus.GetBus().InitializeEventBus(new List <GameEventType> { GameEventType.GameStateEvent, GameEventType.InputEvent }); stateMachine = new StateMachine(); GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine); }
public void TestEventMainMenu() { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); GalagaBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <MainMenu>()); }
public void KeyRelease(string key) { switch (key) { case "KEY_ESCAPE": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; } }
public void TestEventGameRunning() { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); GalagaBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <GameRunning>()); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_UP": if (activeButton > maxMenuButtons) { activeButton -= 1; } else { activeButton %= maxMenuButtons; } break; case "KEY_DOWN": if (activeButton < maxMenuButtons) { activeButton += 1; } else { activeButton %= maxMenuButtons; } break; case "KEY_ENTER": if (activeButton == 0) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } else if (activeButton == 1) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); } break; } break; } }
public void KeyRelease(string key) { switch (key) { case "KEY_RIGHT": case "KEY_LEFT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "MOVE_STOP", "", "")); break; } }
// Check if enemy has won by checking if enemy input // has reached the bottom of the screen, Position.Y <= 0 private void CheckIfEnemyHasWon(Enemy enemy) { if (enemy.Shape.Position.Y <= 0) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors(GameEventType.StatusEvent, this, "GAME_OVER", "", "")); isGameOver = true; squiggleSquadron.Enemies.ClearContainer(); playerShots.Clear(); } }
public void HandleKeyEvent(string keyValue, string keyAction) { if (keyAction == "KEY_PRESS") { switch (keyValue) { case "KEY_UP": if (activeMenuButton == 1) { activeMenuButton = 0; inactiveMenuButton = 1; menuButtons[inactiveMenuButton].SetColor(new Vec3F(0.5f, 0.1f, 0.1f)); menuButtons[activeMenuButton].SetColor((new Vec3F(0.3f, 0.4f, 0.1f))); } break; case "KEY_DOWN": if (activeMenuButton == 0) { activeMenuButton = 1; inactiveMenuButton = 0; menuButtons[inactiveMenuButton].SetColor(new Vec3F(0.5f, 0.1f, 0.1f)); menuButtons[activeMenuButton].SetColor((new Vec3F(0.3f, 0.4f, 0.1f))); } break; case "KEY_ENTER": if (activeMenuButton == 0) { GameRunning.GetInstance().InitializeGameState(); GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } if (activeMenuButton == 1) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); } break; } } }
public StateMachine() { GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this); gameRunning = GameRunning.GetInstance(); gameRunning.InitializeGameState(); gamePaused = GamePaused.GetInstance(); gamePaused.InitializeGameState(); mainMenu = MainMenu.GetInstance(); mainMenu.InitializeGameState(); ActiveState = mainMenu; }
public void InitiateStateMachine() { DIKUArcade.Window.CreateOpenGLContext(); // Here you should: // (1) Initialize a GalagaBus with proper GameEventTypes // (2) Instantiate the StateMachine // (3) Subscribe the GalagaBus to proper GameEventTypes // and GameEventProcessors GameEventBus <object> GalagaBus = GalagaBus.eventBus(); StateMachine stateMachine = new StateMachine(); GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine); }
public void InitializeGameState() { player = new Player(game, new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)), new Image(Path.Combine("Assets", "Images", "Player.png"))); enemyStrides = ImageStride.CreateStrides(4, Path.Combine("Assets", "Images", "BlueMonster.png")); enemies = new List <Enemy>(); score = new Score(new Vec2F(0.0f, 0.0f), new Vec2F(0.2f, 0.2f)); explosionStrides = ImageStride.CreateStrides(8, Path.Combine("Assets", "Images", "Explosion.png")); explosions = new AnimationContainer(20); CreateEnemies(enemyStrides); GalagaBus.GetBus().Subscribe(GameEventType.PlayerEvent, player); }
public GamePaused(GameRunning aCurrentGame) { if (Score.GetInstance().TrueVictory()) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_OVER", ""));; } currentGame = aCurrentGame; maxMenuButtons = menuButtons.Length; buttonSelectImage.Shape.Rotate(0.5f * (float)Math.PI); }
public void InitiateStateMachine() { GalagaBus.GetBus().InitializeEventBus(new List <GameEventType>() { GameEventType.InputEvent, GameEventType.WindowEvent, GameEventType.GameStateEvent, GameEventType.PlayerEvent }); Game game = new Game(); stateMachine = new StateMachine(game); }
public void Enter() { switch (activeMenuButton) { case 0: GalagaBus.GetBus().RegisterEvent(GameEventFactory <object> .CreateGameEventForAllProcessors(GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "MAIN_MENU")); break; case 1: GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors(GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; } }
public void HandleKeyEvent(string keyValue, string keyAction) { if (keyAction == "KEY_PRESS") { switch (keyValue) { case "KEY_UP": if (activeMenuButton > 0) { menuButtons[activeMenuButton].SetColor(new Vec3F(1.0f, 0.0f, 0.0f)); activeMenuButton--; menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f)); } break; case "KEY_DOWN": if (activeMenuButton < maxMenuButtons - 1) { menuButtons[activeMenuButton].SetColor(new Vec3F(1.0f, 0.0f, 0.0f)); activeMenuButton++; menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f)); } break; case "KEY_ENTER": if (activeMenuButton == 1) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); } else if (activeMenuButton == 0) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } break; } } }
public void MoveEnemy(Enemy enemy) { DynamicShape dynamicShape = enemy.Shape.AsDynamicShape(); dynamicShape.ChangeDirection(new Vec2F(0.0f, -0.001f * speedMultiplier)); if ((dynamicShape.Position.Y + dynamicShape.Direction.Y) > 0.0f) { dynamicShape.Move(); } else { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "GAME_OVER", "", "")); } }
public void ActivateButton() { switch (Math.Abs(activeMenuButton % maxMenuButtons)) { case 0: GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); break; case 1: GameRunning.NewInstance(); GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); break; } }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_P": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); break; } break; } }
public void MoveEnemy(Enemy enemy) { DynamicShape dynamicShape = enemy.Shape.AsDynamicShape(); float y = dynamicShape.Position.Y - (s * speedMultiplier); float x = (float)(enemy.startPositionX + a * Math.Sin( (2 * Math.PI * (enemy.startPositionY - y)) / p)); if (y > 0.0f) { dynamicShape.SetPosition(new Vec2F(x, y)); } else { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "GAME_OVER", "", "")); } }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_UP": activeMenuButton = Math.Max(0, activeMenuButton - 1); break; case "KEY_DOWN": activeMenuButton = Math.Min(maxMenuButtons, activeMenuButton + 1); break; case "KEY_ENTER": switch (activeMenuButton) { case 0: GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); break; case 1: GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; } break; } break; } }
public Game() { win = new Window("Galaga", 500, 500); gameTimer = new GameTimer(60, 60); GalagaBus.GetBus().InitializeEventBus(new List <GameEventType> { GameEventType.InputEvent, GameEventType.WindowEvent, GameEventType.MovementEvent, GameEventType.StatusEvent, GameEventType.GameStateEvent }); win.RegisterEventBus(GalagaBus.GetBus()); GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.WindowEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.StatusEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); stateMachine = new StateMachine(); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyAction) { case "KEY_PRESS": switch (keyValue) { case "KEY_DOWN": if (activeMenuButton < maxMenuButtons) { menuButtons[activeMenuButton].SetColor(textColour); activeMenuButton += 1; menuButtons[activeMenuButton].SetColor(textColourSelected); } break; case "KEY_UP": if (activeMenuButton > 0) { menuButtons[activeMenuButton].SetColor(textColour); activeMenuButton -= 1; menuButtons[activeMenuButton].SetColor(textColourSelected); } break; case "KEY_ENTER": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "GAME_STATE", "GAME_RUNNING", "")); break; default: break; } break; case "KEY_RELEASE": break; } }
public void InitializeGameState() { player = new Player( new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)), new Image(Path.Combine("Assets", "Images", "Player.png")), this); GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, player); enemyStrides = ImageStride.CreateStrides(4, Path.Combine("Assets", "Images", "BlueMonster.png")); enemies = new EntityContainer <Enemy>(); explosionStrides = ImageStride.CreateStrides(8, Path.Combine("Assets", "Images", "Explosion.png")); explosions = new AnimationContainer(100); playerShots = new List <PlayerShot>(); score = new Score(new Vec2F(0.8f, 0.8f), new Vec2F(0.2f, 0.2f)); speedMultiplier = 1; random = new Random(); }
public Game() { win = new Window("WindowName", 500, 500); gameTimer = new GameTimer(50, 50); //eventBus = new GameEventBus<object>(); GalagaBus.GetBus().InitializeEventBus(new List <GameEventType>() { GameEventType.InputEvent, // key press / key release GameEventType.WindowEvent, // messages to the window //GameEventType.PlayerEvent GameEventType.GameStateEvent }); win.RegisterEventBus(GalagaBus.GetBus()); //GalagaBus.GetBus().Subscribe(GameEventType.PlayerEvent, player); GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.WindowEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); stateMachine = new StateMachine(); }
public void GameLoop() { while (win.IsRunning()) { gameTimer.MeasureTime(); while (gameTimer.ShouldUpdate()) { win.PollEvents(); stateMachine.ActiveState.UpdateGameLogic(); GalagaBus.GetBus().ProcessEvents(); } if (gameTimer.ShouldRender()) { win.Clear(); stateMachine.ActiveState.RenderState(); win.SwapBuffers(); } if (gameTimer.ShouldReset()) { win.Title = "Galaga | UPS: " + gameTimer.CapturedUpdates + ", FPS: " + gameTimer.CapturedFrames; } } }
public void ItterateEnemies() { if (enemies.CountEntities() == 0) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_WON", "")); } enemies.Iterate(delegate(Enemy enemy) { if (enemy.Shape.Position.Y < 0f) { GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_LOST", "")); } }); }
public void HandleKeyEvent(string keyValue, string keyAction) { if (keyAction == "KEY_PRESS") { switch (keyValue) { case "KEY_ESCAPE": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_PAUSED", "")); break; case "KEY_LEFT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "SET_DIRECTION", "LEFT", "")); break; case "KEY_RIGHT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "SET_DIRECTION", "RIGHT", "")); break; case "KEY_SPACE": Level.AddShot(); break; case "KEY_F": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "LOSE_LIFE", "", "")); break; } } else if (keyAction == "KEY_RELEASE") { switch (keyValue) { case "KEY_LEFT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "SET_DIRECTION", "RIGHT", "")); break; case "KEY_RIGHT": GalagaBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "SET_DIRECTION", "LEFT", "")); break; } } }
public StateMachine() { GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); GalagaBus.GetBus().Subscribe(GameEventType.InputEvent, this); ActiveState = MainMenu.GetInstance(); }