public static bool InRangeOfInteraction(CollisionModel otherInstanceSpecs, CollisionModel currentSpecs) { if (getDistance(otherInstanceSpecs, currentSpecs) < Common.Settings.ActorSettings.InteractionDistance) { return(true); } return(false); }
public static bool Colliding(CollisionModel other, CollisionModel current) { if (Intersect(other, current) || Intersect(current, other)) { return(true); } return(false); }
private static bool PointWithin(CollisionModel area, Point point) { if (point.X <= area.X + area.Size / 2 && point.X >= area.X - area.Size / 2 && point.Y <= area.Y + area.Size / 2 && point.Y >= area.Y - area.Size / 2) { return(true); } return(false); }
private static int getDistance(CollisionModel from, CollisionModel to) { double xDiff = from.X - to.X; double yDiff = from.Y - to.Y; double stage = 2; double mainCalculation = Math.Pow(xDiff, stage) + Math.Pow(yDiff, stage); double result = Math.Sqrt(mainCalculation); return((int)result); }
private static bool Intersect(CollisionModel from, CollisionModel to) { Point leftUp = new Point(from.X - from.Size / 2, from.Y - from.Size / 2); Point rightUp = new Point(from.X + from.Size / 2, from.Y - from.Size / 2); Point rightDown = new Point(from.X + from.Size / 2, from.Y + from.Size / 2); Point leftDown = new Point(from.X - from.Size / 2, from.Y + from.Size / 2); if (PointWithin(to, leftUp) || PointWithin(to, rightUp) || PointWithin(to, rightDown) || PointWithin(to, leftDown)) { return(true); } return(false); }