pico8-0hh1/states/menu.lua

51 lines
1023 B
Lua
Raw Normal View History

2022-05-29 18:38:07 +02:00
function stateMenu()
2022-05-29 19:49:59 +02:00
local selected = 1
2022-06-01 21:26:57 +02:00
function onBtnDraw(btn)
if selected == btn.data.i then
btn.color = 7
end
end
2022-05-29 19:49:59 +02:00
local buttons = {
2022-06-01 21:26:57 +02:00
makeButton({x=10, y=10, w=30, text="play", data={i=1},
onClick=function() setState(states.game) end,
onHover=function(btn) btn.color = 7 selected = 1 end,
onDraw=onBtnDraw}),
makeButton({x=10, y=20, w=30, text="rules", data={i=2},
onClick=function() setState(states.rules) end,
onHover=function(btn) btn.color = 7 selected = 2 end,
onDraw=onBtnDraw})
2022-05-29 19:49:59 +02:00
}
2022-05-29 18:38:07 +02:00
function _enter()
2022-05-29 19:49:59 +02:00
2022-05-29 18:38:07 +02:00
end
return {
_enter = _enter,
2022-05-29 22:55:43 +02:00
2022-05-29 18:38:07 +02:00
_update = function()
for button in all(buttons) do
button:update()
end
2022-05-29 22:55:43 +02:00
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)
2022-05-29 18:38:07 +02:00
end,
_draw = function()
2022-05-29 19:49:59 +02:00
for k,button in ipairs(buttons) do
button:draw(selected == k)
2022-05-29 18:38:07 +02:00
end
2022-05-29 22:55:43 +02:00
print("press 🅾️/c to continue", 8, 120, 7)
2022-05-29 18:38:07 +02:00
end
}
end