grid picking in place
This commit is contained in:
parent
85c1add590
commit
2c593fa968
@ -1,6 +1,8 @@
|
||||
|
||||
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)
|
||||
@ -11,7 +13,15 @@ function init_event()
|
||||
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)
|
||||
@ -19,3 +29,23 @@ function key_down_event(k)
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user