--[[ physics things ]] package.path = "./spec/?.lua;" .. package.path _G.assert = assert local common = require("common") local spawn_1_box = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) GAME.exit() ]] local spawn_several_boxes = [[ GAME.crashy() for i = 1,100 do phys.newphysbox({8,8,8}, {0,10 * i,0}, 0) end GAME.exit() ]] describe("physics",function() it("should be able to spawn a physics box on the client",function() common.writegame(spawn_1_box) common.assert_game_runs() end) it("should be able to spawn several physics boxes on the client", function() common.writegame(spawn_several_boxes) common.assert_game_runs() end) end) local getpos_exists = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) local pos = box:getpos() for i = 1,3 do assert(pos[i] == 0, "Position is not 0") end GAME.exit() ]] local getpos_works = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {10,20,30}, 0) local pos = box:getpos() assert(pos[1] == 10) assert(pos[2] == 20) assert(pos[3] == 30) GAME.exit() ]] local setpos_exists = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {10,20,30}, 0) box:setpos({0,0,0}) local pos = box:getpos() for i = 1,3 do assert(pos[i] == 0) end GAME.exit() ]] local setpos_works = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {0,0,0}, 0) box:setpos({10,20,30}) local pos = box:getpos() assert(pos[1] == 10) assert(pos[2] == 20) assert(pos[3] == 30) GAME.exit() ]] local falls = [[ GAME.crashy() local box = phys.newphysbox({8,8,8}, {0,10,0}, 1) local ticks = 0 GAME.tick = function() print("Tick running...") if box:getpos()[2] < 0 then print("Getpos[2] is less, it is ", box:getpos()[2]) GAME.exit() end ticks = ticks + 1 assert(ticks < 1) end ]] describe("physics box", function() it("should have a .getpos() function",function() common.writegame(getpos_exists) common.assert_game_runs() end) it("should have a .getpos() function that returns the box's position",function() common.writegame(getpos_works) common.assert_game_runs() end) it("should have a .setpos() function",function() common.writegame(setpos_exists) common.assert_game_runs() end) it("should have a .setpos() function that sets the box's position",function() common.writegame(setpos_works) common.assert_game_runs() end) it("should fall when given mass",function() --print("About to write should fall when given mass...") common.writegame(falls) common.assert_game_runs() end) end)