修复box因缺少初始化报错问题

This commit is contained in:
yhh
2020-06-16 16:35:17 +08:00
parent 7f5b78f340
commit 447ea4efe4
18 changed files with 272 additions and 910 deletions

View File

@@ -3,6 +3,24 @@ class Box extends Polygon {
public width: number;
public height: number;
constructor(width: number, height: number){
super(Box.buildBox(width, height), true);
this.width = width;
this.height = height;
}
private static buildBox(width: number, height: number): Vector2[]{
let halfWidth = width / 2;
let halfHeight = height / 2;
let verts = new Array(4);
verts[0] = new Vector2(-halfWidth, -halfHeight);
verts[1] = new Vector2(halfWidth, -halfHeight);
verts[2] = new Vector2(halfWidth, halfHeight);
verts[3] = new Vector2(-halfWidth, halfHeight);
return verts;
}
public updateBox(width: number, height: number){
this.width = width;
this.height = height;

View File

@@ -14,9 +14,11 @@ class Polygon extends Shape {
}
public isBox: boolean;
constructor(vertCount: number, radius: number) {
constructor(points: Vector2[], isBox?: boolean){
super();
this.setPoints(Polygon.buildSymmertricalPolygon(vertCount, radius));
this.setPoints(points);
this.isBox = isBox;
}
private buildEdgeNormals(){
@@ -42,8 +44,10 @@ class Polygon extends Shape {
this.points = points;
this.recalculateCenterAndEdgeNormals();
this._originalPoints = new Array(this.points.length);
this.points.forEach(point => this._originalPoints.push(point));
this._originalPoints = [];
for (let i = 0; i < this.points.length; i ++){
this._originalPoints.push(this.points[i]);
}
}
public collidesWithShape(other: Shape){