From 812af7cc927c2d3f89aea380756eb6bff6863a5d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 20 Oct 2009 23:48:36 +0000 Subject: [PATCH] added "cannon" example (spacebar to "shoot" a "checkerball" model) git-svn-id: svn://anubis/anaglym/trunk@118 99a6e188-d820-4881-8870-2d33a10e2619 --- tests/cannon.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/cannon.lua diff --git a/tests/cannon.lua b/tests/cannon.lua new file mode 100644 index 0000000..1c48357 --- /dev/null +++ b/tests/cannon.lua @@ -0,0 +1,29 @@ + +levels = 6 +crate = ag.loadModel("crate", 0.5) +offset = 0.5 +crate:setPosition(0, 0, offset + levels + 0.5) +for level = 2, levels do + for x = 1, level do + local c = crate:clone() + c:setPosition(x - 0.5 - level/2, + 0, offset + levels - level + 1.5) + end +end + +ground = ag.loadStaticModel("crate", 10) +ground:setPosition(0, 0, -10) +ag.setCamera(levels/2, -2*levels, levels, 0, 0, levels/2, 0, 0, 1) +camx, camy, camz, cx, cy, cz = ag.getCamera() + +ball = ag.loadModel("checkerball") +ball:setPosition(2*camx - cx, 2*camy - cy, 2*camz - cz) + +function key_down_event(key) + if (key == "space") then + local newball = ball:clone() + newball:setPosition(camx, camy, camz) + force = 10000 + newball:addForce(force * (cx-camx), force * (cy-camy), force * (cz-camz)) + end +end