Ejemplo n.º 1
0
        public static BombsState TickBombs(GameConfigState gameConfigState, BombsState bombsState, PlayerState playerState, AliensState aliensState, AliensFiringInput aliensFiringInput)
        {
            List <Vector2i> newPositions = bombsState.Positions.Select(position => position + new Vector2i(0, 1)).Where(position => position.Y < gameConfigState.Height).ToList();

            if (aliensFiringInput.Fire)
            {
                newPositions.Add(aliensState.TopLeft + aliensState.RelativePositions[aliensFiringInput.AlienIndex]);
            }
            return(new BombsState(newPositions));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        private static List <int> FindPlayerBombCollisions(GameConfigState gameConfigState, BombsState bombsState, PlayerState playerState)
        {
            Vector2i playerPosition = new Vector2i(playerState.Position, gameConfigState.Height - 1);

            List <int> collisions = bombsState.Positions.Select((position, index) => new Tuple <Vector2i, int>(position, index))
                                    .Where(positionAndIndex => playerPosition == positionAndIndex.Item1)
                                    .Select(positionAndIndex => positionAndIndex.Item2)
                                    .ToList();

            return(collisions);
        }