summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/rectangles')
-rw-r--r--public/assets/javascripts/rectangles/engine/rooms/mover.js38
-rw-r--r--public/assets/javascripts/rectangles/models/room.js6
2 files changed, 39 insertions, 5 deletions
diff --git a/public/assets/javascripts/rectangles/engine/rooms/mover.js b/public/assets/javascripts/rectangles/engine/rooms/mover.js
index fae2ce6..121ecec 100644
--- a/public/assets/javascripts/rectangles/engine/rooms/mover.js
+++ b/public/assets/javascripts/rectangles/engine/rooms/mover.js
@@ -34,7 +34,43 @@ Rooms.mover = new function(){
}
// check if we've breached one of the walls.. clamp position if so
- var collision = base.room.collidesDisc(pos.x, pos.z, radius)
+ var collision = base.room.collidesDisc(cam, pos, radius)
+
+/*
+ var dz = new vec2( cam.z, pos.z )
+ dz.normalize()
+
+ var dx = new vec2( cam.x, pos.x )
+ dx.normalize()
+
+ Walls.list.forEach(function(wall){
+ switch (wall.side) {
+ case FRONT:
+ break
+ case BACK:
+ break
+ case LEFT:
+ if (cam.x >= wall.edge + radius && wall.edge + radius >= pos.x && (wall.vec.intersects(dz) ) {
+ // intersects the wall.. next check if it intersects any of the surface frames
+ wall.surface.faces.some(function(face, i){
+ // if we can pass through the wall at this point, we do not need to clamp
+ if (face.y.a === 0 && face.x.intersects(dz)) {
+ dz.a = pos.z = face.x.clamp(pos.z)
+ dz.b = cam.z
+ dz.normalize()
+ return true
+ }
+ })
+ }
+ break
+ case RIGHT:
+ if (cam.x <= wall.edge - radius && wall.edge - radius <= pos.x && (wall.vec.contains(cam.z) || wall.vec.contains(pos.z)) ) {
+ // intersects
+ }
+ break
+ }
+ })
+*/
if (collision && ! base.noclip) {
cam.x = (collision & LEFT_RIGHT) ? base.room.rect.x.clampDisc(pos.x, radius) : pos.x
diff --git a/public/assets/javascripts/rectangles/models/room.js b/public/assets/javascripts/rectangles/models/room.js
index b0344a1..26bf055 100644
--- a/public/assets/javascripts/rectangles/models/room.js
+++ b/public/assets/javascripts/rectangles/models/room.js
@@ -122,7 +122,8 @@
return collision
}
- Room.prototype.collidesDisc = function(x,y,radius){
+ Room.prototype.collidesDisc = function(src, dest, radius){
+ var x = dest.x, y = dest.z
var collision = 0, wall_collision, contains_x, contains_y
this.regions.forEach(function(r){
if (! r.sides) return
@@ -152,9 +153,6 @@
if (contains_y) {
collision |= wall_collision & LEFT_RIGHT
}
-// if (bitcount(wall_collision) > 1) {
-// collision |= wall_collision
-// }
})
return collision
}