diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-06-03 16:24:10 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-06-03 16:24:28 -0400 |
| commit | 607f69c67a5b4dc72d2754192e3cdf67d0ad11d0 (patch) | |
| tree | 6556e7922c5bedb274bb1650e5dd100643a7895d /client/assets/javascripts/rectangles/engine/rooms/mover.js | |
| parent | d31259291d807c851de4396921e0c26b6dd8dce2 (diff) | |
partitioning client and serveR
Diffstat (limited to 'client/assets/javascripts/rectangles/engine/rooms/mover.js')
| -rw-r--r-- | client/assets/javascripts/rectangles/engine/rooms/mover.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/client/assets/javascripts/rectangles/engine/rooms/mover.js b/client/assets/javascripts/rectangles/engine/rooms/mover.js new file mode 100644 index 0000000..e67d9bc --- /dev/null +++ b/client/assets/javascripts/rectangles/engine/rooms/mover.js @@ -0,0 +1,82 @@ +Rooms.mover = new function(){ + + var base = this + base.room = null + base.noclip = false + + base.init = function(){ + base.bind() + base.update(scene.camera) + } + + base.bind = function(){ + app.on("move", base.update) + keys.on("backslash", function(){ + base.noclip = ! base.noclip + base.room = null + app.movements.gravity( ! base.noclip ) + }) + } + + base.update = function(pos){ + var radius = scene.camera.radius + + if (base.noclip) { + cam.x = pos.x + cam.y = pos.y + cam.z = pos.z + return + } + + cam.y = pos.y + + // if we were in a room already.. + if (base.room) { + // check if we're still in the room + if (base.room.rect.containsDisc(pos.x, pos.z, radius)) { + cam.x = pos.x + cam.z = pos.z + return + } + + // check if we've breached one of the walls.. clamp position if so + var collision = base.room.collidesDisc(pos.x, pos.z, radius) + + if (collision) { + if (! (collision & LEFT_RIGHT)) { + cam.x = base.room.rect.x.clampDisc(pos.x, radius) + } + else { + // cam.x = base.room.rect.x.clampDisc(pos.x, radius) + } + if (! (collision & FRONT_BACK)) { + cam.z = base.room.rect.y.clampDisc(pos.z, radius) + } + 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 + + // determine what room we are in now + var intersects = Rooms.filter(function(r){ + return r.rect.contains(pos.x, pos.z) + }) + + // did we actually enter a room? + if (intersects.length) { + base.room = intersects[0] + base.room.mx_floor.forEach(function(w){ $(w.el).addClass("active") }) + base.room.mx_ceiling.forEach(function(w){ $(w.el).addClass("active") }) + base.room.mx_walls.forEach(function(w){ $(w.el).addClass("active") }) + } + + } + +} |
