Exemplo n.º 1
0
 public bool collision(GameSprite target)
 {
     if (target == null) return false;
     Rectangle sourceRectangle = new Rectangle(
         (int)(position.X - origin.X), (int)(position.Y - origin.Y),
         image.Width / animationframes, image.Height / animationframes);
     Rectangle targetRectangle = new Rectangle(
         (int)(target.position.X - target.origin.X), (int)(target.position.Y - target.origin.Y),
         target.image.Width / target.animationframes, target.image.Height / target.animationframes);
     return (sourceRectangle.Intersects(targetRectangle));
 }
Exemplo n.º 2
0
 //Reset the bricks upon all being removed.
 private void ResetBricks()
 {
     for (int brickNumber = 0; brickNumber < 10; brickNumber += 1)
     {
         bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 + 60, 100));
     }
     for (int brickNumber = 10; brickNumber < 20; brickNumber += 1)
     {
         bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 940, 150));
     }
     for (int brickNumber = 20; brickNumber < 30; brickNumber += 1)
     {
         bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 1940, 200));
     }
     for (int brickNumber = 30; brickNumber < 40; brickNumber += 1)
     {
         bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 2940, 250));
     }
 }
Exemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////
        // INITIALIZE THE SCREEN
        ///////////////////////////////////////////////////////////////////////
        public override void Initialize(ScreenManager mgr)
        {
            base.Initialize(mgr);
            batImage = Content.Load<Texture2D>("bat");
            ballImage = Content.Load<Texture2D>("ball");
            brickImage = Content.Load<Texture2D>("brick-bw");
            bricks[0] = new GameSprite(brickImage, new Vector2(0,0));
            bricks[0].image = brickImage;

            for(int brickNumber = 0; brickNumber < 10; brickNumber+=1)
            {
                bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100+60,100));
            }
            for (int brickNumber = 10; brickNumber < 20; brickNumber += 1)
            {
                bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 940, 150));
            }
            for (int brickNumber = 20; brickNumber < 30; brickNumber += 1)
            {
                bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 1940, 200));
            }
            for (int brickNumber = 30; brickNumber < 40; brickNumber += 1)
            {
                bricks[brickNumber] = new GameSprite(brickImage, new Vector2(brickNumber * 100 - 2940, 250));
            }

            bat = new GameSprite(batImage, Vector2.Zero);
            ball = new GameSprite(ballImage, Vector2.Zero);
            bounceSound = Content.Load<SoundEffect>("boinggg");
            bounceSoundInst = bounceSound.CreateInstance();
            pointScoredSound = Content.Load<SoundEffect>("break crate");
            loseSound = Content.Load<SoundEffect>("fail");
            ResetLevel();
        }