anaglym/tests/cratestack.lua
Josh Holtrop d4d44dea86 added AV::Sound::pause(), added Lua interface for sounds (play/pause/stop/loop/loopForever)
git-svn-id: svn://anubis/anaglym/trunk@290 99a6e188-d820-4881-8870-2d33a10e2619
2010-06-24 02:46:28 +00:00

69 lines
1.7 KiB
Lua

function init_event()
crates = {}
levels = 5
local crate = ag.loadModel("crate", {scale=0.5})
crates[1] = crate
offset = 0.5
crate:setPosition(0, 0, offset + levels + 0.5)
cratenum = 1
for level = 2, levels do
for x = 1, level do
local c = crate:clone()
c:setPosition((x - 1) * 1.5 - (level * 1.5 - 0.5)/2 + 0.5,
0, offset + levels - level + 1.5)
cratenum = cratenum + 1
crates[cratenum] = c
end
end
ground = ag.loadModel("crate", {static = true, scale = 10})
ground:setPosition(0, 0, -10)
ag.setCamera(2, -12, 8, 0, 0, 2, 0, 0, 1)
iris = ag.loadSound("iris.mp3")
end
function key_down_event(key)
if (key == "d") then
if (cratenum >= 1) then
local idx = math.random(cratenum)
crates[idx]:destroy()
for i = idx, cratenum - 1 do
crates[i] = crates[i + 1]
end
crates[cratenum] = nil
cratenum = cratenum - 1
end
elseif (key == "m") then
ag.registerEventHandler(mouse_moves, "mouse_motion")
elseif (key == "n") then
ag.clearEventHandler("mouse_motion")
elseif (key == "p") then
if (playing) then
iris:pause()
playing = false
else
iris:play()
playing = true
end
end
end
function mouse_moves(x, y, xrel, yrel)
ag.println("mouse_moves ", x, ", ", y)
end
function update_overlay_event()
y = 4
size = 16
for i = 0, 17 do
local message = "Hello there"
local width, height = ag.getTextSize(message, size)
ag.drawText(message, 1, 0.7, 0, size, 2, y)
y = y + height + 4
size = size + 4
end
end