Example #1
0
        private void CheckCollisions()
        {
            if (Collisions.CheckBallScreenCollision(ball, ref delayTimer))
            {
                return;
            }

            // Collision?  Check rectangle intersection between ball and hand
            if (ball.Boundary.Intersects(paddle.Boundary))
            {
                Vector2 paddleColPoint = Collisions.CheckBallPaddleCollision(ball, paddle);
                if (paddleColPoint.X > -1 && ball.SpeedY > 0)
                {
                    //swishSound.Play();
                    Collisions.BallPaddleCollision(ball, paddle);
                    return;
                }
            }


            Vector2 brickColPoint;
            Brick   theBrick;

            Collisions.CheckBallBrickCollision(ball, brickRows, out brickColPoint, out theBrick);
            if (brickColPoint.X > -1)
            {
                //swishSound.Play();
                Collisions.BallBrickCollision(ball, brickColPoint, theBrick);
                return;
            }
        }
        public static void CheckBallBrickCollision(Ball ball, List <List <Brick> > brickRows, out Vector2 colPoint, out Brick colBrick)
        {
            Matrix ballMat = Matrix.CreateScale(ball.Scale) * Matrix.CreateTranslation(ball.X, ball.Y, 0);

            for (int j = (brickRows.Count - 1); j >= 0; j--)
            {
                for (int i = (brickRows[j].Count - 1); i >= 0; i--)
                {
                    Brick brick = brickRows[j][i];

                    if (!brick.IsBroken && ball.Boundary.Intersects(brick.Boundary))
                    {
                        Matrix brickMat = Matrix.CreateScale(brick.ScaleVector.X, brick.ScaleVector.Y, 0) * Matrix.CreateTranslation(brick.X, brick.Y, 0);

                        Vector2 ballBrickCollisionPoint = Collisions.TexturesCollide(brick.ColorArray, brickMat, ball.ColorArray, ballMat);

                        if (ballBrickCollisionPoint.X > -1)
                        {
                            brick.IsBroken = true;
                            brickRows[j].RemoveAt(i);
                            colPoint = ballBrickCollisionPoint;
                            colBrick = brick;
                            return;
                        }
                    }
                }
            }

            colPoint = new Vector2(-1, -1);
            colBrick = null;
        }
Example #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            switch (brickColor)
            {
            case BrickColor.RED:
                brickSprite = contentManager.Load <Texture2D>(@"Content\brick_red");
                break;

            case BrickColor.BLUE:
                brickSprite = contentManager.Load <Texture2D>(@"Content\brick_blue");
                break;

            case BrickColor.YELLOW:
                brickSprite = contentManager.Load <Texture2D>(@"Content\brick_yellow");
                break;

            case BrickColor.GREEN:
                brickSprite = contentManager.Load <Texture2D>(@"Content\brick_green");
                break;
            }

            brickColorArray = Collisions.TextureTo2DArray(brickSprite);

            widthScale  = ((float)Game1.graphics.PreferredBackBufferWidth / (float)numOfBricks) / (float)brickSprite.Width;
            scaleVector = new Vector2((widthScale * 0.8f), 0.2f);

            int yPos = (BRICK_GAP * (rowNumber + 1) + ((int)Height * rowNumber));

            Y = yPos;
        }
Example #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            paddleSprite = contentManager.Load <Texture2D>(@"Content\paddle_red");

            paddleColorArray = Collisions.TextureTo2DArray(paddleSprite);
        }
Example #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load the texture if it exists
            ballSprite = contentManager.Load <Texture2D>(@"Content\ball_black");

            ballColorArray = Collisions.TextureTo2DArray(ballSprite);
        }