summaryrefslogtreecommitdiff
path: root/test/05-test-mover.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/05-test-mover.js')
-rw-r--r--test/05-test-mover.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/05-test-mover.js b/test/05-test-mover.js
new file mode 100644
index 0000000..42c8653
--- /dev/null
+++ b/test/05-test-mover.js
@@ -0,0 +1,74 @@
+var assert = require("assert")
+var vec = require("../public/assets/javascripts/rectangles/models/vec2.js")
+var Rect = require("../public/assets/javascripts/rectangles/models/rect.js")
+var Room = require("../public/assets/javascripts/rectangles/models/room.js")
+var Rooms = require("../public/assets/javascripts/rectangles/engine/rooms/_rooms.js")
+var Clipper = require("../public/assets/javascripts/rectangles/engine/rooms/clipper.js")
+var Builder = require("../public/assets/javascripts/rectangles/engine/rooms/builder.js")
+var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20
+var ALL = FRONT | BACK | LEFT | RIGHT
+var NONE = 0x0
+function sidesToString(sides){
+ var s = ""
+ if (sides & FRONT) s += "front "
+ if (sides & BACK) s += "back "
+ if (sides & LEFT) s += "left "
+ if (sides & RIGHT) s += "right "
+ if (sides & TOP) s += "top "
+ if (sides & BOTTOM) s += "bottom "
+ return s
+}
+
+var radius = 1
+
+var rect = new Rect( new vec(1,5), new vec(1,5) )
+var east = new Rect( new vec(2,6), new vec(1,5) )
+var corner = new Rect( new vec(3,7), new vec(3,7) )
+var peninsula = new Rect( new vec(4,6), new vec(6,8) )
+
+var rect_room = new Room({ id: "rect", rect: rect, height: 2 })
+var east_room = new Room({ id: "east", rect: east, height: 2 })
+var corner_room = new Room({ id: "corner", rect: corner, height: 2 })
+var peninsula_room = new Room({ id: "peninsula", rect: peninsula, height: 2 })
+
+function reset(){
+ Rooms.forEach(function(room){
+ room.reset()
+ })
+ Rooms.list = {}
+ Rooms.regions = []
+}
+function rebuild(){
+ Rooms.clipper.reset_rects()
+ var regions = Rooms.clipper.clip_rects()
+ var culled = Rooms.clipper.cull_rects_iterative()
+ return culled
+}
+
+describe('mover', function(){
+ reset()
+ Rooms.add( rect_room )
+ rebuild()
+
+ describe('room#collidesDisc()', function(){
+ var room = rect_room
+ it("should not collide in the center", function(){
+ assert.equal(NONE, room.collidesDisc(3, 3, radius))
+ assert.equal(NONE, room.collidesDisc(2, 2, radius))
+ assert.equal(NONE, room.collidesDisc(4, 4, radius))
+ })
+ it("should collide on the sides", function(){
+ assert.equal(FRONT, room.collidesDisc(3, 1, radius))
+ assert.equal(BACK, room.collidesDisc(3, 5, radius))
+ assert.equal(LEFT, room.collidesDisc(1, 3, radius))
+ assert.equal(RIGHT, room.collidesDisc(5, 3, radius))
+ })
+ it("should collide in the corners", function(){
+ assert.equal(LEFT | FRONT, room.collidesDisc(1, 1, radius))
+ assert.equal(RIGHT | FRONT, room.collidesDisc(5, 1, radius))
+ assert.equal(LEFT | BACK, room.collidesDisc(1, 5, radius))
+ assert.equal(RIGHT | BACK, room.collidesDisc(5, 5, radius))
+ })
+ })
+})
+