public void PlayerCollision(int timerToTest, string directionValue) { gameR.player.Entity.Shape.SetPosition(new Vec2F(0.3f, 0.3f)); int i = 0; while (i < timerToTest) { if (directionValue == "Left") { gameR.currentVelocity = new Vec2F(-0.1f, 0f); gameR.UpdateGameLogic(); gameR.RenderState(); i++; } else if (directionValue == "Right") { gameR.currentVelocity = new Vec2F(0.1f, 0.0f); gameR.UpdateGameLogic(); gameR.RenderState(); i++; } else { gameR.currentVelocity = new Vec2F(0.0f, -0.1f); gameR.UpdateGameLogic(); gameR.RenderState(); i++; } } SpaceTaxiBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <GameOver>()); }
public void InitializeGameState() { eventBus = SpaceTaxiBus.GetBus(); levelManager = LevelManager.GetInstance(); levelInfos = levelManager.LevelInfos; var levels = new List <string>(); foreach (var levelInfo in levelInfos) { levels.Add(levelInfo.Name); } levelNames = levels.ToArray(); levelManager.ActiveLevelIndex = 0; selectLevelText = new Text("Please select a level \n with the arrow keys. \n ENTER to confirm:", new Vec2F(0.25f, 0.0f), new Vec2F(0.5f, 0.5f)); selectLevelText.SetColor(Color.White); selectLevelText.SetFontSize(35); levelTextBox = new Text(levelNames.First(), new Vec2F(0.3f, -0.2f), new Vec2F(0.5f, 0.5f)); levelTextBox.SetColor(Color.White); levelTextBox.SetFontSize(35); background = new Entity( new StationaryShape(new Vec2F(0f, 0f), new Vec2F(1f, 1f)), new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"))); }
public StateMachine() { SpaceTaxiBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); SpaceTaxiBus.GetBus().Subscribe(GameEventType.WindowEvent, this); SpaceTaxiBus.GetBus().Subscribe(GameEventType.InputEvent, this); ActiveState = MainMenu.GetInstance(); stateTransformer = new StateTransformer(); }
public StateMachine() { SpaceTaxiBus.GetBus().Subscribe(GameEventType.GameStateEvent, this); SpaceTaxiBus.GetBus().Subscribe(GameEventType.InputEvent, this); SpaceTaxiBus.GetBus().Subscribe(GameEventType.TimedEvent, this); ActiveState = MainMenu.GetInstance(); }
public void TestEventGameRunning() { SpaceTaxiBus.GetBus().RegisterEvent(GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); SpaceTaxiBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <GameRunning>()); }
public void CustomerTimeOut() { ChoseLevel.GetInstance().filename = "short-n-sweet.txt"; GameRunning.instance = null; GameOver.instance = null; GameRunning.GetInstance(game, null); // GameRunning.instance.player.thrust = new Vec2F(-0.00001f, 0f); //sets a convenient start position for player GameRunning.instance.player.Entity.Shape.SetPosition(new Vec2F(0.3f , 0.25f)); GameRunning.instance.gravity = new Vec2F(0f, -0.0000003f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); SpaceTaxiBus.GetBus().ProcessEventsSequentially(); while (GameOver.instance == null) { game.gameTimer.MeasureTime(); while (game.gameTimer.ShouldUpdate()) { SpaceTaxiBus.GetBus().ProcessEvents(); game.win.PollEvents(); game.eventBus.ProcessEvents(); game.stateMachine.ActiveState.UpdateGameLogic(); } if (game.gameTimer.ShouldRender()) { game.win.Clear(); game.backGroundImage.RenderEntity(); game.stateMachine.ActiveState.RenderState(); game.win.SwapBuffers(); } if (game.gameTimer.ShouldReset()) { // 1 second has passed - display last captured ups and fps from the timer // win.Title = "Space Taxi | UPS: " + gameTimer.CapturedUpdates + ", FPS: " + // gameTimer.CapturedFrames; } } Assert.That(game.stateMachine.ActiveState, Is.InstanceOf <GameOver>()); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyValue) { case "KEY_PRESS": switch (keyAction) { case "KEY_UP": case "KEY_W": if (activePauseButton == 1) { activePauseButton = 0; } break; case "KEY_DOWN": case "KEY_S": if (activePauseButton == 0) { activePauseButton = 1; } break; case "KEY_ENTER": if (activePauseButton == 0) { SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); } else { GameRunning.GetInstance0(); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_MAINMENU", "")); } break; } break; case "KEY_RELEASE": break; } }
public Player() { orientation = TaxiOrientation.TaxiOrientedLeft; state = TaxiBoosterState.TaxiBoosterOff; SpaceTaxiBus.GetBus().Subscribe(GameEventType.PlayerEvent, this); Shape = new DynamicShape(new Vec2F(), new Vec2F(0.0625f, 0.045f)); PlayerIsMoving = true; }
public void TestEventChooseLevel() { SpaceTaxiBus.GetBus().RegisterEvent(GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "CHOSE_LEVEL", "")); SpaceTaxiBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <ChoseLevel>()); }
public void TestEventMainMenu() { SpaceTaxiBus.GetBus().RegisterEvent(GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); SpaceTaxiBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <MainMenu>()); }
public void InitializeGameState() { bottomPanel = new BottomPanel(); eventBus = SpaceTaxiBus.GetBus(); backGroundImage = new Entity( new StationaryShape(new Vec2F(0.0f, 0.0f + Constants.BOTTOM), new Vec2F(1.0f, 1.0f - Constants.BOTTOM)), new Image(Path.Combine("Assets", "Images", "SpaceBackground.png")) ); }
private int[] mA; //input key array. 0 = left, 1 = up, 2 = right public Player(DynamicShape shape, IBaseImage image) : base(shape, image) { mA = new int[3]; taxiOrientation = TaxiOrientation.Left; taxiDirection = TaxiDirection.None; imageContainer = ImageContainer.GetInstance(); Shape = new DynamicShape( new Vec2F(), new Vec2F(Constants.EXTENT_X * 2, Constants.EXTENT_Y)); Image = imageContainer.GetPlayerStride(taxiOrientation, taxiDirection); SpaceTaxiBus.GetBus().Subscribe(GameEventType.PlayerEvent, this); }
public void InitializeGameState() { eventBus = SpaceTaxiBus.GetBus(); imageContainer = ImageContainer.GetInstance(); backgroundImg = new Entity(new StationaryShape(0, 0, 1, 1), imageContainer.GetImageByName("SpaceBackground.png")); pausedText = new Text( "Game paused. \n\nPress P to continue \nPress ESC to quit", new Vec2F(0.23f, 0.1f), new Vec2F(0.6f, 0.6f)); pausedText.SetColor(Color.White); pausedText.SetFontSize(40); }
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, 1.0f, 1.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, 1.0f, 1.0f)); activeMenuButton++; menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f)); } break; case "KEY_ENTER": switch (activeMenuButton) { case 1: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "SELECT_LEVEL", "")); break; case 2: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", "")); break; default: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); break; } break; } } }
public void InitiateStateMachine() { SpaceTaxiBus.GetBus().InitializeEventBus(new List <GameEventType>() { GameEventType.InputEvent, GameEventType.WindowEvent, GameEventType.GameStateEvent, GameEventType.PlayerEvent }); Game game = new Game(); stateMachine = new StateMachine(game); }
public void InitializeGameState() { spaceTaxiBus = SpaceTaxiBus.GetBus(); imageContainer = ImageContainer.GetInstance(); backgroundImage = new Entity( new StationaryShape(0.0f, 0.0f, 1f, 1f), imageContainer.GetImageByName("SpaceBackground.png")); gameOverText = new Text("GAME OVER", new Vec2F(0.31f, 0.4f), new Vec2F(0.4f, 0.3f)); gameOverText.SetColor(Color.White); tryAgainButton = new Text("Press ENTER to try again", new Vec2F(0.25f, 0.0f), new Vec2F(0.7f, 0.5f)); tryAgainButton.SetColor(Color.White); tryAgainButton.SetFontSize(20); }
public void InitiateStateMachine() { DIKUArcade.Window.CreateOpenGLContext(); stateMachine = new StateMachine(); SpaceTaxiBus.GetBus().InitializeEventBus(new List <GameEventType>() { GameEventType.WindowEvent, GameEventType.InputEvent, GameEventType.GameStateEvent, GameEventType.PlayerEvent }); SpaceTaxiBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine); }
private void InitializeCustomers() { SpaceTaxiEventContainer.SetContainerSize(Customers.Count * 2 + 1); SpaceTaxiEventContainer.GetContainer().ResetContainer(); SpaceTaxiEventContainer.GetContainer().AttachEventBus(SpaceTaxiBus.GetBus()); var container = SpaceTaxiEventContainer.GetContainer(); foreach (Customer c in Customers) { container.AddTimedEvent(TimeSpanType.Seconds, c.SpawnTimer, "SPAWN_CUSTOMER", "", ""); container.AddTimedEvent(TimeSpanType.Seconds, c.DesapwnTimer, "DESPAWN_CUSTOMER", "", ""); } }
public void ActivateGameLevel() { if (Customer != null) { if (Customer.Destination == '^') { Console.WriteLine("Any Platform Please"); } else { Console.WriteLine(Platforms[Customer.Destination].PlatformNumber); } } SpaceTaxiBus.GetBus().Subscribe(GameEventType.PlayerEvent, Player); }
public void PointToWinGameTest(int pointsToWin) { SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); while (gameR.singletonScore.score != pointsToWin) { gameR.singletonScore.PointChanger("Add"); gameR.UpdateGameLogic(); gameR.RenderState(); } SpaceTaxiBus.GetBus().ProcessEventsSequentially(); Assert.That(stateMachine.ActiveState, Is.InstanceOf <GameWon>()); }
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, 1.0f, 1.0f)); activeMenuButton--; menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f)); } break; case "KEY_DOWN": if (activeMenuButton < maxMenuButtons) { menuButtons[activeMenuButton].SetColor(new Vec3F(1.0f, 1.0f, 1.0f)); activeMenuButton++; menuButtons[activeMenuButton].SetColor(new Vec3F(0.0f, 1.0f, 0.0f)); } break; case "KEY_ENTER": switch (activeMenuButton) { case 2: SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "MAIN_MENU", "")); break; default: LevelContainer.GetInstance().GetLevel(maxMenuButtons - activeMenuButton - 1); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); break; } break; } } }
/// <summary> /// Initialize level properties /// </summary> public void InitializeLevel() { spaceTaxibus = SpaceTaxiBus.GetBus(); spaceTaxibus.Subscribe(GameEventType.TimedEvent, this); levelManager = LevelManager.GetInstance(); //setting text sizes scoreText = new Text("", new Vec2F(0.43f, -0.26f), new Vec2F(Constants.EXTENT_X * 17, Constants.EXTENT_Y * 14)); customerDestination = new Text("", new Vec2F(0.37f, -0.30f), new Vec2F(Constants.EXTENT_X * 17, Constants.EXTENT_Y * 14)); scoreText.SetFontSize(23); scoreText.SetColor(new Vec3I(255, 255, 255)); customerDestination.SetFontSize(23); customerDestination.SetColor(new Vec3I(255, 255, 255)); background = new Entity( new StationaryShape(0.0f, 0.0f, 1f, 1f), ImageContainer.GetInstance().GetImageByName("SpaceBackground.png")); PlayerScore = 0; }
GameRunning() { eventBus = SpaceTaxiBus.GetBus(); levelManager = LevelManager.GetInstance(); }
public void DeactivateGameLevel() { SpaceTaxiBus.GetBus().Unsubscribe(GameEventType.PlayerEvent, Player); }
public void HandleKeyEvent(string keyValue, string keyAction) { switch (keyValue) { case "KEY_PRESS": switch (keyAction) { case "KEY_ESCAPE": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_PAUSED", "")); break; case "KEY_SPACE": GameRunning.GetInstance0(); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_MAINMENU", "")); break; case "KEY_Q": SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.WindowEvent, this, "SAVE_SCREENSHOT", "", "")); break; case "KEY_UP": case "KEY_W": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "BOOSTER_UPWARDS", "", "")); break; case "KEY_LEFT": case "KEY_A": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "BOOSTER_TO_LEFT", "", "")); break; case "KEY_RIGHT": case "KEY_D": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "BOOSTER_TO_RIGHT", "", "")); break; } break; case "KEY_RELEASE": switch (keyAction) { case "KEY_LEFT": case "KEY_A": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "STOP_ACCELERATE_LEFT", "", "")); break; case "KEY_RIGHT": case "KEY_D": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "STOP_ACCELERATE_RIGHT", "", "")); break; case "KEY_UP": case "KEY_W": player.ProcessEvent(GameEventType.PlayerEvent, GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.PlayerEvent, this, "STOP_ACCELERATE_UP", "", "")); break; } break; } }
public void CustomerDropOff() { GameRunning.instance = null; GameRunning.GetInstance(game, null); // GameRunning.instance.player.thrust.Y = 0f; //sets a convenient start position for player GameRunning.instance.player.Entity.Shape.SetPosition(new Vec2F(0.3f , 0.25f)); GameRunning.instance.gravity = new Vec2F(0f, -0.0000003f); SpaceTaxiBus.GetBus().RegisterEvent( GameEventFactory <object> .CreateGameEventForAllProcessors( GameEventType.GameStateEvent, this, "CHANGE_STATE", "GAME_RUNNING", "")); // game.GameLoop(); while (SingletonScore.Instance.score == 0) { if (GameRunning.instance != null) { if (GameRunning.instance.player.shape.Position.Y < 0.1) { GameRunning.instance.player.SetPosition(0.5f, 0.7f); GameRunning.instance.player.thrust.Y = 0.00001f; } } if (GameRunning.instance != null) { if (GameRunning.instance.currentLevel.levelName.Equals("the-beach.txt") && GameRunning.instance.player.shape.Position.Y < 0.8f) { GameRunning.instance.player.SetPosition(0.1f, 0.84f); GameRunning.instance.player.thrust.Y = 0.000001f; } } game.gameTimer.MeasureTime(); while (game.gameTimer.ShouldUpdate()) { SpaceTaxiBus.GetBus().ProcessEvents(); game.win.PollEvents(); game.eventBus.ProcessEvents(); game.stateMachine.ActiveState.UpdateGameLogic(); } if (game.gameTimer.ShouldRender()) { game.win.Clear(); game.backGroundImage.RenderEntity(); game.stateMachine.ActiveState.RenderState(); game.win.SwapBuffers(); } if (game.gameTimer.ShouldReset()) { // 1 second has passed - display last captured ups and fps from the timer // win.Title = "Space Taxi | UPS: " + gameTimer.CapturedUpdates + ", FPS: " + // gameTimer.CapturedFrames; } } Assert.AreEqual(100, SingletonScore.Instance.score); }