Exemplo n.º 1
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));
        }
Exemplo n.º 2
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);
        }