public Ball(int x, int y) : base(new Vector2(x, y), XP.Load("Ball")) { //Offset the graphic to centre Graphic.Position = -Graphic.Size / 2; //Collision Collider = new CircleCollider(Graphic.Size.X / 2, Vector2.Zero); CollisionTags.Add("Ball"); }
private static bool CollideRectCirc(RectangleCollider a, CircleCollider b) { if (a.IntersectsPoint(b.GetCenter())) return true; //Check the circle against the four edges of the rectangle Vector2 pA = a.GetTopLeft(); Vector2 pB = a.GetTopRight(); Vector2 pC = a.GetBottomRight(); Vector2 pD = a.GetBottomLeft(); if (b.IntersectsLine(pA, pB, 0) || b.IntersectsLine(pB, pC, 0) || b.IntersectsLine(pC, pD, 0) || b.IntersectsLine(pD, pA, 0)) return true; return false; }
private static bool CollideCircCirc(CircleCollider a, CircleCollider b) { Vector2 diff = b.GetCenter() - a.GetCenter(); return (diff.X * diff.X + diff.Y * diff.Y < Math.Pow(XP.Distance(b.GetCenter(), a.GetCenter()),2)); }