Add better object updates

This commit is contained in:
schmelczerandras 2020-10-17 18:35:09 +02:00
parent fd80a299b6
commit e83c58e1a5
29 changed files with 289 additions and 123 deletions

View file

@ -0,0 +1,37 @@
import { vec2 } from 'gl-matrix';
import { Renderer } from 'sdf-2d';
import { Circle, Id, PlayerCharacterBase, UpdateMessage } from 'shared';
import { BlobShape } from '../shapes/blob-shape';
import { ViewObject } from './view-object';
export class PlayerCharacterView extends PlayerCharacterBase implements ViewObject {
private shape: BlobShape;
constructor(
id: Id,
name: string,
colorIndex: number,
head?: Circle,
leftFoot?: Circle,
rightFoot?: Circle,
) {
super(id, name, colorIndex, head, leftFoot, rightFoot);
this.shape = new BlobShape(colorIndex);
}
public update(updates: Array<UpdateMessage>) {
updates.forEach((u) => ((this as any)[u.key] = u.value));
}
public get position(): vec2 {
return this.head!.center;
}
public step(deltaTimeInMilliseconds: number): void {}
public draw(renderer: Renderer): void {
this.shape.setCircles([this.head!, this.leftFoot!, this.rightFoot!]);
renderer.addDrawable(this.shape);
}
}