private void SwitchState(StateTransformer.GameStateType stateType) { switch (stateType) { case StateTransformer.GameStateType.MainMenu: ActiveState = MainMenu.GetInstance(); break; case StateTransformer.GameStateType.GameRunning: ActiveState = GameRunning.GetInstance(game); break; case StateTransformer.GameStateType.GamePaused: ActiveState = GamePaused.GetInstance(); break; case StateTransformer.GameStateType.ChoseLevel: ActiveState = ChoseLevel.GetInstance(); break; case StateTransformer.GameStateType.GameOver: ActiveState = GameOver.GetInstance(); break; } }
public void UpdateGameLogic() { foreach (var obstacle in currentLevel.obstacles) { var collisionData = CollisionDetection.Aabb(player.Entity.Shape.AsDynamicShape(), obstacle.Shape); if (collisionData.Collision) { if (obstacle.fileName.Equals(GetPlatformName())) { //if collision from below then gameover and explosion if (collisionData.DirectionFactor.Y < 1) { AddExplosion(player.shape.Position.X, player.shape.Position.Y, obstacle.shape.Extent.X + 0.1f, obstacle.shape.Extent.Y + 0.1f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_OVER", "")); } if (currentVelocity.Y < -0.0001f && currentVelocity.Y > -0.0075f) { isOnPlatform = true; currentVelocity.Y = 0; currentVelocity.X = 0; } } else { AddExplosion(player.shape.Position.X, player.shape.Position.Y, obstacle.shape.Extent.X + 0.1f, obstacle.shape.Extent.Y + 0.1f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_OVER", "")); } } else { if (player.shape.Position.Y > 1) { currentVelocity.Y = 0; currentVelocity.X = 0; isOnPlatform = true; GameRunning.instance = null; ChoseLevel.GetInstance().filename = "the-beach.txt"; ChoseLevel.GetInstance().posX = 0.25f; ChoseLevel.GetInstance().posY = 0.162f; SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } } } }
public static GameRunning GetInstance(Game gm) { return(GameRunning.instance ?? (GameRunning.instance = new GameRunning(gm))); }