Skip to content

Instantly share code, notes, and snippets.

@microloop
Created December 14, 2025 14:22
Show Gist options
  • Select an option

  • Save microloop/a4da0d0a442e016707796adc897870f0 to your computer and use it in GitHub Desktop.

Select an option

Save microloop/a4da0d0a442e016707796adc897870f0 to your computer and use it in GitHub Desktop.
Mouse Handler Object (PICO-8, Lua)
Mouse = {}
function Mouse:new(o)
o = o or {}
o.posx = o.posx or 10
o.posy = o.posy or 20
o.mapx = flr(o.posx / 8)
o.mapy = flr(o.posy / 8)
o.busy_hand = false
o.sprite = 8
o.sprite_pressed = 9
o.btnpressed = 0
o.mouseover = 0
o.grabbed_item = 0
o.reload = function () end
o.modes = {
pointer = function(mouse) mouse:pointer() end,
ground = function(mouse) mouse:ground() end,
rubber = function(mouse) mouse:rubber() end
}
o.drawing = {
pointer = function(mouse) mouse:pointer_draw() end,
ground = function(mouse) mouse:ground_draw() end,
rubber = function(mouse) mouse:rubber_draw() end
}
o.current_draw = o.drawing.pointer
o.previous_mode = o.modes.pointer
o.current_mode = o.modes.pointer
o.animation_player = nil
o.last_click_x = 0
o.last_click_y = 0
setmetatable(o, {__index = self})
return o
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment