Skip to content

Instantly share code, notes, and snippets.

@morningtoast
Last active March 23, 2023 05:31
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morningtoast/f5d77c730cd9547ea6d4a7e5168c9a55 to your computer and use it in GitHub Desktop.
Save morningtoast/f5d77c730cd9547ea6d4a7e5168c9a55 to your computer and use it in GitHub Desktop.
Mouse input for PICO-8
--[[
Put mouse.init() in the _init()
Put the following in the _update loop
mouse_x,mouse_y = mouse.pos()
mouse_btn = mouse.button()
Then use mouse_* variables for position and button clicks.
]]
function _init()
mouse.init()
color=10
end
function _update()
mouse_x,mouse_y = mouse.pos()
mouse_btn = mouse.button()
if mouse_btn==1 then color=flr(rnd(15))+1 end
end
function _draw()
circfill(mouse_x,mouse_y, 3, color)
end
mouse = {
init = function()
poke(0x5f2d, 1)
end,
-- return int:x, int:y, onscreen:bool
pos = function()
local x,y = stat(32)-1,stat(33)-1
return stat(32)-1,stat(33)-1
end,
-- return int:button [0..4]
-- 0 .. no button
-- 1 .. left
-- 2 .. right
-- 4 .. middle
button = function()
return stat(34)
end,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment