//Picks either the upper, lower, left, or right sides for the grapple to attach to. public PointF getGrappleAttachPoint(Entity attachEnt, GrappleComponent grapComp) { PositionComponent attachPosComp = ( PositionComponent )attachEnt.getComponent(GlobalVars.POSITION_COMPONENT_NAME); PointF attachPos = attachPosComp.getLocAsPoint(); PointF attachSize = attachPosComp.getSizeAsPoint(); if (attachEnt.hasComponent(GlobalVars.COLLIDER_COMPONENT_NAME)) { ColliderComponent colComp = ( ColliderComponent )attachEnt.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME); attachPos = colComp.getLocationAsPoint(attachPosComp); attachSize = colComp.getSizeAsPoint(); } PointF grapPos = grapComp.getLastPoint(); PointF left = new PointF(attachPos.X - attachSize.X / 2, attachPos.Y); PointF right = new PointF(attachPos.X + attachSize.X / 2, attachPos.Y); PointF up = new PointF(attachPos.X, attachPos.Y - attachSize.Y / 2); PointF down = new PointF(attachPos.X, attachPos.Y + attachSize.Y / 2); double distLeft = getDist(grapPos, left); double distRight = getDist(grapPos, right); double distUp = getDist(grapPos, up); double distDown = getDist(grapPos, down); double minA = Math.Min(distLeft, distRight); double minB = Math.Min(distUp, distDown); double min = Math.Min(minA, minB); if (min == distLeft) { return(left); } else if (min == distRight) { return(right); } else if (min == distUp) { return(up); } else if (min == distDown) { return(down); } else { Console.WriteLine("Error picking point for grapple attachment!"); return(attachPos); } }