Last active
March 23, 2023 05:31
-
-
Save morningtoast/f5d77c730cd9547ea6d4a7e5168c9a55 to your computer and use it in GitHub Desktop.
Mouse input for PICO-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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