pico8-0hh1/states/menu.lua

79 lines
1.7 KiB
Lua
Raw Normal View History

2022-06-02 20:18:02 +02:00
function state_menu()
2023-10-07 19:12:53 +02:00
local selected = 1
2022-06-01 21:26:57 +02:00
2023-10-07 19:12:53 +02:00
local buttons = {}
-- local buttons = {
-- make_button({x=10, y=10, w=30, text="pLAY", data={i=1},
-- on_click=function() set_state(states.loading) end,
-- on_hover=function(btn) selected=1 end,
-- }),
-- }
2023-02-22 20:39:24 +01:00
2023-10-07 19:12:53 +02:00
local game_sizes = {
{ "mINI bOARD - 4X4", 4 },
{ "sMALL bOARD - 6X6", 6 },
{ "mEDIUM bOARD - 8X8", 8 },
{ "lARGE bOARD - 10X10", 10 }
}
for k, item in ipairs(game_sizes) do
add(
buttons,
make_button({
x = 10, y = 10 + k * 10,
selected_color = 7,
text = item[1],
on_click = function() board_size = item[2] set_state(states.loading) end,
on_hover = function() selected = k end
})
)
end
2023-02-22 20:39:24 +01:00
2023-10-07 19:12:53 +02:00
local rulesId = #buttons + 1
add(
buttons,
make_button({
x = 10, y = 20 + (#game_sizes + 1) * 10, w = 30, text = "rULES",
color = 13, selected_color = 12,
on_click = function() set_state(states.rules) end,
on_hover = function() selected = rulesId end
})
)
2023-02-22 20:39:24 +01:00
2023-10-07 19:12:53 +02:00
local function _enter()
-- mouse not bound to buttons
poke(0x5F2D, 1)
end
2022-05-29 18:38:07 +02:00
2023-10-07 19:12:53 +02:00
local function _draw()
cls()
draw_bg_menu()
2022-05-29 19:49:59 +02:00
2023-10-07 19:12:53 +02:00
print("pLAY", 10, 8, 8)
2023-02-23 08:14:29 +01:00
2023-10-07 19:12:53 +02:00
for k, button in ipairs(buttons) do
button:draw(selected == k)
end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
end
2022-05-29 18:38:07 +02:00
2023-10-07 19:12:53 +02:00
return {
_enter = _enter,
2022-05-29 22:55:43 +02:00
2023-10-07 19:12:53 +02:00
_update = function()
for button in all(buttons) do
button:update()
end
2022-05-29 22:55:43 +02:00
2023-10-07 19:12:53 +02:00
if btnp(UP) then
selected -= 1
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_X) then
buttons[selected]:on_click()
end
selected = mid(1, selected, #buttons)
end,
2022-05-29 22:55:43 +02:00
2023-10-07 19:12:53 +02:00
_draw = _draw
}
2022-05-29 18:38:07 +02:00
end