コード例 #1
0
        public static bool Intersects(Hitbox _a, Hitbox _b)
        {
            var a = (RectangleF)_a;
            var b = (RectangleF)_b;

            if (a.Left > b.Right)
                return false;
            if (a.Right < b.Left)
                return false;
            if (a.Top > b.Bottom)
                return false;
            if (a.Bottom < b.Top)
                return false;

            return true;
        }
コード例 #2
0
        public static bool Intersects(Hitbox b, CircularHitbox c)
        {
            //Vector2 closest = new Vector2(MathHelper.Clamp(c.Position.X, b.Centre.X - b.Size.X / 2, b.Centre.X + b.Size.X / 2),
            //    MathHelper.Clamp(c.Position.Y, b.Centre.Y - b.Size.Y / 2, b.Centre.Y + b.Size.Y / 2));

            //Vector2 distance = c.Position -closest;

            //return distance.LengthSquared() < (c.Radius * c.Radius);
            float cX = c.Position.X;
            float cY = c.Position.X;
            float rX = b.Centre.X;
            float rY = b.Centre.Y;
            float halfWidth = b.Width / 2;
            float halfHeight = b.Height / 2;

            float closestX = MathHelper.Clamp(cX, rX - halfWidth, rX + halfWidth);
            float closestY = MathHelper.Clamp(cY, rY - halfHeight, rY + halfHeight);

            float distX = cX - closestX;
            float distY = cY - closestY;

            float distSq = (distX * distX) + (distY * distY);
            return distSq < (c.Radius * c.Radius);
        }
コード例 #3
0
 public void SetHitbox(int width, int height)
 {
     Hitbox = new Hitbox(width, height, this);
     HasHitbox = true;
 }
コード例 #4
0
 public void MakeDefaultHitbox()
 {
     if (Graphic != null)
     {
         if (Animated)
         {
             Hitbox = new Hitbox(frameBounds.Width, frameBounds.Height, this);
             Hitbox.Offset = -Origin;
         }
         else
         {
             Hitbox = new Hitbox(Graphic.Width, Graphic.Height, this);
             Hitbox.Offset = -Origin;
         }
         //if (Hitbox.Flipped)
         //    H
     }
     else
         throw new InvalidOperationException("Graphic not assigned. Cannot assign default hitbox.");
     HasHitbox = true;
 }