2022-04-22 18:48:45 +00:00
|
|
|
local gfx <const> = playdate.graphics
|
|
|
|
local controlY = 0
|
2022-04-23 05:50:57 +00:00
|
|
|
local controlX = 0
|
2022-04-22 18:48:45 +00:00
|
|
|
|
2022-04-23 05:50:57 +00:00
|
|
|
local index = 0
|
|
|
|
|
|
|
|
local menuitems = {}
|
|
|
|
local menu = null
|
|
|
|
|
|
|
|
local imgCursor = gfx.image.new("gfx/cursor")
|
2022-04-23 21:48:23 +00:00
|
|
|
local imgBytes = gfx.image.new("gfx/bytes")
|
2022-04-23 05:50:57 +00:00
|
|
|
assert(imgCursor)
|
2022-04-23 21:48:23 +00:00
|
|
|
assert(imgBytes)
|
|
|
|
|
|
|
|
mainmenu = {}
|
|
|
|
function mainMenuCreation()
|
|
|
|
mainmenu = {}
|
|
|
|
if playdate.datastore.read("savegame") then
|
|
|
|
map = playdate.datastore.read("savegame").level
|
|
|
|
mainmenu[4],mainmenu[3],mainmenu[2],mainmenu[1], mainmenu[0] = "CONTINUE", "START NEW GAME", "USER LEVELS", "ABOUT THE CREATOR", "mainPlay"
|
|
|
|
else
|
|
|
|
mainmenu[3],mainmenu[2],mainmenu[1], mainmenu[0] = "START NEW GAME", "USER LEVELS", "ABOUT THE CREATOR", "mainNoPlay"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mainMenuCreation()
|
2022-04-23 05:50:57 +00:00
|
|
|
|
|
|
|
function createMenu(items)
|
2022-04-23 06:54:45 +00:00
|
|
|
killPlayer()
|
|
|
|
mode = "menu"
|
2022-04-23 05:50:57 +00:00
|
|
|
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
|
2022-04-23 05:50:57 +00:00
|
|
|
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
|
|
|
|
|
2022-04-23 05:50:57 +00:00
|
|
|
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)
|
|
|
|
for i = 1, #menuitems, 1 do
|
|
|
|
local item = menuitems[i]
|
|
|
|
gfx.drawText(item.name,controlX,item.y)
|
|
|
|
end
|
2022-04-23 21:48:23 +00:00
|
|
|
imgCursor:draw(controlX - 17,controlY + (243 - (20 * #menuitems)))
|
|
|
|
|
|
|
|
if playdate.buttonJustPressed(playdate.kButtonA) then
|
|
|
|
menuButtonPress(menuitems[#menuitems - index].name)
|
|
|
|
end
|
|
|
|
|
|
|
|
imgBytes:draw(0,0)
|
|
|
|
end
|
|
|
|
|
|
|
|
function menuButtonPress(name)
|
|
|
|
if name == "START NEW GAME" and menu == "mainPlay" then
|
|
|
|
local m = {}
|
|
|
|
m[0], m[1], m[2] = "newgame", "CANCEL", "CONFIRM"
|
|
|
|
createMenu(m)
|
|
|
|
|
|
|
|
elseif name == "START NEW GAME" or name == "CONFIRM" then
|
|
|
|
addMapSave("levels/level1.json")
|
|
|
|
|
|
|
|
elseif name == "CONTINUE" then
|
|
|
|
addMap(map)
|
|
|
|
|
|
|
|
elseif name == "ABOUT THE CREATOR" then
|
|
|
|
local m = {}
|
|
|
|
m[0],m[1] = "about", "BACK"
|
|
|
|
createMenu(m)
|
|
|
|
|
|
|
|
elseif name == "BACK" or name == "CANCEL" then
|
|
|
|
createMenu(mainmenu)
|
|
|
|
end
|
|
|
|
end
|