示例#1
0
        private void CheckBoardBonusCollisions(Bonus bonus)
        {
            if (bonus.CollisionRectangle.Intersects(stopBoard.CollisionRectangle))
            {
                bonus.IsActive = false;
                BricksOutGame.PlaySound(bonusSound);

                if (bonus.Type == BonusType.FireBall)
                {
                    flamingBalls            = true;
                    elapsedFlamingBallsTime = 0;

                    foreach (Ball ball in balls)
                    {
                        ball.IsFlaming = true;
                    }
                }
                else if (bonus.Type == BonusType.ExtraLife)
                {
                    lives++;
                }
                else
                {
                    CreateExtraBalls();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Hits the brick by the ball.
        /// </summary>
        /// <param name="flamingBall">Whether the ball was flaming.</param>
        /// <param name="detonated">Whether this brick was hitted by the detonation.</param>
        /// <param name="delay">The time delay before the brick has to be destroyed.</param>
        public void Hit(bool flamingBall, bool detonated, int delay)
        {
            if (flamingBall)
            {
                MarkAsDestroyed(delay);
                destructionSound = GameScreen.fireExplosionSound;
            }
            else if (detonated)
            {
                MarkAsDestroyed(delay);
            }
            else if (!destroyable)
            {
                if (hitSound != null)
                {
                    BricksOutGame.PlaySound(hitSound);
                }
            }
            else
            {
                hits++;

                if (hits == maxHits)
                {
                    MarkAsDestroyed(delay);
                }
                else if (hitSound != null)
                {
                    BricksOutGame.PlaySound(hitSound);
                }
            }
        }
示例#3
0
 private void DestroyBrick()
 {
     if (destructionSound != null)
     {
         BricksOutGame.PlaySound(destructionSound);
     }
     isActive = false;
 }
示例#4
0
 private void CheckBallBoardCollision(Ball ball)
 {
     if (ball.CollisionRectangle.Intersects(stopBoard.CollisionRectangle))
     {
         if (Vector2.Distance(new Vector2(ball.CollisionRectangle.Center.X, ball.CollisionRectangle.Center.Y),
                              new Vector2(stopBoard.DrawRectangle.Center.X, stopBoard.DrawRectangle.Center.Y)) <=
             ball.CollisionRectangle.Width / 2 + stopBoard.DrawRectangle.Width / 2)
         {
             if (ball.CollisionRectangle.Bottom <= stopBoard.CollisionRectangle.Bottom &&
                 ball.CollisionRectangle.Right >= stopBoard.CollisionRectangle.Left &&
                 ball.CollisionRectangle.Left <= stopBoard.CollisionRectangle.Right)
             {
                 stopBoard.IsBouncing = true;
                 BricksOutGame.PlaySound(boardHitSound);
                 GetNewBallVelocity(ball);
             }
         }
     }
 }
示例#5
0
 private void BounceBorders()
 {
     if (CollisionRectangle.Y < GameScreen.TopBorderWidth)
     {
         drawRectangle.Y = GameScreen.TopBorderWidth - (drawRectangle.Height - CollisionRectangle.Height) / 2;
         ballVelocity.Y *= -1;
         BricksOutGame.PlaySound(hitSound);
     }
     else if (CollisionRectangle.X < GameScreen.LeftBorderWidth)
     {
         drawRectangle.X = GameScreen.LeftBorderWidth - (drawRectangle.Width - CollisionRectangle.Width) / 2;
         ballVelocity.X *= -1;
         BricksOutGame.PlaySound(hitSound);
     }
     else if (CollisionRectangle.Right > BricksOutGame.WindowWidth - GameScreen.InfoFieldWidth)
     {
         drawRectangle.X = BricksOutGame.WindowWidth - GameScreen.InfoFieldWidth - drawRectangle.Width +
                           (drawRectangle.Width - CollisionRectangle.Width) / 2;
         ballVelocity.X *= -1;
         BricksOutGame.PlaySound(hitSound);
     }
 }
示例#6
0
        /// <summary>
        /// Updates the menu button.
        /// </summary>
        /// <param name="mouse">The mose state.</param>
        public void Update(MouseState mouse)
        {
            if (drawRectangle.Contains(mouse.X, mouse.Y))
            {
                if (!isSelected)
                {
                    isSelected = true;
                    BricksOutGame.PlaySound(soundEffect);
                }

                // highlight button
                sourceRectangle.X = buttonWidth + 1;

                // check for click started on the button
                if (mouse.LeftButton == ButtonState.Pressed &&
                    buttonReleased)
                {
                    clickStarted   = true;
                    buttonReleased = false;
                }
                else if (mouse.LeftButton == ButtonState.Released)
                {
                    buttonReleased = true;

                    // if click finished on button, button was pressed
                    if (clickStarted)
                    {
                        clickStarted = false;
                        isPressed    = true;
                    }
                }
            }
            else
            {
                sourceRectangle.X = 0;
                isSelected        = false;
            }
        }
示例#7
0
 static void Main()
 {
     using (var game = new BricksOutGame())
         game.Run();
 }