예제 #1
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);
        }
예제 #2
0
 public Explosion(Vector2 position, float radius, float time)
 {
     aoe = new CircularHitbox(position, radius);
     Position = position;
     timer = time;
 }
예제 #3
0
 /// <summary>
 /// Query the stage for intersection with a CircularHitbox.
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public List<Entity> QueryCircle(CircularHitbox box, string type)
 {
     var result = new List<Entity>();
     for (int i = 0; i < AllEntities.Count; i++)
     {
         if (AllEntities[i].HasHitbox && AllEntities[i].Type == type)
         {
             if (Utils.Intersects(AllEntities[i].Hitbox, box))
                 result.Add(AllEntities[i]);
         }
     }
     return result;
 }