summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/javascripts/mx/extensions/mx.movements.js2
-rw-r--r--assets/javascripts/rectangles/engine/builder.js102
-rw-r--r--assets/javascripts/rectangles/engine/clipper.js3
-rw-r--r--assets/javascripts/rectangles/map/ui.js5
-rw-r--r--assets/javascripts/rectangles/models/room.js2
-rw-r--r--assets/javascripts/rectangles/util/mouse.js11
-rw-r--r--assets/javascripts/rectangles/util/sort.js5
7 files changed, 99 insertions, 31 deletions
diff --git a/assets/javascripts/mx/extensions/mx.movements.js b/assets/javascripts/mx/extensions/mx.movements.js
index 4e964f9..97aff02 100644
--- a/assets/javascripts/mx/extensions/mx.movements.js
+++ b/assets/javascripts/mx/extensions/mx.movements.js
@@ -17,7 +17,7 @@ MX.Movements = function (cam, viewHeight) {
locked = false,
gravity = false
- var v = 28,
+ var v = 20,
vr = Math.PI * 0.015
jumpV = 30,
vx = vy = vz = 0,
diff --git a/assets/javascripts/rectangles/engine/builder.js b/assets/javascripts/rectangles/engine/builder.js
index 7248689..697b7e7 100644
--- a/assets/javascripts/rectangles/engine/builder.js
+++ b/assets/javascripts/rectangles/engine/builder.js
@@ -26,6 +26,15 @@ var builder = new function(){
}
}
function build (){
+ clipper.rooms = sort_rooms_by_height(clipper.rooms)
+ clipper.rooms.forEach(function(r){
+ floors(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){
els.push(el)
@@ -53,6 +62,7 @@ var builder = new function(){
el.height = height
el.rotationY = PI
el.x = r.x.a + width/2
+ el.y = height/2
el.z = r.y.a
list.push(el)
}
@@ -62,6 +72,7 @@ var builder = new function(){
el.height = height
el.rotationY = 0
el.x = r.x.b - width/2
+ el.y = height/2
el.z = r.y.b
list.push(el)
}
@@ -71,6 +82,7 @@ var builder = new function(){
el.height = height
el.width = depth
el.x = r.x.a
+ el.y = height/2
el.z = r.y.a + depth/2
list.push(el)
}
@@ -80,11 +92,53 @@ var builder = new function(){
el.height = height
el.width = depth
el.x = r.x.b
+ el.y = height/2
el.z = r.y.b - depth/2
list.push(el)
}
- el = wall('.bottom')
+ return list
+ }
+
+ function floors(rm){
+ var list = [], el = null
+
+ var already_constructed = rm.intersects.filter(function(rr){ return rr.constructed })
+
+ if (already_constructed.length > 0) {
+ // render the regions that don't intersect with anything we've already rendered
+ // if the height is different, calculate the overlapping sides and render half-walls
+ rm.regions.forEach(function(r){
+ var intersected = false
+ for (var i = 0; i < already_constructed.length; i++) {
+ if (already_constructed[i].rect.intersects(r)) {
+ // probably create walls here?
+ intersected = true
+ }
+ }
+ if (! intersected) {
+ list.push( ground(rm, r) )
+ list.push( ceiling(rm, r) )
+ }
+ })
+
+
+ }
+ else {
+ // render floor and ceiling for the entire rectangle
+ list.push( ground(rm, rm.rect) )
+ list.push( ceiling(rm, rm.rect) )
+ }
+
+ rm.constructed = true
+ return list
+ }
+
+ function ground(rm, r){
+ var width = r.x.length()
+ var depth = r.y.length()
+
+ var el = wall('.bottom')
el.height = depth
el.width = width
el.x = r.x.a + width/2
@@ -92,31 +146,31 @@ var builder = new function(){
el.z = r.y.a + depth/2
el.rotationX = PI/2
el.el.style.backgroundColor = "#f00"
- list.push(el)
+ return el
+ }
+ function ceiling(rm, r){
+ var width = r.x.length()
+ var depth = r.y.length()
+ var height = rm.height
- if (r.sides != 0) {
- el = wall('.top')
- el.height = depth
- el.width = width
- el.x = r.x.a + width/2
- el.y = height
- el.z = r.y.a + depth/2
- el.rotationX = -PI/2
- el.el.style.backgroundColor = "#00f"
- list.push(el)
- }
+ var el = wall('.top')
+ el.height = depth
+ el.width = width
+ el.x = r.x.a + width/2
+ el.y = height
+ el.z = r.y.a + depth/2
+ el.rotationX = -PI/2
+ el.el.style.backgroundColor = "#00f"
+ return el
+ }
- function wall(klass){
- var el = new MX.Object3D(".face" + (klass || ""))
- el.width = el.height = el.scaleX = el.scaleY = el.scaleZ = 1
- el.z = el.y = el.x = 0
- el.y = height/2
- el.type = "Face"
- el.el.style.opacity = 1.0
- return el
- }
-
- return list
+ function wall(klass){
+ var el = new MX.Object3D(".face" + (klass || ""))
+ el.width = el.height = el.scaleX = el.scaleY = el.scaleZ = 1
+ el.z = el.y = el.x = 0
+ el.type = "Face"
+ el.el.style.opacity = 1.0
+ return el
}
}
diff --git a/assets/javascripts/rectangles/engine/clipper.js b/assets/javascripts/rectangles/engine/clipper.js
index d6eb618..2b04a23 100644
--- a/assets/javascripts/rectangles/engine/clipper.js
+++ b/assets/javascripts/rectangles/engine/clipper.js
@@ -47,6 +47,8 @@ var clipper = new function(){
if (left.rect.intersects(right.rect)) {
left.clipTo(right.rect)
right.clipTo(left.rect)
+ left.intersects.push(right)
+ right.intersects.push(left)
}
if (left.rect.x.b < right.rect.x.a) {
break
@@ -91,7 +93,6 @@ var clipper = new function(){
}
}
- base.rooms = sort_rooms_by_id(rooms)
base.regions = sort_rects_by_position(regions)
}
diff --git a/assets/javascripts/rectangles/map/ui.js b/assets/javascripts/rectangles/map/ui.js
index 9faebea..f612fe2 100644
--- a/assets/javascripts/rectangles/map/ui.js
+++ b/assets/javascripts/rectangles/map/ui.js
@@ -58,7 +58,10 @@ map.ui = new function(){
}
}
- function up (e, cursor) {
+ function up (e, cursor, new_cursor) {
+
+ new_cursor.x.div(map.zoom).add( map.center.a + map.bounds.a/2 )
+ new_cursor.y.div(map.zoom).add( -map.center.b - map.bounds.b/2 )
if (base.creating) {
if (cursor.height() != 0 && cursor.width() != 0) {
diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js
index a9d6936..3d512c3 100644
--- a/assets/javascripts/rectangles/models/room.js
+++ b/assets/javascripts/rectangles/models/room.js
@@ -17,6 +17,8 @@ window.room = (function(){
copy.id = this.id
copy.sides = FRONT | BACK | LEFT | RIGHT
this.regions = [ copy ]
+ this.intersects = []
+ this.constructed = false
}
room.prototype.clipTo = function(r){
diff --git a/assets/javascripts/rectangles/util/mouse.js b/assets/javascripts/rectangles/util/mouse.js
index b8d6045..8217a1d 100644
--- a/assets/javascripts/rectangles/util/mouse.js
+++ b/assets/javascripts/rectangles/util/mouse.js
@@ -12,7 +12,7 @@
// delta.a (x)
// delta.b (y)
},
- up: function(e, cursor){
+ up: function(e, cursor, new_cursor){
// cursor.x.a
// cursor.y.a
},
@@ -101,11 +101,14 @@ function mouse (opt) {
base.mouseup = function(e){
e.stopPropagation()
+ var pos, new_cursor
+
if (base.down) {
base.down = false
- base.tube("up", e, base.cursor)
- var pos = positionFromMouse(e)
- base.cursor = new rect(pos.a, pos.b)
+ pos = positionFromMouse(e)
+ new_cursor = new rect(pos.a, pos.b)
+ base.tube("up", e, base.cursor, new_cursor)
+ base.cursor = new_cursor
}
}
diff --git a/assets/javascripts/rectangles/util/sort.js b/assets/javascripts/rectangles/util/sort.js
index 673b3cc..e53a09c 100644
--- a/assets/javascripts/rectangles/util/sort.js
+++ b/assets/javascripts/rectangles/util/sort.js
@@ -32,6 +32,11 @@ function sort_rooms_by_id(list){
return a.id < b.id ? -1 : a.id == b.id ? 0 : 1
})
}
+function sort_rooms_by_height(list){
+ return list.sort(function(b,a){
+ return a.height < b.height ? -1 : a.height == b.height ? 0 : 1
+ })
+}
function sort_rooms_by_position(list){
return list.sort(function(a,b){
return compare_rect_position(a.rect, b.rect)