2020-06-12 08:47:13 +08:00
|
|
|
///<reference path="./Shape.ts" />
|
|
|
|
|
class Circle extends Shape {
|
|
|
|
|
public radius: number;
|
|
|
|
|
private _originalRadius: number;
|
|
|
|
|
|
|
|
|
|
constructor(radius: number){
|
|
|
|
|
super();
|
|
|
|
|
this.radius = radius;
|
|
|
|
|
this._originalRadius = radius;
|
|
|
|
|
}
|
2020-06-12 20:24:51 +08:00
|
|
|
|
|
|
|
|
public pointCollidesWithShape(point: Vector2): CollisionResult {
|
|
|
|
|
return ShapeCollisions.pointToCicle(point, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public collidesWithShape(other: Shape): CollisionResult{
|
2020-06-15 10:42:06 +08:00
|
|
|
if (other instanceof Box && (other as Box).isUnrotated){
|
|
|
|
|
return ShapeCollisions.circleToRect(this, other as Box);
|
2020-06-12 20:24:51 +08:00
|
|
|
}
|
|
|
|
|
|
2020-06-15 20:08:21 +08:00
|
|
|
if (other instanceof Circle){
|
|
|
|
|
// TODO CIRCLETOCIRCLE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (other instanceof Polygon){
|
|
|
|
|
return ShapeCollisions.circleToPolygon(this, other);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-12 20:24:51 +08:00
|
|
|
throw new Error(`Collisions of Circle to ${other} are not supported`);
|
|
|
|
|
}
|
2020-06-15 20:08:21 +08:00
|
|
|
|
|
|
|
|
public recalculateBounds(collider: Collider) {
|
|
|
|
|
this.center = collider.localOffset;
|
|
|
|
|
}
|
2020-06-12 08:47:13 +08:00
|
|
|
}
|