diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/control/MapContext.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/control/MapContext.ts b/src/control/MapContext.ts index 4e69408..73b3c4d 100644 --- a/src/control/MapContext.ts +++ b/src/control/MapContext.ts @@ -59,21 +59,22 @@ export default class MapContext { } + private inMap(p: Position): boolean { + return p.x >= 0 && p.x < this.map.width && p.y >= 0 && p.y < this.map.height; + } + private incCollision(p: Position) { - if (this.collision[p.x] && !_.isUndefined(this.collision[p.x][p.y])) + if (this.inMap(p)) this.collision[p.x][p.y]++; } private decCollision(p: Position) { - if (this.collision[p.x] && !_.isUndefined(this.collision[p.x][p.y])) + if (this.inMap(p)) this.collision[p.x][p.y]--; } private collides(p: Position): boolean { - if (this.collision[p.x] && !_.isUndefined(this.collision[p.x][p.y])) - return (this.collision[p.x][p.y] > 0); - else - return true; + return (!this.inMap(p)) || (this.collision[p.x][p.y] > 0); } private addEntity(entity: EntityPosition) { |