diff options
| -rw-r--r-- | assets/javascripts/mx/extensions/mx.movements.js | 12 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/_env.js | 2 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/engine/mover.js | 5 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/rect.js | 2 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/room.js | 37 |
5 files changed, 49 insertions, 9 deletions
diff --git a/assets/javascripts/mx/extensions/mx.movements.js b/assets/javascripts/mx/extensions/mx.movements.js index df3d79c..4f39f66 100644 --- a/assets/javascripts/mx/extensions/mx.movements.js +++ b/assets/javascripts/mx/extensions/mx.movements.js @@ -19,8 +19,8 @@ MX.Movements = function (cam, viewHeight) { rotationX_min = PI/-2, rotationX_max = PI/2 - var v = 10, - vr = Math.PI * 0.015, + var v = 12, + vr = Math.PI * 0.012, jumpV = 23, vx = vy = vz = 0, creepFactor = 0.3 @@ -204,7 +204,7 @@ MX.Movements = function (cam, viewHeight) { if (moveForward || moveBackward || moveRight || moveLeft || moveUp || moveDown || turnLeft || turnRight || turnUp || turnDown) { - vx = vy = vz = 0 + vx = vy = vz = 0 if (moveForward) { vx += v * Math.cos(ry + Math.PI / 2) * s @@ -257,9 +257,9 @@ MX.Movements = function (cam, viewHeight) { cam.y += vy if (cam.y <= viewHeight * scale) { - cam.y = viewHeight * scale - vy = 0 - jumping = false + cam.y = viewHeight * scale + vy = 0 + jumping = false } } diff --git a/assets/javascripts/rectangles/_env.js b/assets/javascripts/rectangles/_env.js index d41d490..9bdad6a 100644 --- a/assets/javascripts/rectangles/_env.js +++ b/assets/javascripts/rectangles/_env.js @@ -10,7 +10,7 @@ environment.init = function(){ "rotationY": PI/2, // PI }) - scene.camera.radius = 25 + scene.camera.radius = 20 } map.center.a = scene.camera.x diff --git a/assets/javascripts/rectangles/engine/mover.js b/assets/javascripts/rectangles/engine/mover.js index 66c1813..71656ef 100644 --- a/assets/javascripts/rectangles/engine/mover.js +++ b/assets/javascripts/rectangles/engine/mover.js @@ -28,12 +28,15 @@ var mover = new function(){ } // check if we've breached one of the walls.. clamp position if so - var collision = base.room.collides(pos.x, pos.z, radius) + var collision = base.room.collidesDisc(pos.x, pos.z, radius) if (collision) { if (! (collision & LEFT_RIGHT)) { cam.x = base.room.rect.x.clampDisc(pos.x, radius) } + else { + // cam.x = base.room.rect.x.clampDisc(pos.x, radius) + } if (! (collision & FRONT_BACK)) { cam.z = base.room.rect.y.clampDisc(pos.z, radius) } diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js index 51162c0..0664693 100644 --- a/assets/javascripts/rectangles/models/rect.js +++ b/assets/javascripts/rectangles/models/rect.js @@ -59,7 +59,7 @@ window.rect = (function(){ return this.x.contains(x) && this.y.contains(y) } rect.prototype.containsDisc = function(x,y,r){ - return this.x.contains(x,r) && this.y.contains(y,r) + return this.x.containsDisc(x,r) && this.y.containsDisc(y,r) } rect.prototype.intersects = function(r){ return this.x.intersects(r.x) && this.y.intersects(r.y) diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js index f0ebc76..b66d868 100644 --- a/assets/javascripts/rectangles/models/room.js +++ b/assets/javascripts/rectangles/models/room.js @@ -94,6 +94,43 @@ window.room = (function(){ return collision } + room.prototype.collidesDisc = function(x,y,radius){ + var collision = 0, wall_collision, contains_x, contains_y + this.regions.forEach(function(r){ + if (! r.sides) return + + wall_collision = 0 + + if ((r.sides & FRONT) && y-radius < r.y.a) { + wall_collision |= FRONT + } + if ((r.sides & BACK) && r.y.b < y+radius) { + wall_collision |= BACK + } + if ((r.sides & LEFT) && x-radius < r.x.a) { + wall_collision |= LEFT + } + if ((r.sides & RIGHT) && r.x.b < x+radius) { + wall_collision |= RIGHT + } + if (! wall_collision) return + + contains_x = r.x.contains(x, radius) + contains_y = r.y.contains(y, radius) + + if (contains_x) { + collision |= wall_collision & FRONT_BACK + } + else if (contains_y) { + collision |= wall_collision & LEFT_RIGHT + } + else if (bitcount(wall_collision) > 1) { + collision |= wall_collision + } + }) + return collision + } + return room })() |
