pico8-0hh1/states/menu.lua

43 lines
784 B
Lua

function stateMenu()
local selected = 1
local buttons = {
makeButton(10, 10, 30, 6, "play",
function() setState(states.game) end,
function() selected = 1 end),
makeButton(10, 20, 30, 6, "rules",
function() setState(states.rules) end,
function() selected = 2 end)
}
function _enter()
end
return {
_enter = _enter,
_update = function()
for button in all(buttons) do
button:update()
end
if btnp(UP) then
selected -= 1
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_O) then
buttons[selected]:onClick()
end
selected = mid(1, selected, #buttons)
end,
_draw = function()
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("press 🅾️/c to continue", 8, 120, 7)
end
}
end