/// <summary> /// Moves objeBePushed back until it isn't colliding with objPushing /// </summary> public static void Push(Sprite objPushing, AnimatedObject objBeingPushed) { if (Colliding(objPushing, objBeingPushed)) { Vector2 push = Utils.ClampMagnitude(objBeingPushed.Position - objPushing.position, 1); push *= MathF.Abs(Vector2.Distance(objBeingPushed.Position, objPushing.position) - (objBeingPushed.radius + objPushing.radius)); objBeingPushed.Position += push; } }
/// <summary> /// checks to see if an AnimatedObject and a LineSprite are colliding /// </summary> public static bool Colliding(AnimatedObject spriteOne, LineSprite spriteTwo) { float u = (spriteOne.Position.X - spriteTwo.StartPos.X) * (spriteTwo.EndPos.X - spriteTwo.StartPos.X); u += (spriteOne.Position.Y - spriteTwo.StartPos.Y) * (spriteTwo.EndPos.Y - spriteTwo.StartPos.Y); u /= MathF.Pow((spriteTwo.EndPos - spriteTwo.StartPos).Length(), 2); u = MathF.Max(u, 0); u = MathF.Min(u, 1); Vector2 P = spriteTwo.StartPos + (u * (spriteTwo.EndPos - spriteTwo.StartPos)); return(Vector2.Distance(P, spriteOne.Position) < spriteOne.radius + spriteTwo.thickness); }
/// <summary> /// checks to see if an AnimatedObject and a Rectangle are colliding /// </summary> public static bool Colliding(AnimatedObject spriteOne, Rectangle spriteTwo) { return(CheckCollisionCircleRec(spriteOne.Position, spriteOne.radius, spriteTwo)); }
/// <summary> /// checks to see if a Sprite and an AnimatedObject are colliding /// </summary> public static bool Colliding(Sprite spriteOne, AnimatedObject spriteTwo) { return(CheckCollisionCircles(spriteOne.position, spriteOne.radius, spriteTwo.Position, spriteTwo.radius)); }