Exemplo n.º 1
0
        public static WorldState CreateNewWorldState(int width, int height, int maxRockets, int aliensWidth, int aliensHeight, int initialLives)
        {
            GameConfigState     gameConfigState     = new GameConfigState(width, height, maxRockets, aliensWidth, aliensHeight);
            PlayerState         playerState         = new PlayerState(width / 2);
            AliensState         aliensState         = CreateNewAliensState(width, height, aliensWidth, aliensHeight);
            AliensMovementState aliensMovementState = new AliensMovementState(AliensMovementState.MovementDirection.Right);
            RocketsState        rocketsState        = new RocketsState(new List <Vector2i>());
            BombsState          bombsState          = new BombsState(new List <Vector2i>());
            GameProgressState   gameProgressState   = new GameProgressState(0, initialLives, false);
            WorldState          worldState          = new WorldState(gameConfigState, playerState, aliensState, aliensMovementState, rocketsState, bombsState, gameProgressState);

            return(worldState);
        }
Exemplo n.º 2
0
        public WorldState(GameConfigState gameConfigState, PlayerState playerState, AliensState aliensState, AliensMovementState aliensMovementState,
                          RocketsState rocketsState, BombsState bombsState, GameProgressState gameProgressState)
        {
            GameConfigState = gameConfigState;
            PlayerState     = playerState;
            AliensState     = aliensState;

            AliensMovementState = aliensMovementState;

            RocketsState = rocketsState;

            BombsState = bombsState;

            GameProgressState = gameProgressState;
        }
Exemplo n.º 3
0
        public static WorldState Tick(WorldState worldState, PlayerInput playerInput)
        {
            PlayerState newPlayerState = TickPlayer(worldState.GameConfigState, worldState.PlayerState, playerInput);

            AliensState         newAliensState;
            AliensMovementState newAliensMovementState;
            AliensFiringInput   newAliensFiringInput;

            bool createNewAliens = (worldState.AliensState.RelativePositions.Count == 0);

            if (createNewAliens)
            {
                newAliensState = CreateNewAliensState(worldState.GameConfigState.Width, worldState.GameConfigState.Height,
                                                      worldState.GameConfigState.AliensWidth, worldState.GameConfigState.AliensHeight);
                newAliensMovementState = new AliensMovementState(AliensMovementState.MovementDirection.Right);
                newAliensFiringInput   = new AliensFiringInput(false, 0);
            }
            else
            {
                TickAliens(worldState.GameConfigState, worldState.AliensState, worldState.AliensMovementState, out newAliensState, out newAliensMovementState, out newAliensFiringInput);
            }

            RocketsState newRocketsState = TickRockets(worldState.GameConfigState, worldState.RocketsState, worldState.PlayerState, playerInput);

            BombsState newBombsState = TickBombs(worldState.GameConfigState, worldState.BombsState, worldState.PlayerState, worldState.AliensState, newAliensFiringInput);

            List <Tuple <int, int> > alienRocketCollisions = FindAlienRocketCollisions(newAliensState, newRocketsState);
            List <int> playerBombCollisions = FindPlayerBombCollisions(worldState.GameConfigState, newBombsState, newPlayerState);

            AliensState  newAliensState2  = ResolveAlienCollisions(newAliensState, alienRocketCollisions);
            RocketsState newRocketsState2 = ResolveRocketCollisions(newRocketsState, alienRocketCollisions);

            GameProgressState newGameProgressState = TickGameProgress(worldState.GameConfigState, worldState.GameProgressState, newAliensState2, alienRocketCollisions.Count, playerBombCollisions.Count != 0);

            return(new WorldState(worldState.GameConfigState, newPlayerState, newAliensState2, newAliensMovementState, newRocketsState2, newBombsState, newGameProgressState));
        }
Exemplo n.º 4
0
        public static GameProgressState TickGameProgress(GameConfigState gameConfigState, GameProgressState gameProgressState, AliensState aliensState, int aliensKilled, bool playerCollidedWithBomb)
        {
            Vector2i topLeft, bottomRight;

            aliensState.GetAbsoluteBoundingBox(out topLeft, out bottomRight);

            int  newScore    = gameProgressState.Score + aliensKilled;
            int  newLives    = Math.Max(gameProgressState.Lives - (playerCollidedWithBomb ? 1 : 0), 0);
            bool newGameOver = gameProgressState.GameOver || (newLives == 0 || (bottomRight.Y >= gameConfigState.Height));

            return(new GameProgressState(newScore, newLives, newGameOver));
        }