summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/engine/builder.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/engine/builder.js')
-rw-r--r--assets/javascripts/rectangles/engine/builder.js33
1 files changed, 21 insertions, 12 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
}