Refactor collision handling

This commit is contained in:
Matthias Schiffer 2016-01-08 08:27:38 +01:00
parent 6c896c3f23
commit 00970b9faa

View file

@ -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) {