diff options
Diffstat (limited to 'assets/javascripts/rectangles')
| -rw-r--r-- | assets/javascripts/rectangles/_env.js | 41 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/engine/builder.js | 10 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/engine/clipper.js | 2 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/engine/mover.js | 31 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/draw.js | 2 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/util/keys.js | 9 |
6 files changed, 67 insertions, 28 deletions
diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js index 818cb55..be3d931 100644 --- a/assets/javascripts/rectangles/_env.js +++ b/assets/javascripts/rectangles/_env.js @@ -2,50 +2,43 @@ var environment = new function(){} environment.init = function(){ window.scene && scene.camera.move({ - "x": 500, + "x": 1000, "y": 1500, - "z": 200, - "rotationX": PI/2, - "rotationY": PI + "z": 250, + "rotationX": 0, // PI/2, + "rotationY": PI/2, // PI }) // map.center.a = scene.camera.x // map.center.b = scene.camera.z - map.center.a = 100 - map.center.b = 100 + map.center.a = 0 + map.center.b = 0 clipper.rooms.push( new room ({ - rect: new rect(-100,-100, 100,100), - height: 400, + rect: new rect(0,0, 500,500), + height: 500, })) clipper.rooms.push( new room ({ - rect: new rect(100,100, 200,300), - height: 400, + rect: new rect(600,0, 1100,500), + height: 500, })) clipper.rooms.push( new room ({ - rect: new rect(200,300, 300,500), - height: 400, - })) - clipper.rooms.push( new room ({ - rect: new rect(300,100, 600,300), - height: 400, - })) - clipper.rooms.push( new room ({ - rect: new rect(400,200, 700,400), - height: 400, + rect: new rect(450,150, 650,350), + height: 300, })) + app.movements.gravity(true) - builder.init() - if (window.location.href.match(/stone/)) { - builder.tube.on("clip", function(){ + app.on("clip", function(){ $(".face").css({ "background-image": "url(http://i.asdf.us/im/4a/_1398144847_frankhats.gif)" }) }) $("#map").hide() } - + + builder.init() + mover.init() clipper.init() window.scene && scene.update() environment.update() diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js index 2b8734a..8e1508a 100644 --- a/assets/javascripts/rectangles/engine/builder.js +++ b/assets/javascripts/rectangles/engine/builder.js @@ -1,6 +1,5 @@ var builder = new function(){ var base = this - base.tube = new Tube () var els = [] @@ -9,7 +8,7 @@ var builder = new function(){ } base.bind = function(){ - base.tube.on("clip", rebuild) + app.on("clip", rebuild) } function rebuild(){ @@ -20,6 +19,10 @@ var builder = new function(){ } function build (){ clipper.rooms = sort_rooms_by_id(clipper.rooms) + clipper.rooms.forEach(function(r){ + r.walls = [] + r.floors = [] + }) clipper.regions.forEach(function(r){ walls(r).forEach(function(el){ els.push(el) @@ -203,6 +206,9 @@ var builder = new function(){ el.z = r.y.a + depth/2 el.rotationX = PI/2 el.el.style.backgroundColor = "#f00" + + rm.floors.push(el) + return el } function ceiling(rm, r){ diff --git a/assets/javascripts/rectangles/engine/clipper.js b/assets/javascripts/rectangles/engine/clipper.js index 79e44e5..bcd0586 100644 --- a/assets/javascripts/rectangles/engine/clipper.js +++ b/assets/javascripts/rectangles/engine/clipper.js @@ -18,7 +18,7 @@ var clipper = new function(){ base.update = function(){ clipper.solve_rects() - builder.tube("clip") + app.tube("clip") } base.add_room = function(r){ diff --git a/assets/javascripts/rectangles/engine/mover.js b/assets/javascripts/rectangles/engine/mover.js new file mode 100644 index 0000000..ebe4447 --- /dev/null +++ b/assets/javascripts/rectangles/engine/mover.js @@ -0,0 +1,31 @@ +var mover = new function(){ + + var base = this + var last_room = null + + base.init = function(){ + last_room = clipper.rooms[0] + base.bind() + } + + base.bind = function(){ + app.on("move", base.update) + } + + base.update = function(pos){ + if (last_room && last_room.rect.contains(pos.x, pos.z)) return; + + var intersects = [] + clipper.rooms.forEach(function(r){ + if (r.rect.contains(pos.x, pos.z)) { + intersects.push(r) + } + }) + + if (intersects.length) { + $(".face.active").removeClass("active") + last_room = intersects[0] + } + } + +} diff --git a/assets/javascripts/rectangles/map/draw.js b/assets/javascripts/rectangles/map/draw.js index 57faa10..560cf38 100644 --- a/assets/javascripts/rectangles/map/draw.js +++ b/assets/javascripts/rectangles/map/draw.js @@ -151,7 +151,7 @@ map.draw = new function(){ ctx.save() ctx.translate(x,z) - var radius = 3 / map.zoom + var radius = 2 / map.zoom ctx.beginPath(); ctx.arc(0, 0, radius, 0, 2*Math.PI, false); diff --git a/assets/javascripts/rectangles/util/keys.js b/assets/javascripts/rectangles/util/keys.js index 7c437a1..03abe50 100644 --- a/assets/javascripts/rectangles/util/keys.js +++ b/assets/javascripts/rectangles/util/keys.js @@ -1,7 +1,16 @@ var keys = (function(){ + var base = new function(){} base.tube = new Tube () + base.on = function(){ + base.tube.on.apply(base.tube, arguments) + } + + base.off = function(){ + base.tube.off.apply(base.tube, arguments) + } + $(window).keydown(function(e){ var key = KEY_NAMES[e.keyCode]; switch (key) { |
