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-05-09 04:31:57 +00:00
|
|
|
local sidebar <const> = gfx.image.new("gfx/sidebar")
|
|
|
|
local barpos = 0
|
|
|
|
local barposLerp = 160
|
|
|
|
|
|
|
|
local logopos = 0
|
|
|
|
local logposLerp = -122
|
|
|
|
|
2022-04-23 05:50:57 +00:00
|
|
|
local index = 0
|
|
|
|
|
|
|
|
local menuitems = {}
|
|
|
|
local menu = null
|
2022-04-27 02:40:39 +00:00
|
|
|
page = 0
|
2022-04-23 05:50:57 +00:00
|
|
|
|
|
|
|
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()
|
2022-05-12 22:04:00 +00:00
|
|
|
barposLerp = 160
|
|
|
|
logposLerp = -122
|
2022-04-23 21:48:23 +00:00
|
|
|
mainmenu = {}
|
2022-04-24 18:47:37 +00:00
|
|
|
mainmenu[4],mainmenu[3],mainmenu[2], mainmenu[1], mainmenu[0] = "START NEW GAME", "USER LEVELS", "LEVEL EDITOR", "ABOUT THE CREATOR", "mainNoPlay"
|
2022-04-23 23:54:00 +00:00
|
|
|
|
|
|
|
if playdate.datastore.read("savegame") then
|
|
|
|
map = playdate.datastore.read("savegame").savedLevel
|
2022-05-07 20:31:34 +00:00
|
|
|
deaths = playdate.datastore.read("savegame").savedDeaths
|
2022-04-24 18:47:37 +00:00
|
|
|
mainmenu[5], mainmenu[0] = "CONTINUE", "mainPlay"
|
2022-04-23 23:54:00 +00:00
|
|
|
end
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
|
|
|
|
2022-04-23 05:50:57 +00:00
|
|
|
function createMenu(items)
|
2022-04-24 05:03:32 +00:00
|
|
|
killBlades()
|
2022-04-23 06:54:45 +00:00
|
|
|
killPlayer()
|
2022-05-09 04:31:57 +00:00
|
|
|
|
|
|
|
controlX = -80
|
|
|
|
|
|
|
|
index = 0
|
2022-04-23 05:50:57 +00:00
|
|
|
menuitems = {}
|
|
|
|
local _y =220
|
|
|
|
menu = items[0]
|
|
|
|
for i=1, #items, 1 do
|
|
|
|
menuitems[i] = {name=items[i],y=_y}
|
|
|
|
_y -= 20
|
|
|
|
end
|
2022-04-27 02:40:39 +00:00
|
|
|
|
2022-05-09 04:31:57 +00:00
|
|
|
if mode == "game" or mode == "play" then
|
2022-04-27 02:40:39 +00:00
|
|
|
song:stop()
|
|
|
|
song:load("sfx/song1")
|
|
|
|
song:play(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
mode = "menu"
|
2022-04-23 05:50:57 +00:00
|
|
|
end
|
2022-04-22 18:48:45 +00:00
|
|
|
|
|
|
|
function updateMenu()
|
|
|
|
gfx.clear(gfx.kColorBlack)
|
2022-05-09 04:31:57 +00:00
|
|
|
sidebar:draw(barposLerp,0)
|
2022-04-22 18:48:45 +00:00
|
|
|
-- input
|
2022-04-23 05:50:57 +00:00
|
|
|
local change, aChange = playdate.getCrankChange()
|
|
|
|
|
2022-04-24 18:47:37 +00:00
|
|
|
if playdate.buttonJustPressed(playdate.kButtonUp) then
|
2022-04-23 05:50:57 +00:00
|
|
|
index -= 1
|
2022-04-24 18:47:37 +00:00
|
|
|
elseif playdate.buttonJustPressed(playdate.kButtonDown) then
|
2022-04-23 05:50:57 +00:00
|
|
|
index += 1
|
2022-04-22 18:48:45 +00:00
|
|
|
end
|
|
|
|
|
2022-04-24 18:47:37 +00:00
|
|
|
index += change * 0.01
|
|
|
|
|
|
|
|
if math.floor(index) < 0 then index = #menuitems -0.01 end
|
|
|
|
if math.floor(index) > #menuitems - 1 then index = 0 end
|
2022-04-23 05:50:57 +00:00
|
|
|
|
|
|
|
controlX = playdate.math.lerp(controlX, 20, 0.3)
|
2022-04-24 18:47:37 +00:00
|
|
|
controlY = playdate.math.lerp(controlY, (20 * math.floor(index)) - 1, 0.5)
|
2022-05-09 04:31:57 +00:00
|
|
|
|
|
|
|
barposLerp = playdate.math.lerp(barposLerp, barpos, 0.2)
|
|
|
|
logposLerp = playdate.math.lerp(logposLerp, logopos, 0.3)
|
2022-04-23 05:50:57 +00:00
|
|
|
for i = 1, #menuitems, 1 do
|
|
|
|
local item = menuitems[i]
|
2022-05-09 04:31:57 +00:00
|
|
|
if item.name:match("(.+)%..+$") then
|
|
|
|
gfx.drawText(item.name:match("(.+)%..+$"),controlX,item.y)
|
|
|
|
else
|
|
|
|
gfx.drawText(item.name,controlX,item.y)
|
|
|
|
end
|
2022-04-23 05:50:57 +00:00
|
|
|
end
|
2022-04-23 21:48:23 +00:00
|
|
|
imgCursor:draw(controlX - 17,controlY + (243 - (20 * #menuitems)))
|
|
|
|
|
2022-04-24 19:17:55 +00:00
|
|
|
if playdate.buttonJustPressed(playdate.kButtonA) or playdate.buttonJustPressed(playdate.kButtonRight) then
|
2022-04-24 18:47:37 +00:00
|
|
|
menuButtonPress(menuitems[#menuitems - math.floor(index)].name)
|
2022-04-27 02:40:39 +00:00
|
|
|
elseif playdate.buttonJustPressed(playdate.kButtonB) or playdate.buttonJustPressed(playdate.kButtonLeft) then
|
|
|
|
menuButtonPress("BACK")
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
|
|
|
|
2022-05-09 04:31:57 +00:00
|
|
|
imgBytes:draw(logposLerp,0)
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
|
|
|
|
2022-04-24 03:25:48 +00:00
|
|
|
local function customLoad()
|
2022-05-09 04:31:57 +00:00
|
|
|
barpos = 160
|
|
|
|
logopos = -112
|
2022-04-24 03:25:48 +00:00
|
|
|
local lvls = playdate.file.listFiles("levels")
|
|
|
|
local m = {}
|
|
|
|
m[0], m[1] = "customs", "BACK"
|
2022-05-09 04:31:57 +00:00
|
|
|
if #lvls - ((10*page)) <= 0 then page = 0 end
|
|
|
|
if #lvls <= 11 then
|
2022-04-24 03:25:48 +00:00
|
|
|
for i = 1, #lvls, 1 do
|
|
|
|
m[i+1] = lvls[i]:upper()
|
|
|
|
end
|
2022-05-09 04:31:57 +00:00
|
|
|
elseif lvls[1 + (10*page)] then
|
2022-04-24 03:25:48 +00:00
|
|
|
m[2] = "NEXT PAGE"
|
2022-05-09 04:31:57 +00:00
|
|
|
for i = 1, 10, 1 do
|
|
|
|
if lvls[i+(10*page)] then
|
|
|
|
m[i+2] = lvls[i+(10*page)]:upper()
|
2022-04-24 03:25:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-09 04:31:57 +00:00
|
|
|
|
2022-04-24 03:25:48 +00:00
|
|
|
createMenu(m)
|
|
|
|
end
|
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
function editLoad()
|
2022-05-09 04:31:57 +00:00
|
|
|
logopos = -112
|
|
|
|
barpos = 160
|
2022-04-27 02:40:39 +00:00
|
|
|
local lvls = playdate.file.listFiles("levels")
|
|
|
|
local m = {}
|
|
|
|
m[0], m[1], m[2] = "edits", "BACK", "CREATE NEW"
|
2022-05-09 04:31:57 +00:00
|
|
|
if #lvls - (1 + (9*page)) <= 0 then page = 0 end
|
|
|
|
if #lvls <= 10 then
|
2022-04-27 02:40:39 +00:00
|
|
|
for i = 1, #lvls, 1 do
|
|
|
|
m[i+2] = lvls[i]:upper()
|
|
|
|
end
|
2022-05-09 04:31:57 +00:00
|
|
|
elseif lvls[1 + (9*page)] then
|
2022-05-07 20:31:34 +00:00
|
|
|
m[3] = "NEXT PAGE"
|
2022-05-09 04:31:57 +00:00
|
|
|
for i = 1, 9, 1 do
|
|
|
|
if lvls[i+(9*page)] then
|
|
|
|
m[i+3] = lvls[i+(9*page)]:upper()
|
2022-04-27 02:40:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-05-09 04:31:57 +00:00
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
createMenu(m)
|
|
|
|
end
|
|
|
|
|
2022-04-23 21:48:23 +00:00
|
|
|
function menuButtonPress(name)
|
2022-05-09 04:31:57 +00:00
|
|
|
logopos = 0
|
|
|
|
barpos = 0
|
2022-04-23 21:48:23 +00:00
|
|
|
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
|
2022-05-07 20:31:34 +00:00
|
|
|
deaths = 0
|
2022-05-12 22:04:00 +00:00
|
|
|
map = "data/level.rocketbyte"
|
|
|
|
addMapSave("data/level.rocketbyte")
|
2022-04-23 21:48:23 +00:00
|
|
|
|
|
|
|
elseif name == "CONTINUE" then
|
|
|
|
addMap(map)
|
2022-05-07 20:31:34 +00:00
|
|
|
mode = "game"
|
2022-04-23 21:48:23 +00:00
|
|
|
|
|
|
|
elseif name == "ABOUT THE CREATOR" then
|
|
|
|
local m = {}
|
|
|
|
m[0],m[1] = "about", "BACK"
|
|
|
|
createMenu(m)
|
|
|
|
|
2022-04-24 03:25:48 +00:00
|
|
|
elseif name == "USER LEVELS" then
|
|
|
|
page = 0
|
|
|
|
customLoad()
|
2022-04-27 02:40:39 +00:00
|
|
|
elseif name == "LEVEL EDITOR" then
|
|
|
|
page = 0
|
|
|
|
editLoad()
|
|
|
|
elseif name == "CREATE NEW" then
|
|
|
|
newProject()
|
2022-04-24 03:25:48 +00:00
|
|
|
elseif name == "NEXT PAGE" then
|
|
|
|
page += 1
|
2022-04-24 18:47:37 +00:00
|
|
|
if menu == "customs" then
|
|
|
|
customLoad()
|
|
|
|
else
|
|
|
|
editLoad()
|
|
|
|
end
|
2022-04-24 03:25:48 +00:00
|
|
|
|
2022-04-23 21:48:23 +00:00
|
|
|
elseif name == "BACK" or name == "CANCEL" then
|
|
|
|
createMenu(mainmenu)
|
2022-04-24 03:25:48 +00:00
|
|
|
|
|
|
|
elseif menu == "customs" then
|
2022-05-07 20:31:34 +00:00
|
|
|
addMap("levels/"..name, true)
|
|
|
|
mode = "play"
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
2022-04-24 03:25:48 +00:00
|
|
|
end
|