diff options
| -rw-r--r-- | assets/javascripts/rectangles/engine/builder.js | 15 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/room.js | 26 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/wall.js | 11 |
3 files changed, 37 insertions, 15 deletions
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js index bdc52ed..dcd89dc 100644 --- a/assets/javascripts/rectangles/engine/builder.js +++ b/assets/javascripts/rectangles/engine/builder.js @@ -143,7 +143,8 @@ var builder = new function(){ else if (constructed[i].rect.intersects(region)) { intersected = true if (room.height < constructed[i].height) { - list = list.concat( make_ceiling_walls( room, constructed[i], region ) ) + var ceiling_walls = make_ceiling_walls( room, constructed[i], region ) + list = list.concat(ceiling_walls) } } } @@ -191,8 +192,9 @@ var builder = new function(){ el.z = region.y.a + depth/2 el.rect = region list.push(el) - hi.walls.push(el) + hi.mx_walls.push(el) region.half_sides |= LEFT + el.half_side = LEFT } if (! (region.half_sides & RIGHT) && region.x.b == hi.rect.x.b) { @@ -205,8 +207,9 @@ var builder = new function(){ el.z = region.y.b - depth/2 el.rect = region list.push(el) - hi.walls.push(el) + hi.mx_walls.push(el) region.half_sides |= RIGHT + el.half_side = RIGHT } if (! (region.half_sides & FRONT) && region.y.a == hi.rect.y.a) { @@ -219,8 +222,9 @@ var builder = new function(){ el.z = region.y.a el.rect = region list.push(el) - hi.walls.push(el) + hi.mx_walls.push(el) region.half_sides |= FRONT + el.half_side = FRONT } if (! (region.half_sides & BACK) && region.y.b == hi.rect.y.b) { @@ -233,8 +237,9 @@ var builder = new function(){ el.z = region.y.b el.rect = region list.push(el) - hi.walls.push(el) + hi.mx_walls.push(el) region.half_sides |= BACK + el.half_side = BACK } return list } diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js index 440dacb..3636284 100644 --- a/assets/javascripts/rectangles/models/room.js +++ b/assets/javascripts/rectangles/models/room.js @@ -61,12 +61,13 @@ window.Room = (function(){ base.mx_walls.forEach(function(wall){ // ignore half-walls for now - if (! wall.side) return; - if (side_groups[ wall.side ]) { - side_groups[ wall.side ].push(wall) + var side = wall.side || wall.half_side + + if (side_groups[side]) { + side_groups[side].push(wall) } else { - side_groups[ wall.side ] = [wall] + side_groups[side] = [wall] } }) @@ -81,11 +82,19 @@ window.Room = (function(){ els.sort(compare_z) } - var wall = new_wall(els.shift()) - walls.push(wall) + var wall els.forEach(function(el){ - if (side & FRONT_BACK && wall.rect.x.b == el.rect.x.a) { + if (el.half_side) { + wall = new_wall(el) + walls.push(wall) + wall = null + } + else if (! wall) { + wall = new_wall(el) + walls.push(wall) + } + else if (side & FRONT_BACK && wall.rect.x.b == el.rect.x.a) { wall.rect.x.b = el.rect.x.b wall.mx.push(el) } @@ -103,7 +112,8 @@ window.Room = (function(){ function new_wall (el) { return new Wall ({ room: base.id, - side: el.side, + side: el.side | el.half_side, + half_side: el.half_side, rect: el.rect.clone(), el: el, }) diff --git a/assets/javascripts/rectangles/models/wall.js b/assets/javascripts/rectangles/models/wall.js index ecc334d..baaac43 100644 --- a/assets/javascripts/rectangles/models/wall.js +++ b/assets/javascripts/rectangles/models/wall.js @@ -46,9 +46,16 @@ window.Wall = (function(){ new vec2( img.height/2, clipper.rooms[this.room].height - img.height/2 ) ) } - var bzz = 0 + Wall.prototype.color = function(color){ + this.$walls && this.$walls.css("background-color", color) + } + Wall.prototype.randomize_colors = function(){ - this.$walls.css("background-color", window.colors[bzz=(bzz+1)%window.colors.length]) + var base = this + var match = base.side | base.half_side + var walls = clipper.rooms[this.room].walls.filter(function(w){ return (w.side | w.half_side) & match }) + var color = choice(window.colors) + walls.forEach(function(w){ w.color(color) }) } return Wall |
