summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-01-08 08:27:38 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2016-01-08 08:27:38 +0100
commit00970b9faa9338817ec3dddced6dadef69d86fe3 (patch)
treedf5f7ecefe2458a54f3a5d024aa5b543f3faf373
parent6c896c3f23895582967aadb8d379d617d757f2fd (diff)
downloadrpgedit-00970b9faa9338817ec3dddced6dadef69d86fe3.tar
rpgedit-00970b9faa9338817ec3dddced6dadef69d86fe3.zip
Refactor collision handling
-rw-r--r--src/control/MapContext.ts13
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) {