Esempio n. 1
0
        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>());
        }
Esempio n. 2
0
        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")));
        }
Esempio n. 3
0
 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();
 }
Esempio n. 4
0
        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>());
 }
Esempio n. 6
0
        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>());
        }
Esempio n. 7
0
        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;
            }
        }
Esempio n. 8
0
        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>());
        }
Esempio n. 10
0
        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>());
        }
Esempio n. 11
0
        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"))
                );
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 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);
 }
Esempio n. 14
0
        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;
                }
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
 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);
 }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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", "", "");
            }
        }
Esempio n. 19
0
        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>());
 }
Esempio n. 21
0
        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;
                }
            }
        }
Esempio n. 22
0
        /// <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;
        }
Esempio n. 23
0
 GameRunning()
 {
     eventBus     = SpaceTaxiBus.GetBus();
     levelManager = LevelManager.GetInstance();
 }
Esempio n. 24
0
 public void DeactivateGameLevel()
 {
     SpaceTaxiBus.GetBus().Unsubscribe(GameEventType.PlayerEvent, Player);
 }
Esempio n. 25
0
        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;
            }
        }
Esempio n. 26
0
        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);
        }