Lasers
Draw lines / lasers.
Last updated
local function dist2d(x1, y1, x2, y2)
return ((x2-x1)^2+(y2-y1)^2)^0.5
end
local function angle_of_vector_between_two_points(x1,y1, x2,y2)
return math.atan2(y2-y1, x2-x1)
end
function init(self)
msg.post(".", "acquire_input_focus")
self.position = go.get_position()
self.target_position = go.get_position()
self.scale = go.get_scale()
go.animate(".", "scale.y", go.PLAYBACK_LOOP_PINGPONG, 1.5, go.EASING_INOUTSINE, 1.2 + math.random(30) * 0.01)
end
function update(self, dt)
local distance = dist2d(self.position.x, self.position.y, self.target_position.x, self.target_position.y)
self.scale.x = distance
go.set_scale(self.scale)
local direction = angle_of_vector_between_two_points(self.position.x, self.position.y, self.target_position.x, self.target_position.y)
local rotation = vmath.quat_rotation_z(direction)
go.set_rotation(rotation)
end
function on_input(self, action_id, action)
if action.x ~= nil then
self.target_position.x = action.x
self.target_position.y = action.y
end
end