public override bool IsColliding(BHCollisionShape mShape) { if (mShape is BHCSPoint) { double dx = Parent.Position.X - mShape.Parent.Position.X; double dy = Parent.Position.Y - mShape.Parent.Position.Y; return dx*dx + dy*dy < RadiusSquared; } if (mShape is BHCSCircle) { var circle = (BHCSCircle) mShape; double dx = Parent.Position.X - mShape.Parent.Position.X; double dy = Parent.Position.Y - mShape.Parent.Position.Y; return dx*dx + dy*dy < RadiusSquared + circle.RadiusSquared; } return mShape.IsColliding(this); }
public override bool IsColliding(BHCollisionShape mShape) { return mShape.IsColliding(this); }
public override bool IsColliding(BHCollisionShape mShape) { if (mShape is BHCSPoint) { Vector2i p1 = Parent.Position; var angleVector = Utils.Math.Vectors.OrbitDegrees(new SSVector2F(p1.X, p1.Y), Degrees, Length); var p2 = new Vector2i((int) angleVector.X, (int) angleVector.Y); Vector2i p3 = mShape.Parent.Position; double xDelta = p2.X - p1.X; double yDelta = p2.Y - p1.Y; double u = ((p3.X - p1.X)*xDelta + (p3.Y - p1.Y)*yDelta)/(xDelta*xDelta + yDelta*yDelta); Vector2i closestPoint; if (u < 0) closestPoint = p1; else if (u > 1) closestPoint = p2; else closestPoint = new Vector2i((int) (p1.X + u*xDelta), (int) (p1.Y + u*yDelta)); double dx = closestPoint.X - p3.X; double dy = closestPoint.Y - p3.Y; return dx*dx + dy*dy < RadiusSquared; } if (mShape is BHCSCircle) return false; if (mShape is BHCSLine) return false; return mShape.IsColliding(this); }