Пример #1
0
        /// <summary>
        /// Called 60 frames/per second and updates the positions
        /// of all the drawable objects
        /// </summary>
        /// <param name='gameTime'>
        /// Can work out the elapsed time since last call if
        /// you want to compensate for different frame rates
        /// </param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (state == GameStates.playing)
            {
                // Update Asteriod

                shipSprite.Update(gameTime);

                asteroidController.Update(gameTime);
                asteroidController.HasCollided(shipSprite);

                UpdateScore();
                UpdateHealth();

                coinsController.Update(gameTime);
                coinsController.HasCollided(shipSprite);


                base.Update(gameTime);
            }
        }
Пример #2
0
        /// <summary>
        /// This is an enemy Sprite with four animations for the four
        /// directions, up, down, left and right.  Has no intelligence!
        /// </summary>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (gameState == GameStates.Loading)
            {
                gameState = GameStates.Running;
            }

            if (gameState == GameStates.Running)
            {
                //maybe put a pause method in here

                restartButton.Update(gameTime);

                // Update Asteroids

                shipSprite.Update(gameTime);
                asteroidController.Update(gameTime);
                asteroidController.HasCollided(shipSprite);

                if (shipSprite.Score >= 100)
                {
                    gameState = GameStates.Won;
                }
                else if (shipSprite.Health <= 0)
                {
                    gameState = GameStates.Lost;
                }

                // Update Chase Game

                base.Update(gameTime);
            }
        }