click to spawn sphere on pick point
This commit is contained in:
parent
2c593fa968
commit
206518b337
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
ag.import("std")
|
ag.import("std")
|
||||||
|
|
||||||
td = {mx = 0, my = 0, picking = false}
|
td = {mx = 0, my = 0, picking = false, pick_x = 0, pick_y = 0}
|
||||||
|
|
||||||
function init_event()
|
function init_event()
|
||||||
ground = std.createPlanePointNormal(0, 0, 0, 0, 0, 1)
|
ground = std.createPlanePointNormal(0, 0, 0, 0, 0, 1)
|
||||||
@ -40,6 +40,8 @@ function update_event()
|
|||||||
td.picking = (x_coord >= 0 and x_coord <= 15 and y_coord >= 0 and y_coord <= 15)
|
td.picking = (x_coord >= 0 and x_coord <= 15 and y_coord >= 0 and y_coord <= 15)
|
||||||
if (td.picking) then
|
if (td.picking) then
|
||||||
grid_selector:setPosition(x_coord - 7.5, y_coord - 7.5, 0)
|
grid_selector:setPosition(x_coord - 7.5, y_coord - 7.5, 0)
|
||||||
|
td.pick_x = x_coord
|
||||||
|
td.pick_y = y_coord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
grid_selector:setVisible(td.picking)
|
grid_selector:setVisible(td.picking)
|
||||||
@ -49,3 +51,13 @@ function mouse_motion_event(x, y)
|
|||||||
td.mx = x
|
td.mx = x
|
||||||
td.my = y
|
td.my = y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mousebutton_down_event(button, x, y)
|
||||||
|
if (button == 1) then
|
||||||
|
if td.picking then
|
||||||
|
local s = ag.createSphere(0.48)
|
||||||
|
s:setColor(math.random(), math.random(), math.random())
|
||||||
|
s:setPosition(td.pick_x - 7.5, td.pick_y - 7.5, 0.6)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user