Beispiel #1
0
        public override void Update(GameTime gameTime)
        {
            this.reflected = false;     //Only Reflect the Ball once per update
            foreach (Block b in Blocks)
            {
                if (b.Enabled)              //Only chack active blocks
                {
                    b.Update(gameTime);     //Update Block
                    //Ball Collision
                    if (b.Intersects(ball)) //Check for collision with current block
                    {
                        b.HitByBall(ball);
                        blocksToRemove.Add(b); //Can't remove blocks from the current Array as we are interating on that collection
                                               //Add the current block to another array to be removed after the look finishes
                        if (!reflected)        //Only reflect once but can break multiple blocks
                        {
                            ball.Reflect(b);
                            this.reflected = true;
                        }
                    }
                }
            }

            //remove disabled blocks
            foreach (var block in blocksToRemove)
            {
                Blocks.Remove(block);
            }
            blocksToRemove.Clear(); //empty broken blocks array

            base.Update(gameTime);
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (ball.Intersects(testBlock))
            {
                testBlock.HitByBall(ball);
                ball.Reflect(testBlock);
            }

            base.Update(gameTime);
        }