diff options
Diffstat (limited to 'assets/javascripts/rectangles/engine')
| -rw-r--r-- | assets/javascripts/rectangles/engine/builder.js | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js index 697b7e7..ba180d2 100644 --- a/assets/javascripts/rectangles/engine/builder.js +++ b/assets/javascripts/rectangles/engine/builder.js @@ -112,8 +112,13 @@ var builder = new function(){ var intersected = false for (var i = 0; i < already_constructed.length; i++) { if (already_constructed[i].rect.intersects(r)) { - // probably create walls here? + // probably create extra walls here? intersected = true + + if (rm.height < already_constructed[i].height) { + list = list.concat( ceiling_walls( rm, already_constructed[i], r ) ) + } + } } if (! intersected) { @@ -122,7 +127,6 @@ var builder = new function(){ } }) - } else { // render floor and ceiling for the entire rectangle @@ -133,6 +137,59 @@ var builder = new function(){ rm.constructed = true return list } + + function ceiling_walls( lo, hi, r ){ + var list = [] + + var width = r.x.length() + var depth = r.y.length() + var height = hi.height - lo.height + + if (r.x.a == hi.rect.x.a) { + el = wall('.left') + el.rotationY = HALF_PI + el.height = height + el.width = depth + el.x = r.x.a + el.y = lo.height + height/2 + el.z = r.y.a + depth/2 + list.push(el) + } + + if (r.x.b == hi.rect.x.b) { + el = wall('.right') + el.rotationY = -HALF_PI + el.height = height + el.width = depth + el.x = r.x.b + el.y = lo.height + height/2 + el.z = r.y.b - depth/2 + list.push(el) + } + + if (r.y.a == hi.rect.y.a) { + el = wall('.front') + el.width = width + el.height = height + el.rotationY = PI + el.x = r.x.a + width/2 + el.y = lo.height + height/2 + el.z = r.y.a + list.push(el) + } + + if (r.y.b == hi.rect.y.b) { + el = wall('.back') + el.width = width + el.height = height + el.rotationY = 0 + el.x = r.x.b - width/2 + el.y = lo.height + height/2 + el.z = r.y.b + list.push(el) + } + return list + } function ground(rm, r){ var width = r.x.length() |
