add phys.apply

This commit is contained in:
Donald Ball 2025-11-16 22:51:51 -05:00
parent fddb06ed8b
commit 9cdf032c39
4 changed files with 3880 additions and 0 deletions

33
asteroids/test_phys.lua Normal file
View file

@ -0,0 +1,33 @@
t = require('luaunit')
local phys = require('phys')
function TestUpdate()
local actor = { x = 0, y = 0, speed = 1, angle = math.pi }
phys.update(actor, 0.1)
t.assertAlmostEquals(
actor,
{ x = -0.1, y = 0, speed = 1, angle = math.pi })
end
function TestApply()
local actor = { x = 0, y = 0, speed = 1, angle = math.pi }
phys.apply(actor, { speed = 1, angle = 0 })
t.assertAlmostEquals(
{ x = actor.x, y = actor.y, speed = actor.speed },
{ x = 0, y = 0, speed = 0 })
phys.apply(actor, { speed = 1, angle = math.pi })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = 1, angle = math.pi }
)
phys.apply(actor, { speed = 1, angle = math.pi / 2 })
t.assertAlmostEquals(
actor,
{ x = 0, y = 0, speed = math.sqrt(2), angle = math.pi * 3 / 4 }
)
end
os.exit(t.LuaUnit.run())