Example #1
0
        /// <summary>
        /// Updates the game world
        /// </summary>
        /// <param name="gameTime">The game time</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            slimeGhost.Update(gameTime);

            //detect and process collisions
            foreach (var coin in coins)
            {
                if (!coin.Collected && coin.Bounds.CollidesWith(slimeGhost.Bounds))
                {
                    coin.Collected   = true;
                    slimeGhost.Color = Color.Red;
                    coinsLeft--;
                    break;      //is this technically more efficient to cancel out the else? Won't always run through all of the coins to check?
                }
                else
                {
                    slimeGhost.Color = Color.White;
                }
            }

            base.Update(gameTime);
        }
Example #2
0
        /// <summary>
        /// Updates the game world
        /// </summary>
        /// <param name="gameTime">The game time</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            slimeGhost.Update(gameTime);

            // Detect and process collisions
            slimeGhost.Color = Color.White;
            foreach (var coin in coins)
            {
                if (!coin.Collected && coin.Bounds.CollidesWith(slimeGhost.Bounds))
                {
                    slimeGhost.Color = Color.Red;
                    coin.Collected   = true;
                    coinsLeft--;
                }
            }

            base.Update(gameTime);
        }