Rocket-Bytes/Source/Menu.lua

47 lines
1.1 KiB
Lua
Raw Normal View History

2022-04-22 18:48:45 +00:00
local gfx <const> = playdate.graphics
local controlY = 0
local controlX = 0
2022-04-22 18:48:45 +00:00
local index = 0
local menuitems = {}
local menu = null
local imgCursor = gfx.image.new("gfx/cursor")
assert(imgCursor)
function createMenu(items)
controlX = -80
index = 0
menuitems = {}
local _y =220
menu = items[0]
for i=1, #items, 1 do
menuitems[i] = {name=items[i],y=_y}
_y -= 20
end
end
2022-04-22 18:48:45 +00:00
function updateMenu()
gfx.clear(gfx.kColorBlack)
-- input
local change, aChange = playdate.getCrankChange()
if playdate.buttonJustPressed(playdate.kButtonUp) or change < -10 then
index -= 1
elseif playdate.buttonJustPressed(playdate.kButtonDown) or change > 10 then
index += 1
2022-04-22 18:48:45 +00:00
end
if index < 0 then index = #menuitems -1 end
if index > #menuitems - 1 then index = 0 end
controlX = playdate.math.lerp(controlX, 20, 0.3)
controlY = playdate.math.lerp(controlY, (20 * index) - 1, 0.5)
print(index)
imgCursor:draw(3,controlY + (243 - (20 * #menuitems)))
for i = 1, #menuitems, 1 do
local item = menuitems[i]
gfx.drawText(item.name,controlX,item.y)
end
2022-04-22 18:48:45 +00:00
end