1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
--[[
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)
|