Last active
December 11, 2018 15:33
-
-
Save RicoP/81702becf95eb331abf1aef24b87f0c7 to your computer and use it in GitHub Desktop.
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
-- helper function for buttons state | |
-- call btn_update ONCE per update | |
-- btnd returns true once the button is pressed down | |
-- btnu returns true when the button is released | |
do | |
local state = {0,0,0,0,0,0} | |
-- call this in _update! | |
btn_update=function () | |
for b=0,6 do | |
if state[b] == 0 and btn(b) then | |
state[b] = 1 | |
elseif state[b] == 1 then | |
state[b] = 2 | |
elseif state[b] == 2 and not btn(b) then | |
state[b] = 3 | |
elseif state[b] == 3 then | |
state[b] = 0 | |
end | |
end | |
end | |
btnd=function (b) | |
return state[b] == 1 | |
end | |
btnu=function (b) | |
return state[b] == 3 | |
end | |
end | |
-- don't forget! | |
-- function _update() | |
-- btn_update() | |
-- end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment