var mover = new function(){ var base = this base.room = null base.init = function(){ base.bind() base.update(scene.camera) } base.bind = function(){ app.on("move", base.update) } base.update = function(pos){ 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.contains(pos.x, pos.z)) { 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.collides(pos.x, pos.z) if (collision) { if (! (collision & LEFT || collision & RIGHT)) { cam.x = pos.x } if (! (collision & FRONT || collision & BACK)) { cam.z = pos.z } 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 = clipper.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.$floor.addClass("active") base.room.$ceiling.addClass("active") base.room.$walls.addClass("active") } } }