예제 #1
0
        public static void TickAliensFiring(AliensState aliensState, out AliensFiringInput newAliensFiringInput)
        {
            Random r = new Random();

            if (r.Next(10) == 0)
            {
                List <int> bottomRow = aliensState.GetBottomRow();
                newAliensFiringInput = new AliensFiringInput(true, bottomRow[r.Next(bottomRow.Count)]);
            }
            else
            {
                newAliensFiringInput = new AliensFiringInput(false, 0);
            }
        }
예제 #2
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));
        }
예제 #3
0
        public static void TickAliens(GameConfigState gameConfigState, AliensState aliensState, AliensMovementState aliensMovementState,
                                      out AliensState newAliensState, out AliensMovementState newAliensMovementState, out AliensFiringInput newAliensFiringInput)
        {
            Vector2i topLeft, bottomRight;

            aliensState.GetAbsoluteBoundingBox(out topLeft, out bottomRight);
            AliensMovementState.MovementDirection nextMovementDirection = ChooseNewAliensMovementDirection(gameConfigState, aliensMovementState, topLeft, bottomRight);

            Dictionary <AliensMovementState.MovementDirection, Vector2i> movementDirectionToDelta =
                new Dictionary <AliensMovementState.MovementDirection, Vector2i>
            {
                { AliensMovementState.MovementDirection.Left, new Vector2i(-1, 0) },
                { AliensMovementState.MovementDirection.Right, new Vector2i(1, 0) },
                { AliensMovementState.MovementDirection.Down, new Vector2i(0, 1) },
            };

            Vector2i movementDelta = movementDirectionToDelta[nextMovementDirection];

            newAliensState         = new AliensState(aliensState.TopLeft + movementDelta, aliensState.RelativePositions);
            newAliensMovementState = new AliensMovementState(nextMovementDirection);

            TickAliensFiring(aliensState, out newAliensFiringInput);
        }
예제 #4
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));
        }