예제 #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            brickTexture = Content.Load<Texture2D>("brick");

            player.LoadContent(Content);

            bricks = new Brick[10, 10];
            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    brickRect = new Rectangle(x * brickTexture.Width, y * brickTexture.Height, brickTexture.Width, brickTexture.Height);
                    bricks[x, y] = new Brick(new Vector2(x * brickTexture.Width, y * brickTexture.Height));
                }
            }
            foreach (Brick brick in bricks)
            {
                brick.LoadContent(Content);
            }
            ball.LoadContent(Content);
        }
예제 #2
0
파일: Ball.cs 프로젝트: Oriannanas/Breakout
        public bool BrickCollision(Brick brick)
        {
            int intersectResult = this.Rect.IntersectSub(brick.Rect, 10);

            while (intersectResult == 6)
            {
                this.Position -= this.velocity / 7.5f;
                intersectResult = this.Rect.IntersectSub(brick.Rect, 10);
                Console.WriteLine(Position);
            }
            if (intersectResult == 1 || intersectResult == 4)
            {
                this.velocity = new Vector2(this.velocity.X, -this.velocity.Y);
                return true;
            }
            else if (intersectResult == 2 || intersectResult == 3)
            {

                this.velocity = new Vector2(-this.velocity.X, this.velocity.Y);
                return true;
            }
            else if (intersectResult == 5)
            {
                //check if the ball is going straight towards the brick or sort of hits it while passing
                if ((brick.Position.X - this.Position.X < 0 && this.velocity.X < 0 && brick.Position.Y - this.Position.Y < 0 && this.velocity.Y < 0)
                   || (brick.Position.X - this.Position.X > 0 && this.velocity.X > 0 && brick.Position.Y - this.Position.Y < 0 && this.velocity.Y < 0)
                   || (brick.Position.X - this.Position.X < 0 && this.velocity.X < 0 && brick.Position.Y - this.Position.Y > 0 && this.velocity.Y > 0)
                   || (brick.Position.X - this.Position.X > 0 && this.velocity.X > 0 && brick.Position.Y - this.Position.Y > 0 && this.velocity.Y > 0)
                   )
                {
                    this.velocity = new Vector2(-this.velocity.X, -this.velocity.Y);
                    return true;

                }
            }
            return false;
        }
예제 #3
0
 private void SpawnBricks()
 {
     int distanceBetweenBricks = 3;
     int maxBricksX = (int)Math.Floor((double)(viewportWidth - 20) / (Config.brickWidth + distanceBetweenBricks));
     int maxBricksY = (int)Math.Floor((double)(viewportHeight - 250) / (Config.brickHeight + distanceBetweenBricks));
     for (int i = 0; i < maxBricksX; i++)
     {
         for (int j = 0; j < maxBricksY; j++)
         {
             int x = (int)(viewportWidth - (maxBricksX * (Config.brickWidth + distanceBetweenBricks))) / 2 + (int)(Config.brickWidth + distanceBetweenBricks) * i;
             int y = 10 + (int)(Config.brickHeight + distanceBetweenBricks) * j;
             int generated = rng.Next(1, 4);
             Brick brick =  new Brick(x, y, game.dotTexture, Color.Transparent);
             brickList.Add(brick);
             brick.Init(50 * (generated * 2), generated, new Color((float)rng.NextDouble(), (float)rng.NextDouble(), (float)rng.NextDouble()));
             bricksEnabled += 1;
         }
     }
 }
예제 #4
0
        private void BreakBrick(Brick brick)
        {
            if (brick.Integrity <= 1)
            {
                particleManagerList.Add(new ParticleManager(this, brick.Rect, 50, game.dotTexture, brick.Color));
                brick.isEnabled = false;

                if (!buffTimers.ContainsKey("score"))
                {
                    this.score += brick.Score;
                }
                else
                {
                    this.score += brick.Score * 2;
                }
                //random drop?
                if (rng.NextDouble() <= 0.08f)
                {
                    int generated = (int)(rng.NextDouble()*Enum.GetValues(typeof(PowerUpType)).Length);
                    powerUpList.Add(new PowerUp((PowerUpType)generated, (int)brick.Position.X, (int)brick.Rect.Y, game.dotTexture, Color.Yellow));
                }
                //decrease brick count and check brickcount to see if level is finished
                bricksEnabled -= 1;
            }
            else
            {
                brick.Integrity -= 1;
            }
        }