示例#1
0
        public override void Update(GameTime gameTime)
        {
            Randomizer.Update(gameTime);
            switch (currentState)
            {
            case GameState.Starting:
                HandleStart(gameTime);
                break;

            case GameState.Active:
                HandleActive(gameTime);
                break;

            case GameState.Paused:
                HandlePause(gameTime);
                break;

            case GameState.LevelCompleted:
                HandleLevelComplete(gameTime);
                break;

            case GameState.GameOver:
                HandleGameOver(gameTime);
                break;

            case GameState.GameComplete:
                HandleGameComplete(gameTime);
                break;
            }
            GameObjectCollection.ProcessPending();
        }
示例#2
0
        private void SetScreenMessageFromState()
        {
            if (currentState != GameState.Active)
            {
                var message = GameObjectCollection.Collection.FirstOrDefault(x => x is InfoMessage infoMessage &&
                                                                             infoMessage.MessageId == stateMessageMap[currentState]);

                if (message != null)
                {
                    message.IsActive = true;
                }
            }
            else
            {
                GameObjectCollection.GetActive <InfoMessage>().ForEach(x => x.IsActive = false);
            }
        }
示例#3
0
        //Set up the objects
        public override void Initialize()
        {
            var ball = GameObjectInitializer.GetBall();

            ball.OnGameEnd += CurrentGame_OnGameEnd;

            var slider = GameObjectInitializer.GetSlider();
            var bricks = GameObjectInitializer.GetBricks();

            bricks.ForEach(x => x.OnGameEnd += CurrentGame_OnGameEnd);

            var messages = GameObjectInitializer.GetMessageCollection();

            var toAdd = new List <GameObject>()
            {
                ball, slider
            };

            toAdd.AddRange(bricks);
            toAdd.AddRange(messages);

            GameObjectCollection.Initialize(toAdd);
        }
示例#4
0
        private void HandleActive(GameTime gameTime)
        {
            if (CheckForPause())
            {
                return;
            }
            //process all the collisions first so we don't have to worry about the order things are processed in.
            //this can probably get changed to a better way now that all objects handle their own collision logic.
            GameObjectCollection.CheckCollisions(gameTime);
            GameObjectCollection.UpdateCollection(gameTime);

            //todo replace this magic number with a const. Does a limit of 50 even make sense?
            //run some tests to find out if the size of this collection could ever become a problem.
            if (GameObjectCollection.CountInactive <InteractiveGameObject>() > 50)
            {
                GameObjectCollection.DestroyInactive();
            }

            //If the user hasn't seen a  power up in a while, give them one for free.
            if (gameTime.TotalElapsedTime - timeSinceLastRandomPowerUp > waitTimeForRandomPowerUp)
            {
                if (GameObjectCollection.ActivePowerUps.Any())
                {
                    timeSinceLastRandomPowerUp = gameTime.TotalElapsedTime;
                }
                else
                {
                    var xMin  = CurrentSettings.WindowWidth / 4;
                    var xMax  = CurrentSettings.WindowWidth - CurrentSettings.WindowWidth / 4;
                    var y     = CurrentSettings.WindowHeight / 3;
                    var power = GameObjectInitializer.GetRandomPowerUp(Randomizer.RandomNumber(xMin, xMax), y);
                    GameObjectCollection.Inject(power);
                    timeSinceLastRandomPowerUp = gameTime.TotalElapsedTime;
                }
            }
        }
示例#5
0
 public override void Draw(GameTime gameTime)
 {
     GameObjectCollection.DrawCollection(gameTime);
 }