Exemple #1
0
        public void Deflect(Brick brick)
        {
            if (!collided)
            {
                motion.Y *= -1;

                /*
                 * TODO: cleverer collision detection here (intersecting line segments
                 * of the ball's movement between frames and each edge of the brick's
                 * bounding box)
                 */

                collided = true;
            }
        }
Exemple #2
0
        private void StartGame()
        {
            paddle.SetInStartPosition();
            ball.SetInStartPosition(paddle.GetBounds());

            // set up bricks
            bricks = new Brick[bricksWide, bricksHigh];

            for (int y = 0; y < bricksHigh; y++)
            {
                Color tint = Color.White;

                switch (y % bricksHigh)
                {
                    case 0:
                        tint = Color.Blue;
                        break;
                    case 1:
                        tint = Color.Red;
                        break;
                    case 2:
                        tint = Color.Green;
                        break;
                    case 3:
                        tint = Color.Yellow;
                        break;
                    case 4:
                        tint = Color.Purple;
                        break;
                }

                for (int x = 0; x < bricksWide; x++)
                {
                    Rectangle location = new Rectangle(x * brickTexture.Width, y * brickTexture.Height,
                        brickTexture.Width, brickTexture.Height);

                    bricks[x, y] = new Brick(brickTexture, location, tint);
                }
            }
        }