diff options
Diffstat (limited to 'assets/javascripts/rectangles/engine')
| -rw-r--r-- | assets/javascripts/rectangles/engine/mover.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/assets/javascripts/rectangles/engine/mover.js b/assets/javascripts/rectangles/engine/mover.js index 5a1f7d9..311ed83 100644 --- a/assets/javascripts/rectangles/engine/mover.js +++ b/assets/javascripts/rectangles/engine/mover.js @@ -15,15 +15,17 @@ var mover = new function(){ base.update = function(pos){ cam.y = pos.y - // if we were in a room + // if we were in a room already.. if (base.room) { + // check if we're still in the room if (base.room.rect.contains(pos.x, pos.z)) { cam.x = pos.x cam.z = pos.z return } - // check if we've crossed one of the walls.. clamp position if so + + // check if we've breached one of the walls.. clamp position if so var collision = base.room.collides(pos.x, pos.z) if (collision) { if (! (collision & LEFT || collision & RIGHT)) { @@ -34,26 +36,29 @@ var mover = new function(){ } return } + + // in this case, we appear to have left the room.. + $(".face.active").removeClass("active") + base.room = null } + + // collision test failed, so update position + cam.x = pos.x + cam.z = pos.z - // otherwise we've either entered into a new room, or broken free + // determine what room we are in now var intersects = clipper.rooms.filter(function(r){ return r.rect.contains(pos.x, pos.z) }) - $(".face.active").removeClass("active") + // did we actually enter a room? if (intersects.length) { base.room = intersects[0] base.room.$floor.addClass("active") base.room.$ceiling.addClass("active") base.room.$walls.addClass("active") } - else { - base.room = null - } - cam.x = pos.x - cam.z = pos.z } } |
