/// <summary>
 /// Handles GameStateEvents in this class.
 /// </summary>
 public StateMachine()
 {
     SpaceBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);
     SpaceBus.GetBus().Subscribe(GameEventType.PlayerEvent, this);
     // Sets state to MainMenu to start off with.
     ActiveState = MainMenu.GetInstance();
 }
Exemple #2
0
        /// <summary>
        /// Handles the key events. For key up, key down and enter.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
            }

            switch (keyValue)
            {
            case "KEY_UP":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_UPWARDS", "", ""));
                break;

            case "KEY_LEFT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_LEFT", "", ""));
                break;

            case "KEY_RIGHT":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.PlayerEvent, this, "BOOSTER_TO_RIGHT", "", ""));
                break;

            case "KEY_ESCAPE":
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.GameStateEvent, this, "GAME_PAUSED", "", ""));
                break;
            }

            if (keyAction == "KEY_RELEASE")
            {
                switch (keyValue)
                {
                case "KEY_LEFT":
                    SpaceBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.PlayerEvent, this, "STOP_ACCELERATE_LEFT", "", ""));
                    break;

                case "KEY_RIGHT":
                    SpaceBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.PlayerEvent, this, "STOP_ACCELERATE_RIGHT", "", ""));
                    break;

                case "KEY_UP":
                    SpaceBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.PlayerEvent, this, "STOP_ACCELERATE_UP", "", ""));
                    break;

                default:
                    break;
                }
            }
        }
        private void Collision()
        {
            foreach (Entity entity in paintBoard.Images)
            {
                switch (CollisionDetection.Aabb(
                            (DynamicShape)player.Entity.Shape, entity.Shape).Collision)
                {
                case true:
                    AddExplosion(player.Entity.Shape.Position,
                                 player.Entity.Shape.Extent);
                    player.Entity.DeleteEntity();
                    break;
                }

                var newPlayerList = new List <Player>();
                foreach (var player in playerList)
                {
                    if (!player.Entity.IsDeleted())
                    {
                        newPlayerList.Add(player);
                    }
                    if (player.Entity.IsDeleted())
                    {
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors
                                (GameEventType.GameStateEvent, this,
                                "CHANGE_STATE", "GAME_OVER", ""));
                    }
                }

                playerList = newPlayerList;
            }
        }
Exemple #4
0
        public StateMachine()
        {
            SpaceBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);
            SpaceBus.GetBus().Subscribe(GameEventType.InputEvent, this);

            ActiveState = MainMenu.GetInstance();
        }
Exemple #5
0
        /// <summary>
        /// Method that updates all logic features, which could be gravity.
        /// </summary>
        public void UpdateGameLogic()
        {
            if (player.GetsShape().Position.Y >= 0.98f && GameRunning.levelCounter == levelInfo.Count - 1)
            {
                AddCash();
                SpaceBus.GetBus().RegisterEvent(
                    GameEventFactory <object> .CreateGameEventForAllProcessors(
                        GameEventType.GameStateEvent, this, "GAME_VICTORY", "", ""));
            }

            CheckGameOver(GameRunning.levelCounter);
            RenderState();
            player.Physics();
            AddCash();

            foreach (Passenger passenger in levelPassengers[GameRunning.levelCounter])
            {
                passenger.PassengerMove();
            }

            levelCollisionCheckers[GameRunning.levelCounter].CheckCollsion();
            timerHandlers[GameRunning.levelCounter].SpawnPassengerTimer();
            timerHandlers[GameRunning.levelCounter].SetPickUpTimer();
            CheckGameOver(GameRunning.levelCounter);

            if (player.GetsShape().Position.Y >= 1.0f)
            {
                GameRunning.levelCounter++;
                player.SetPosition(playerXcoordinates[GameRunning.levelCounter], playerYcoordinates[GameRunning.levelCounter]);
            }
        }
        /// <summary>
        /// Handles the key events. For key up, key down and enter.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_UP":
                    if (activeMenuButton == 0)
                    {
                        activeMenuButton = maxMenuButtons - 1;
                    }
                    else
                    {
                        activeMenuButton -= 1;
                    }

                    break;

                case "KEY_DOWN":
                    if (activeMenuButton == maxMenuButtons - 1)
                    {
                        activeMenuButton = 0;
                    }
                    else
                    {
                        activeMenuButton += 1;
                    }

                    break;

                case "KEY_ENTER":
                    switch (activeMenuButton)
                    {
                    case 0:
                        GameRunning.ResetGameRunning();
                        GameLevels.Levelcount = 0;
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_RUNNING", "", ""));
                        break;

                    case 1:
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "MAIN_MENU", "", ""));

                        break;

                    default:
                        break;
                    }

                    break;

                default:
                    break;
                }
            }
        }
        /// <summary>
        /// Handles the key events. Such as the key enter, sets the player back to main menu.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_UP":
                    if (activeMenuButton == 0)
                    {
                        activeMenuButton = maxMenuButtons - 1;
                    }
                    else
                    {
                        activeMenuButton -= 1;
                    }

                    break;

                case "KEY_DOWN":
                    if (activeMenuButton == maxMenuButtons - 1)
                    {
                        activeMenuButton = 0;
                    }
                    else
                    {
                        activeMenuButton += 1;
                    }

                    break;

                case "KEY_ENTER":
                    switch (activeMenuButton)
                    {
                    case 0:
                        GameRunning.ResetGameRunning();
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_LEVELS", "", ""));
                        break;

                    case 1:
                        GameRunning.ResetGameRunning();
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_CONTROLS", "", ""));
                        break;

                    case 2:
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", ""));
                        break;
                    }

                    break;
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// This method takes two arguments and render the map by using the methods from the level class.
 /// </summary>
 /// <param name="levelNum"> Number of the level in the level container </param>
 private void CheckGameOver(int levelNum)
 {
     if (levelCollisionCheckers[levelNum].GetGameOverChecker())
     {
         ObstacleCollision.CreateExplosion(player);
         SpaceBus.GetBus().RegisterEvent(
             GameEventFactory <object> .CreateGameEventForAllProcessors(
                 GameEventType.GameStateEvent, this, "GAME_OVER", "", ""));
     }
 }
Exemple #9
0
        private GameRunning()
        {
            player = new Player();
            player.SetExtent(0.05f, 0.05f);

            GameRunning.levelCounter = GameLevels.Levelcount;

            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)),
                new Image(Path.Combine("Assets", "Images", "GameSpaceBaground.png")));

            GameRunning.cash      = 0;
            GameRunning.cashLabel = new Text($"Cash: {GameRunning.cash}", new Vec2F(0.8f, 0.004f), new Vec2F(0.2f, 0.2f));
            GameRunning.cashLabel.SetColor(Color.DarkRed);
            PassengerCollision.SetPassengerPickupsToNew();
            SpaceBus.GetBus().Subscribe(GameEventType.PlayerEvent, player);

            levelCollisionCheckers = new List <CollisionChecker>();
            timerHandlers          = new List <TimeHandler>();
            levels                 = Game.GetLevels();
            levelobstacles         = Game.GetLevelObstacles();
            levelplatforms         = Game.GetLevelPlatforms();
            levelPassengers        = new List <List <Passenger> >();
            levelDiffrentPlatforms = Game.GetLevelDiffrentPlatforms();

            playerXcoordinates = Game.GetPlayerXCoordinates();
            playerYcoordinates = Game.GetPlayerYCoordinates();

            levelInfo = Game.GetLevelInfo();

            passengerListInfo = new List <Dictionary <int, string> >();

            for (int i = 0; i < filePath.Length; i++)
            {
                levelPassengers.Add(new List <Passenger>());
            }

            for (int cp = 0; cp < filePath.Length; cp++)
            {
                CreatePassenger(cp);
            }

            for (int clc = 0; clc < levels.Count; clc++)
            {
                CreateLevelCollision(clc);
            }

            for (int cth = 0; cth < levels.Count; cth++)
            {
                CreateTimerHandlers(cth);
            }

            player.SetPosition(playerXcoordinates[GameRunning.levelCounter], playerYcoordinates[GameRunning.levelCounter]);
        }
Exemple #10
0
 public void HandleKeyEvent(string keyValue, string keyAction)
 {
     switch (keyValue)
     {
     case "KEY_P":
         SpaceBus.GetBus().RegisterEvent(
             GameEventFactory <object> .CreateGameEventForAllProcessors
                 (GameEventType.GameStateEvent, this,
                 "CHANGE_STATE", "GAME_PAUSED", ""));
         break;
     }
 }
Exemple #11
0
        /// <summary>
        /// Handles the key events. Such as the key enter, sets the player back to main menu.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_ENTER":
                    SpaceBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.GameStateEvent, this, "MAIN_MENU", "", ""));
                    break;

                default:
                    break;
                }
            }
        }
Exemple #12
0
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            switch (keyValue)
            {
            case "KEY_UP":
                if (keyAction == "KEY_PRESS")
                {
                    activeMenuButton   = 0;
                    inactiveMenuButton = 1;
                }

                break;

            case "KEY_DOWN":
                if (keyAction == "KEY_PRESS")
                {
                    activeMenuButton   = 1;
                    inactiveMenuButton = 0;
                }
                break;

            case "KEY_ENTER":
                switch (activeMenuButton)
                {
                case 0:
                    SpaceBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors
                            (GameEventType.GameStateEvent, this,
                            "CHANGE_STATE", "MAIN_MENU", ""));
                    break;

                case 1:
                    if (keyAction == "KEY_PRESS")
                    {
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.WindowEvent, this, "CLOSE_WINDOW",
                                "", ""));
                    }
                    break;
                }
                break;
            }
        }