pico8-0hh1/states/menu.lua

73 lines
1.4 KiB
Lua

function state_menu()
local selected = 1
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,
}),
}
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, w=200,
text=item[1], data={i=2},
on_click=function() board_size=item[2] set_state(states.loading) end,
on_hover=function(btn) selected=k+1 end,
})
)
end
local rulesId = #buttons+1
add(buttons,
make_button({x=10, y=10+(#game_sizes+1)*10, w=30, text="rULES", data={i=2},
on_click=function() set_state(states.rules) end,
on_hover=function(btn) selected=rulesId end,
})
)
local function _enter()
-- mouse not bound to buttons
poke(0x5F2D, 1)
end
local function _draw()
cls()
draw_bg_menu()
-- printh(selected)
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
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_X) then
buttons[selected]:on_click()
end
selected = mid(1, selected, #buttons)
end,
_draw = _draw
}
end