Exemplo n.º 1
0
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            player = new Player(3);
            LoadLevels();
            ball = new Ball(content);
            paddle = new Paddle(content);
            LoadNextLevel();
            hud = new Hud(content, currentLevel.Name, player.Lives, player.Score);

            base.LoadContent();
        }
Exemplo n.º 2
0
        public bool Move(_wall _wall, Paddle paddle)
        {
            if (!Visible)
            {
                return(false);
            }

            X = X + XVelocity;
            Y = Y + YVelocity;

            /*  Check for _wall hits */
            if (X < 1)
            {
                X          = 1;
                XVelocity *= -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (X > ScreenWidth - Width + 5)
            {
                X          = ScreenWidth - Width + 5;
                XVelocity *= -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (Y < 1)
            {
                Y          = 1;
                YVelocity *= -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (Y + Height > ScreenHeight)
            {
                Visible = false;
                Y       = 0;
                PlaySound(gameContent.MissSound);
                return(false);
            }

            /*  Check for paddle hits
             *  Paddle is 70 pixels. We'll divide it into segments that will determine the angle of the bounce. */
            Rectangle paddleRect = new Rectangle((int)paddle.X, (int)paddle.Y, (int)paddle.Width, (int)paddle.Height);
            Rectangle ballRect   = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);

            if (HitTest(paddleRect, ballRect))
            {
                PlaySound(gameContent.PaddleBounceSound);
                int offset = Convert.ToInt32((paddle.Width - (paddle.X + paddle.Width - X + Width / 2)));
                offset /= 5;
                if (offset < 0)
                {
                    offset = 0;
                }

                switch (offset)
                {
                case 0:
                    XVelocity = -6;
                    break;

                case 1:
                    XVelocity = -5;
                    break;

                case 2:
                    XVelocity = -4;
                    break;

                case 3:
                    XVelocity = -3;
                    break;

                case 4:
                    XVelocity = -2;
                    break;

                case 5:
                    XVelocity = -1;
                    break;

                case 6:
                    XVelocity = 1;
                    break;

                case 7:
                    XVelocity = 2;
                    break;

                case 8:
                    XVelocity = 3;
                    break;

                case 9:
                    XVelocity = 4;
                    break;

                case 10:
                    XVelocity = 5;
                    break;

                default:
                    XVelocity = 6;
                    break;
                }

                YVelocity *= -1;
                Y          = paddle.Y - Height + 1;
                return(true);
            }

            bool hitBrick = false;

            for (int i = 0; i < 7; i++)
            {
                if (!hitBrick)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Brick brick = _wall.BrickWall[i, j];
                        if (brick.Visible)
                        {
                            Rectangle brickRect = new Rectangle((int)brick.X, (int)brick.Y, (int)brick.Width, (int)brick.Height);
                            if (HitTest(ballRect, brickRect))
                            {
                                PlaySound(gameContent.BrickSound);
                                brick.Visible = false;
                                Score        += 7 - i;
                                YVelocity    *= -1;
                                bricksCleared++;
                                hitBrick = true;
                                break;
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool Move(Wall wall, Paddle paddle)
        {
            if (Visible == false)
            {
                return(false);
            }

            X = X + XVelocity;
            Y = Y + YVelocity;

            // Wall hits
            if (X < 1)
            {
                X         = 1;
                XVelocity = XVelocity * -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (X > ScreenWidth - Width + 5)
            {
                X         = ScreenWidth - Width + 5;
                XVelocity = XVelocity * -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (Y < 1)
            {
                Y         = 1;
                YVelocity = YVelocity * -1;
                PlaySound(gameContent.WallBounceSound);
            }
            if (Y + Height > ScreenHeight)
            {
                Visible = false;
                Y       = 0;
                PlaySound(gameContent.MissSound);
                return(false);
            }

            // Paddle hits
            Rectangle paddleRect = new Rectangle((int)paddle.X, (int)paddle.Y, (int)paddle.Width, (int)paddle.Height);
            Rectangle ballRect   = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);

            if (HitTest(paddleRect, ballRect))
            {
                PlaySound(gameContent.PaddleBounceSound);
                int offset = Convert.ToInt32((paddle.Width - (paddle.X + paddle.Width - X + Width / 2)));

                offset = offset / 5;
                if (offset < 0)
                {
                    offset = 0;
                }

                switch (offset)
                {
                case 0:
                    XVelocity = -6;
                    break;

                case 1:
                    XVelocity = -5;
                    break;

                case 2:
                    XVelocity = -4;
                    break;

                case 3:
                    XVelocity = -3;
                    break;

                case 4:
                    XVelocity = -2;
                    break;

                case 5:
                    XVelocity = -1;
                    break;

                case 6:
                    XVelocity = 1;
                    break;

                case 7:
                    XVelocity = 2;
                    break;

                case 8:
                    XVelocity = 3;
                    break;

                case 9:
                    XVelocity = 4;
                    break;

                case 10:
                    XVelocity = 5;
                    break;

                default:
                    XVelocity = 6;
                    break;
                }

                YVelocity = YVelocity * -1;
                Y         = paddle.Y - Height + 1;
                return(true);
            }

            bool hitBrick = false;

            for (int i = 0; i < 7; i++)
            {
                if (hitBrick == false)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Brick brick = wall.BrickWall[i, j];
                        if (brick.Visible)
                        {
                            Rectangle brickRect = new Rectangle((int)brick.X, (int)brick.Y, (int)brick.Width, (int)brick.Height);
                            if (HitTest(ballRect, brickRect))
                            {
                                PlaySound(gameContent.BrickSound);
                                brick.Visible = false;
                                Score         = Score + 7 - i;
                                YVelocity     = YVelocity * -1;
                                BricksCleared++;
                                hitBrick = true;
                                break;
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool Move(Wall wall, Paddle paddle)
        {
            if (Visible == false)
            {
                return(false);
            }

            X += XVelocity;
            Y += YVelocity;

            // check for wall hits
            if (X < 1)
            {
                X          = 1;
                XVelocity *= -1;
                PlaySound(gameContent.wallBounceSound);
            }
            if (X > ScreenWidth - Width + 5)
            {
                X          = ScreenWidth - Width + 5;
                XVelocity *= -1;
                PlaySound(gameContent.wallBounceSound);
            }
            if (Y < 1)
            {
                Y          = 1;
                YVelocity *= -1;
                PlaySound(gameContent.wallBounceSound);
            }
            if (Y + Height > ScreenHeight)
            {
                Visible = false;
                Y       = 0;
                PlaySound(gameContent.missSound);
                return(false);
            }

            // check for paddle hit
            // paddle is 70 pixels. we'll logically divide it into segments that
            // will determine the angle of the bounce

            Rectangle paddleRect = new Rectangle((int)paddle.Position.X,
                                                 (int)paddle.Position.Y, (int)paddle.Width, (int)paddle.Height);
            Rectangle ballRect = new Rectangle((int)X, (int)Y, (int)Width,
                                               (int)Height);

            if (HitTest(paddleRect, ballRect))
            {
                PlaySound(gameContent.paddleBounceSound);

                int offset = Convert.ToInt32(paddle.Width - (paddle.Position.X + paddle.Width - X + Width / 2)) / 5;

                if (offset < 0)
                {
                    offset = 0;
                }

                switch (offset)
                {
                case 0:
                    XVelocity = -6;
                    break;

                case 1:
                    XVelocity = -5;
                    break;

                case 2:
                    XVelocity = -4;
                    break;

                case 3:
                    XVelocity = -3;
                    break;

                case 4:
                    XVelocity = -2;
                    break;

                case 5:
                    XVelocity = -1;
                    break;

                case 6:
                    XVelocity = 1;
                    break;

                case 7:
                    XVelocity = 2;
                    break;

                case 8:
                    XVelocity = 3;
                    break;

                case 9:
                    XVelocity = 4;
                    break;

                case 10:
                    XVelocity = 5;
                    break;

                default:
                    XVelocity = 6;
                    break;
                }

                YVelocity *= -1;
                Y          = paddle.Position.Y - Height + 1;

                return(true);
            }

            bool hitBrick = false;

            for (int i = 0; i < 7; i++)
            {
                if (hitBrick == false)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Brick brick = wall.BrickWall[i, j];
                        if (brick.Visible)
                        {
                            Rectangle brickRect = new Rectangle(
                                (int)brick.Position.X,
                                (int)brick.Position.Y,
                                (int)brick.Width,
                                (int)brick.Height
                                );

                            if (HitTest(ballRect, brickRect))
                            {
                                PlaySound(gameContent.brickSound);
                                brick.Visible = false;
                                Score         = Score + 7 - i;
                                YVelocity    *= -1;
                                bricksCleared++;
                                hitBrick = true;
                                break;
                            }
                        }
                    }
                }
            }

            return(true);
        }