Ejemplo n.º 1
0
        public void Draw(Graphics g)
        {
            Pen pen = new Pen(Color.DarkGray, 3);

            g.DrawRectangle(pen, Border);
            foreach (Brick brick in BrickListTemp)
            {
                brick.Draw(g);
            }
            BallI.Draw(g);
            BouncerI.Draw(g);
            if (isDead)
            {
                if (PlayerLives > 0)
                {
                    System.Threading.Thread.Sleep(420);
                }
                else
                {
                    ShowEndMessage();
                }

                isDead = false;
            }
            pen.Dispose();
        }
Ejemplo n.º 2
0
 public void ResetLevel()
 {
     BrickListTemp = new List <Brick>(BrickList);
     PlayerLives   = 3;
     CurrentScore  = 0;
     BallI.ResetProperties(new Point(FULLSCREEN_SIZE.Width / 2, FULLSCREEN_SIZE.Height - 400));
     BouncerI.ResetProperties(new Point(BOUNCER_POSITION, FULLSCREEN_SIZE.Height - 60));
 }
Ejemplo n.º 3
0
        public void MoveBall(Graphics g)
        {
            List <Brick> BricksLeft = new List <Brick>(BrickListTemp);

            if (BouncerI.HitBox.IntersectsWith(BallI.HitBox))
            {
                float modifier = BouncerI.Position.X + BouncerI.Width / 2 - BallI.Position.X;
                BallI.velocityY = -BallI.velocityY;
                BallI.velocityX = BallI.velocityX - modifier / BouncerI.Width;
            }
            if (BrickListTemp.Count > 0)
            {
                foreach (Brick b in BrickListTemp)
                {
                    if (BallI.HitBox.IntersectsWith(b.HitBox))
                    {
                        if (BallI.HitBox.Top <= b.HitBox.Bottom)
                        {
                            BallI.velocityY = -BallI.velocityY;
                            BallI.Position  = new Point(BallI.Position.X, BallI.Position.Y + 5);
                            if (Math.Abs(BallI.velocityY) < 0.5)
                            {
                                BallI.ChangeBallVelocity('Y');
                            }
                        }
                        if (BallI.HitBox.Bottom <= b.HitBox.Top)
                        {
                            BallI.velocityY = -BallI.velocityY;
                            BallI.Position  = new Point(BallI.Position.X, BallI.Position.Y - 5);
                            if (Math.Abs(BallI.velocityY) < 0.5)
                            {
                                BallI.ChangeBallVelocity('Y');
                            }
                        }
                        if (BallI.HitBox.Left >= b.HitBox.Right)
                        {
                            BallI.velocityX = -BallI.velocityX;
                            BallI.Position  = new Point(BallI.Position.X + 2, BallI.Position.Y);
                            if (Math.Abs(BallI.velocityX) < 0.5)
                            {
                                BallI.ChangeBallVelocity('X');
                            }
                        }
                        if (BallI.HitBox.Right <= b.HitBox.Left)
                        {
                            BallI.velocityX = -BallI.velocityX;

                            BallI.Position = new Point(BallI.Position.X - 2, BallI.Position.Y);
                            if (Math.Abs(BallI.velocityX) < 0.5)
                            {
                                BallI.ChangeBallVelocity('X');
                            }
                        }
                        if (b.Lives <= 1)
                        {
                            BricksLeft.Remove(b);
                            CurrentScore += 1000;
                        }
                        b.Lives -= 1;
                        b.SetColorBasedOnLives();
                        break;
                    }
                }
            }
            int Padding = 3;

            if (BallI.HitBox.Top < Border.Top)
            {
                BallI.velocityY = -BallI.velocityY;
                BallI.Position  = new Point(BallI.Position.X, BallI.Position.Y + Padding);
            }
            else if (BallI.HitBox.Bottom > Border.Bottom)
            {
                BallI.ResetProperties(new Point(FULLSCREEN_SIZE.Width / 2, FULLSCREEN_SIZE.Height - 400));
                BouncerI.ResetProperties(new Point(BOUNCER_POSITION, FULLSCREEN_SIZE.Height - 60));
                isDead       = true;
                PlayerLives -= 1;
            }
            else if (BallI.HitBox.Left < Border.Left)
            {
                BallI.velocityX = -BallI.velocityX;
                BallI.Position  = new Point(BallI.Position.X + Padding, BallI.Position.Y);
            }
            else if (BallI.HitBox.Right > Border.Right)
            {
                BallI.velocityX = -BallI.velocityX;
                BallI.Position  = new Point(BallI.Position.X - Padding, BallI.Position.Y);
            }
            if (BallI.Position.X == 22)
            {
                BallI.velocityX = 0.55F;
            }
            BrickListTemp = BricksLeft;
            BallI.Move();
        }