Esempio n. 1
0
        public static RocketsState TickRockets(GameConfigState gameConfigState, RocketsState rocketsState, PlayerState playerState, PlayerInput playerInput)
        {
            List <Vector2i> newPositions = rocketsState.Positions.Select(position => position + new Vector2i(0, -1)).Where(position => position.Y >= 0).ToList();

            if (playerInput == PlayerInput.Fire && newPositions.Count < gameConfigState.MaxRockets)
            {
                newPositions.Add(new Vector2i(playerState.Position, gameConfigState.Height - 1));
            }
            return(new RocketsState(newPositions));
        }
Esempio n. 2
0
 private static RocketsState ResolveRocketCollisions(RocketsState rocketsState, List <Tuple <int, int> > alienRocketCollisions)
 {
     if (alienRocketCollisions.Count != 0)
     {
         List <Vector2i> remainingPositions = rocketsState.Positions.Where((position, index) => !alienRocketCollisions.Exists(collision => index == collision.Item2)).ToList();
         return(new RocketsState(remainingPositions));
     }
     else
     {
         return(rocketsState);
     }
 }
Esempio n. 3
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);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        private static List <Tuple <int, int> > FindAlienRocketCollisions(AliensState aliensState, RocketsState rocketsState)
        {
            List <Tuple <int, int> > collisions = new List <Tuple <int, int> >();

            for (int rocketIndex = 0; rocketIndex < rocketsState.Positions.Count; rocketIndex++)
            {
                Vector2i rocketPosition = rocketsState.Positions[rocketIndex];
                int      alienIndex     = aliensState.RelativePositions.FindIndex(alienRelativePosition => (alienRelativePosition + aliensState.TopLeft) == rocketPosition);
                if (alienIndex != -1)
                {
                    collisions.Add(new Tuple <int, int>(alienIndex, rocketIndex));
                }
            }

            return(collisions);
        }