diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-11-05 00:51:30 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-11-05 00:51:30 +0100 |
commit | aee504be88f155adafc412936663607da72d7e4a (patch) | |
tree | 6fc8553f5c1b3c6633245fbedf3953e73cfa491b /src/controller | |
parent | 6a02ea105a4e15e9f36a5b2d7d0a26169164fb1d (diff) | |
download | rpgedit-aee504be88f155adafc412936663607da72d7e4a.tar rpgedit-aee504be88f155adafc412936663607da72d7e4a.zip |
Add collision radius
Diffstat (limited to 'src/controller')
-rw-r--r-- | src/controller/gamecontext.ts | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/controller/gamecontext.ts b/src/controller/gamecontext.ts index 295872d..8107b31 100644 --- a/src/controller/gamecontext.ts +++ b/src/controller/gamecontext.ts @@ -39,6 +39,7 @@ export class GameContext { private readonly entityPos: vec2 = vec2.clone([6, 6]); private readonly entityMovement: vec2 = vec2.create(); + private readonly collisionRadius = 7 / 16; private readonly walls: LineSegment[] = [ LineSegment.fromPoints(vec2.fromValues(1, 1), vec2.fromValues(11, 1)), @@ -99,10 +100,14 @@ export class GameContext { const move = new Movement(this.entityPos, dest); for (const w of this.walls) { - if (!w.collidesMove(dest2, move)) + if (!w.collidesMoveCircle(dest2, move, this.collisionRadius)) continue; if (!vec2.exactEquals(dest, dest2)) { + // Ensure termination + if (vec2.squaredDistance(this.entityPos, dest2) >= vec2.squaredDistance(this.entityPos, dest)) + return; + vec2.copy(dest, dest2); rescan = true; break; |