Microsoft.Xna.Framework.Rectangle.Intersects C# (CSharp) Method

Intersects() public method

public Intersects ( Rectangle value ) : bool
value Rectangle
return bool
		public bool Intersects (Rectangle value)
		{
			return value.X < this.X + this.Width && this.X < value.X + value.Width && value.Y < this.Y + this.Height && this.Y < value.Y + value.Height;
		}

Same methods

Rectangle::Intersects ( Rectangle &value, bool &result ) : void

Usage Example

Beispiel #1
0
 public void HandleBulletZombieCollision(Player p, EnemyHandler e)
 {
     foreach (Bullet b in p.bullets)
         if (b.Visible)
         {
             bulletRectangle = new Rectangle((int)b.X, (int)b.Y, 2, 1);
             foreach (ZombieDispenser zd in e.zombies)
                 foreach (Zombie z in zd.zombies)
                     if (z.Visible)
                     {
                         zombieRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 19 * z.Scale), (int)(28 * z.Scale), (int)(45 * z.Scale));
                         zombieHeadRectangle = new Rectangle((int)(z.X + 18 * z.Scale), (int)(z.Y + 4 * z.Scale), (int)(22 * z.Scale), (int)(15 * z.Scale));
                         if (bulletRectangle.Intersects(zombieRectangle))
                         {
                             z.Hitpoints -= bulletDmg;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                         else if(bulletRectangle.Intersects(zombieHeadRectangle))
                         {
                             z.Hitpoints = 0;
                             p.Score += 5;
                             b.SprayBlood = true;
                             b.Visible = false;
                         }
                     }
         }
 }
All Usage Examples Of Microsoft.Xna.Framework.Rectangle::Intersects