private void SwitchState(StateTransformer.GameStateType stateType) { switch (stateType) { case StateTransformer.GameStateType.MainMenu: ActiveState = MainMenu.GetInstance(); break; case StateTransformer.GameStateType.GameRunning: ActiveState = GameRunning.GetInstance(game, ChoseLevel.GetInstance().Customer); 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; case StateTransformer.GameStateType.GameWon: ActiveState = GameWon.GetInstance(); break; } }
/// <summary> /// Handles the collisions and the level changing /// </summary> /// <param name="Entities"> /// List of entities /// </param> /// <param name="player"> /// Player /// </param> public void Collisions(EntityContainer <Entity> Entities, Player player) { if (player.Entity.Shape.Position.Y >= 1f) { GameRunning.GetInstance().ChangeLevel(); } else { CollisionDetect(Entities, player); } }
public static GameRunning GetInstance(Game gm, Customer cust) { return(GameRunning.instance ?? (GameRunning.instance = new GameRunning(gm, cust))); }
public void UpdateGameLogic() { if (singletonScore.score == 300) { SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_WON", "")); } for (int i = 0; i < currentLevel.cusList.Count; i++) { collisiondatas[i] = CollisionDetection.Aabb(player.Entity.Shape.AsDynamicShape(), currentLevel.cusList[i].entity.Shape); } for (int i = 0; i < currentLevel.cusList.Count; i++) { if (collisiondatas[i].Collision) { //if no customer on board then delete (pickup) customer if (customer == null) { currentLevel.cusList[i].entity.DeleteEntity(); customer = currentLevel.cusList[i]; singletonTimer.stopwatch.Start(); } } } foreach (var obstacle in currentLevel.obstacles) { var collisionData = CollisionDetection.Aabb(player.Entity.Shape.AsDynamicShape(), obstacle.Shape); if (collisionData.Collision) { if (obstacle.fileName.Equals(GetPlatformName()[0]) || obstacle.fileName.Equals(GetPlatformName()[1]) || obstacle.fileName.Equals(GetPlatformName()[2]) || obstacle.fileName.Equals(GetPlatformName()[3])) { // lands if (customer != null) { if (obstacle.symbol.ToString().Equals(customer.landplatform) || (customer.landplatform == "^" && currentLevel.levelName == "short-n-sweet.txt")) { singletonScore.PointChanger("Add"); singletonTimer.stopwatch.Reset(); customer = null; /* if (singletonScore.score == 300) { * SpaceTaxiBus.GetBus().RegisterEvent( * GameEventFactory<object>.CreateGameEventForAllProcessors( * GameEventType.GameStateEvent, * this, * "CHANGE_STATE", * "GAME_WON", "")); * } */ } } if (currentVelocity.Y < -0.0001f && currentVelocity.Y > -0.0075f) { isOnPlatform = true; currentVelocity.Y = 0; currentVelocity.X = 0; } } else { singletonTimer.stopwatch.Reset(); ChoseLevel.GetInstance().Customer = null; singletonScore.PointChanger("Reset"); 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) { // if customer has been picked up and has to be dropped off at next level if (customer == null) { singletonTimer.stopwatch.Reset(); ChoseLevel.GetInstance().Customer = null; singletonScore.PointChanger("Reset"); //END GAME SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_OVER", "")); } else { if (customer.entity.IsDeleted()) { //change customer.platformname to remove ^ if (customer.landplatform.Contains("^")) { if (customer.landplatform.Length > 1) { customer.landplatform = customer.landplatform.Substring(1, 1); } } ChoseLevel.GetInstance().Customer = customer; } currentVelocity.Y = 0; currentVelocity.X = 0; isOnPlatform = true; GameRunning.instance = null; if (currentLevel.levelName.Equals("short-n-sweet.txt")) { ChoseLevel.GetInstance().filename = "the-beach.txt"; ChoseLevel.GetInstance().posX = 0.25f; ChoseLevel.GetInstance().posY = 0.20f; } else { ChoseLevel.GetInstance().filename = "short-n-sweet.txt"; ChoseLevel.GetInstance().posX = 0.45f; ChoseLevel.GetInstance().posY = 0.15f; } SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } } } } }