41 lines
1.0 KiB
Lua
41 lines
1.0 KiB
Lua
-- manage clicks, since tic-80 only returns a "pressed" state
|
|
|
|
Input = {
|
|
--- @type boolean
|
|
lclick_prev_state = false,
|
|
--- @type 'none'|'pressed'|'released'
|
|
lclick_state = "none"
|
|
}
|
|
|
|
function Input.update_mouse(self)
|
|
local x, y, left = mouse()
|
|
-- left btn down
|
|
if left then
|
|
-- was not pressed before
|
|
if not self.lclick_prev_state then
|
|
self.lclick_state = "pressed"
|
|
self.lclick_prev_state = true
|
|
|
|
-- was already pressed
|
|
elseif self.lclick_prev_state then
|
|
self.lclick_state = "none"
|
|
end
|
|
-- left btn up
|
|
elseif not left then
|
|
if self.lclick_prev_state then
|
|
self.lclick_state = "released"
|
|
self.lclick_prev_state = false
|
|
elseif not self.lclick_prev_state then
|
|
self.lclick_state = "none"
|
|
end
|
|
end
|
|
end
|
|
|
|
function Input.mouse_pressed(self)
|
|
return self.lclick_state == "pressed"
|
|
end
|
|
|
|
function Input.mouse_released(self)
|
|
return self.lclick_state == "released"
|
|
end
|