Refactor physics

This commit is contained in:
schmelczerandras 2020-10-05 20:30:42 +02:00
parent 46a48e7c15
commit c5d97eeea6
40 changed files with 484 additions and 791 deletions

View file

@ -0,0 +1,45 @@
import { vec2, vec3 } from 'gl-matrix';
import { LampBase, settings, id } from 'shared';
import { ImmutableBoundingBox } from '../physics/bounding-boxes/immutable-bounding-box';
import { Physical } from '../physics/physical';
export class LampPhysical extends LampBase implements Physical {
public readonly canCollide = false;
public readonly isInverted = false;
public readonly canMove = false;
constructor(center: vec2, color: vec3, lightness: number) {
super(id(), center, color, lightness);
}
private _boundingBox?: ImmutableBoundingBox;
public get boundingBox(): ImmutableBoundingBox {
if (!this._boundingBox) {
this._boundingBox = new ImmutableBoundingBox(
this.center.x - settings.lightCutoffDistance,
this.center.x + settings.lightCutoffDistance,
this.center.y - settings.lightCutoffDistance,
this.center.y + settings.lightCutoffDistance
);
}
return this._boundingBox;
}
public get gameObject(): LampPhysical {
return this;
}
// todo
public distance(_: vec2): number {
return 0;
}
public toJSON(): any {
const { type, id, center, color, lightness } = this;
return [type, id, center, color, lightness];
}
}