Ejemplo n.º 1
0
 public bool CollidesWith(Object2D obj2D)
 {
     if (!this.Visible || !obj2D.Visible || !BoundingBox.Intersects(obj2D.BoundingBox))
           return false;
       Rectangle b = Collision.Intersection(BoundingBox, obj2D.BoundingBox);
       for(int x = 0; x<b.Width; x++)
           for(int y = 0; y<b.Height; y++)
           {
               int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
               int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
               int objx = b.X - (int)(obj2D.GlobalPosition.X - obj2D.origin.X) + x;
               int objy = b.Y - (int)(obj2D.GlobalPosition.Y - obj2D.origin.Y) + y;
               if (SpriteSheet.GetPixelColor(thisx, thisy).A != 0 && obj2D.spriteSheet.GetPixelColor(objx, objy).A != 0)
                   return true;
           }
       return false;
 }
Ejemplo n.º 2
0
        public bool CollidesWith(Object2D obj2D)
        {
            if (!this.Visible || !obj2D.Visible || !BoundingBox.Intersects(obj2D.BoundingBox))
            {
                return(false);
            }
            Rectangle b = Collision.Intersection(BoundingBox, obj2D.BoundingBox);

            for (int x = 0; x < b.Width; x++)
            {
                for (int y = 0; y < b.Height; y++)
                {
                    int thisx = b.X - (int)(GlobalPosition.X - origin.X) + x;
                    int thisy = b.Y - (int)(GlobalPosition.Y - origin.Y) + y;
                    int objx  = b.X - (int)(obj2D.GlobalPosition.X - obj2D.origin.X) + x;
                    int objy  = b.Y - (int)(obj2D.GlobalPosition.Y - obj2D.origin.Y) + y;
                    if (SpriteSheet.GetPixelColor(thisx, thisy).A != 0 && obj2D.spriteSheet.GetPixelColor(objx, objy).A != 0)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }