diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-10-31 23:13:52 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-10-31 23:25:26 +0100 |
commit | 1ae0884a7376a87a2df4a77d1ba861cd58a4dda7 (patch) | |
tree | fa70185d4163d6a2a6132f4246ba550d38e831e5 /src/controller | |
parent | 5372d1b4173234a5066010a4ca973a5b1ad2a629 (diff) | |
download | rpgedit-1ae0884a7376a87a2df4a77d1ba861cd58a4dda7.tar rpgedit-1ae0884a7376a87a2df4a77d1ba861cd58a4dda7.zip |
controller: clean up GameContext a bit
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/gamecontext.ts | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/src/controller/gamecontext.ts b/src/controller/gamecontext.ts index 76ca7cc..4d86abf 100644 --- a/src/controller/gamecontext.ts +++ b/src/controller/gamecontext.ts @@ -10,14 +10,6 @@ import { getJSON } from '../util'; import { vec2 } from 'gl-matrix'; -function snapToGrid(out: vec2, a: vec2): void { - const res = 64; - - vec2.scale(out, a, res); - vec2.round(out, out); - vec2.scale(out, out, 1 / res); -} - export class GameContext { public static async load(renderer: Renderer): Promise<GameContext> { const [ @@ -66,10 +58,7 @@ export class GameContext { } private updateTime(time: number): number { - let diff = 0; - if (this.time !== null) - diff = time - this.time; - + const diff = this.time !== null ? time - this.time : 0; this.time = time; return diff; @@ -78,8 +67,10 @@ export class GameContext { private update(time: number): void { const diff = this.updateTime(time); - vec2.scaleAndAdd(this.entityPos, this.entityPos, this.entityMovement, diff * this.speed); - snapToGrid(this.entityPos, this.entityPos); + if (vec2.sqrLen(this.entityMovement) > 0) + vec2.scaleAndAdd(this.entityPos, this.entityPos, this.entityMovement, diff * this.speed); + else + this.renderer.snapToGrid(this.entityPos, this.entityPos); } private render = (time: number) => { |