diff options
| author | Julie Lala <jules@okfoc.us> | 2014-04-24 09:18:06 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-04-24 09:45:26 -0400 |
| commit | a9f550c6981d96d5ff0910601586a7477396fe56 (patch) | |
| tree | cdacde4d4af8e549c0bf899c7fe326e7272baf1e /assets/javascripts/rectangles/engine/mover.js | |
| parent | 1f434dfedae0f57c0b74978a6c5c144e34287501 (diff) | |
corner collision
Diffstat (limited to 'assets/javascripts/rectangles/engine/mover.js')
| -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 } } |
