diff options
| -rw-r--r-- | assets/javascripts/rectangles/engine/builder.js | 33 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/map/ui.js | 5 |
2 files changed, 24 insertions, 14 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js index 7ee85ab..2b8734a 100644 --- a/assets/javascripts/rectangles/engine/builder.js +++ b/assets/javascripts/rectangles/engine/builder.js @@ -19,17 +19,17 @@ var builder = new function(){ } } function build (){ - clipper.rooms = sort_rooms_by_height(clipper.rooms) - clipper.rooms.forEach(function(r){ - floors(r).forEach(function(el){ + clipper.rooms = sort_rooms_by_id(clipper.rooms) + clipper.regions.forEach(function(r){ + walls(r).forEach(function(el){ els.push(el) scene.add(el) }) }) - clipper.rooms = sort_rooms_by_id(clipper.rooms) - clipper.regions.forEach(function(r){ - walls(r).forEach(function(el){ + clipper.rooms = sort_rooms_by_height(clipper.rooms) + clipper.rooms.forEach(function(r){ + floors(r).forEach(function(el){ els.push(el) scene.add(el) }) @@ -97,6 +97,7 @@ var builder = new function(){ var list = [], el = null var already_constructed = rm.intersects.filter(function(rr){ return rr.constructed }) + sort_rooms_by_height(already_constructed) if (already_constructed.length > 0) { // render the regions that don't intersect with anything we've already rendered @@ -104,12 +105,15 @@ var builder = new function(){ rm.regions.forEach(function(r){ var intersected = false for (var i = 0; i < already_constructed.length; i++) { - if (already_constructed[i].rect.intersects(r)) { + if (already_constructed[i].rect.contains(r)) { + intersected = true + r.sides = 0xf + } + else if (already_constructed[i].rect.intersects(r)) { intersected = true if (rm.height < already_constructed[i].height) { list = list.concat( ceiling_walls( rm, already_constructed[i], r ) ) } - } } if (! intersected) { @@ -136,7 +140,7 @@ var builder = new function(){ var depth = r.y.length() var height = hi.height - lo.height - if (r.x.a == hi.rect.x.a) { + if (! (r.sides & LEFT) && r.x.a == hi.rect.x.a) { el = wall('.left') el.rotationY = HALF_PI el.height = height @@ -145,9 +149,11 @@ var builder = new function(){ el.y = lo.height + height/2 el.z = r.y.a + depth/2 list.push(el) + r.sides |= LEFT + console.log(hi.height, lo.height) } - if (r.x.b == hi.rect.x.b) { + if (! (r.sides & RIGHT) && r.x.b == hi.rect.x.b) { el = wall('.right') el.rotationY = -HALF_PI el.height = height @@ -156,9 +162,10 @@ var builder = new function(){ el.y = lo.height + height/2 el.z = r.y.b - depth/2 list.push(el) + r.sides |= RIGHT } - if (r.y.a == hi.rect.y.a) { + if (! (r.sides & FRONT) && r.y.a == hi.rect.y.a) { el = wall('.front') el.width = width el.height = height @@ -167,9 +174,10 @@ var builder = new function(){ el.y = lo.height + height/2 el.z = r.y.a list.push(el) + r.sides |= FRONT } - if (r.y.b == hi.rect.y.b) { + if (! (r.sides & BACK) && r.y.b == hi.rect.y.b) { el = wall('.back') el.width = width el.height = height @@ -178,6 +186,7 @@ var builder = new function(){ el.y = lo.height + height/2 el.z = r.y.b list.push(el) + r.sides |= BACK } return list } diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js index ef96217..6560695 100644 --- a/assets/javascripts/rectangles/map/ui.js +++ b/assets/javascripts/rectangles/map/ui.js @@ -26,11 +26,12 @@ map.ui = new function(){ cursor.x.div(map.zoom).add( map.center.a + map.bounds.a/2 ) cursor.y.div(map.zoom).add( -map.center.b - map.bounds.b/2 ) - if (e.ctrlKey) { + if (e.ctrlKey || e.which === 3) { map.center.a = cursor.x.b = cursor.x.a + map.bounds.a/2 - map.center.b = cursor.y.b = cursor.y.a + map.center.b = cursor.y.b = cursor.y.a + map.bounds.b base.mouse.down = false e.preventDefault() + e.stopPropagation() return } |
