Make physics more fun
This commit is contained in:
parent
155e360c8e
commit
89fafeafd3
41 changed files with 511 additions and 334 deletions
28
frontend/src/scripts/objects/planet-view.ts
Normal file
28
frontend/src/scripts/objects/planet-view.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { Drawable, Renderer } from 'sdf-2d';
|
||||
import { CommandExecutors, Id, Random, PlanetBase } from 'shared';
|
||||
import { RenderCommand } from '../commands/types/render';
|
||||
import { Polygon } from '../shapes/polygon';
|
||||
import { ViewObject } from './view-object';
|
||||
|
||||
export class PlanetView extends PlanetBase implements ViewObject {
|
||||
private shape: Drawable;
|
||||
|
||||
protected commandExecutors: CommandExecutors = {
|
||||
[RenderCommand.type]: (c: RenderCommand) => c.renderer.addDrawable(this.shape),
|
||||
};
|
||||
|
||||
constructor(id: Id, vertices: Array<vec2>) {
|
||||
super(id, vertices);
|
||||
this.shape = new Polygon(vertices);
|
||||
(this.shape as any).randomOffset = Random.getRandom();
|
||||
}
|
||||
|
||||
public step(deltaTimeInMilliseconds: number): void {
|
||||
(this.shape as any).randomOffset += deltaTimeInMilliseconds / 4000;
|
||||
}
|
||||
|
||||
public draw(renderer: Renderer): void {
|
||||
renderer.addDrawable(this.shape);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue