Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. static class CollisionCalculator
  2.     {
  3.         public static bool RadiusRadius(CollisionRadiusGO first, CollisionRadiusGO second)
  4.         {
  5.             double x = first.Position.X - second.Position.X;
  6.             double y = first.Position.Y + first.HitRadiusOffset - second.Position.Y + second.HitRadiusOffset;
  7.             double length = x + y;
  8.  
  9.             return (Math.Pow(first.HitRadius + second.HitRadius, 2) > length);
  10.         }
  11.  
  12.         public static bool RectangleRadius(CollisionRectGO first, CollisionRadiusGO second)
  13.         {
  14.             float deltaX = second.Position.X - MathHelper.Max(first.Hitbox.Left, MathHelper.Max(second.Position.X, first.Hitbox.Right));
  15.             float deltaY = second.Position.Y + second.HitRadiusOffset - MathHelper.Max(first.Hitbox.Top, MathHelper.Max(second.Position.Y + second.HitRadiusOffset, first.Hitbox.Bottom));
  16.             return (deltaX * deltaX + deltaY * deltaY) < Math.Pow(second.HitRadius * second.HitRadius, 2);
  17.         }
  18.  
  19.         private static bool RectangleRectangle(CollisionRectGO first, CollisionRectGO second)
  20.         {
  21.             return first.Hitbox.Intersects(second.Hitbox);
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement