anaglymtd/anaglymtd.lua
2010-11-18 08:54:29 -05:00

52 lines
1.2 KiB
Lua

ag.import("std")
td = {mx = 0, my = 0, picking = false}
function init_event()
ground = std.createPlanePointNormal(0, 0, 0, 0, 0, 1)
ground:setColor(0, 1, 0)
grid_texture = ag.loadTexture("grid.png")
grid = ag.createQuad(0, 0, 0, 8, 0, 0, 0, 8, 0)
grid:setTexture(grid_texture)
grid:setOffset(1)
grid_selector = ag.createQuad(0, 0, 0, 0.5, 0, 0, 0, 0.5, 0)
grid_selector:setVisible(false)
grid_selector:setColor(0, 0, 1, 0.5)
grid_selector:setBlending(true)
grid_selector:setOffset(2)
ag.setCamera(2, -12, 10)
ag.setCursorVisible(true)
end
function key_down_event(k)
if (k == "q") then
ag.exit()
end
end
function update_event()
hit = ag.pickOne(td.mx, td.my, ground)
if (hit) then
local px = ground.pick_pos[1]
local py = ground.pick_pos[2]
local x_coord = math.floor(px + 8)
local y_coord = math.floor(py + 8)
td.picking = (x_coord >= 0 and x_coord <= 15 and y_coord >= 0 and y_coord <= 15)
if (td.picking) then
grid_selector:setPosition(x_coord - 7.5, y_coord - 7.5, 0)
end
end
grid_selector:setVisible(td.picking)
end
function mouse_motion_event(x, y)
td.mx = x
td.my = y
end