summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models/room.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/models/room.js')
-rw-r--r--assets/javascripts/rectangles/models/room.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js
index 3d512c3..c760174 100644
--- a/assets/javascripts/rectangles/models/room.js
+++ b/assets/javascripts/rectangles/models/room.js
@@ -6,6 +6,9 @@ window.room = (function(){
this.regions = []
this.height = opt.height || 200
this.focused = false
+ this.$walls = $([])
+ this.$floor = $([])
+ this.$ceiling = $([])
}
room.prototype.toString = function(){
@@ -19,6 +22,9 @@ window.room = (function(){
this.regions = [ copy ]
this.intersects = []
this.constructed = false
+ this.$walls = $([])
+ this.$floor = $([])
+ this.$ceiling = $([])
}
room.prototype.clipTo = function(r){
@@ -34,7 +40,35 @@ window.room = (function(){
}
this.regions = regions
}
+
+ room.prototype.collides = function(x,y){
+ var collision = 0
+ this.regions.forEach(function(r){
+ if (! r.sides) return
+
+ if ((r.sides & FRONT) && y < r.y.a && r.x.contains(x)) {
+ collision |= FRONT
+ }
+ if ((r.sides & BACK) && r.y.b < y && r.x.contains(x)) {
+ collision |= BACK
+ }
+ if ((r.sides & LEFT) && x < r.x.a && r.y.contains(y)) {
+ collision |= LEFT
+ }
+ if ((r.sides & RIGHT) && r.x.b < x && r.y.contains(y)) {
+ collision |= RIGHT
+ }
+ })
+ return collision
+ }
return room
})()
+
+function bitcount(v) {
+ v = v - ((v >>> 1) & 0x55555555);
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
+ return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24;
+}
+