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-05-13 04:34:12 +00:00
|
|
|
mainmenu[4],mainmenu[3],mainmenu[2], mainmenu[1], mainmenu[0] = "START NEW GAME", "USER LEVELS", "LEVEL EDITOR", "EXTRAS", "mainNoPlay"
|
2022-04-23 23:54:00 +00:00
|
|
|
|
2022-05-22 02:06:58 +00:00
|
|
|
local g = playdate.datastore.read("savegame")
|
|
|
|
|
|
|
|
if g then
|
|
|
|
map = g.savedLevel
|
|
|
|
deaths = g.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-05-18 05:09:02 +00:00
|
|
|
function createMenu(items, invert)
|
2022-05-20 17:01:59 +00:00
|
|
|
song:setRate(1.0)
|
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
|
|
|
|
2022-05-18 05:09:02 +00:00
|
|
|
if invert then playdate.display.setInverted(true) else playdate.display.setInverted(false) end
|
|
|
|
|
2022-05-09 04:31:57 +00:00
|
|
|
controlX = -80
|
|
|
|
|
2022-05-18 05:09:02 +00:00
|
|
|
index = 0.5
|
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
|
|
|
|
2022-05-18 05:09:02 +00:00
|
|
|
|
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-05-18 05:09:02 +00:00
|
|
|
|
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-05-15 00:31:57 +00:00
|
|
|
|
|
|
|
if dev then
|
|
|
|
small:drawText(index, 0, 209)
|
|
|
|
end
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
|
|
|
|
2022-05-22 02:06:58 +00:00
|
|
|
local function dataLoad()
|
|
|
|
barpos = 160
|
|
|
|
logopos = -112
|
|
|
|
local lvls = playdate.file.listFiles("data")
|
|
|
|
local m = {}
|
|
|
|
m[0], m[1] = "data", "EXTRAS"
|
|
|
|
if #lvls - ((10*page)) <= 0 then page = 0 end
|
|
|
|
if #lvls <= 11 then
|
|
|
|
for i = 1, #lvls, 1 do
|
|
|
|
m[i+1] = lvls[i]:upper()
|
|
|
|
end
|
|
|
|
elseif lvls[1 + (10*page)] then
|
|
|
|
m[2] = "NEXT PAGE"
|
|
|
|
for i = 1, 10, 1 do
|
|
|
|
if lvls[i+(10*page)] then
|
|
|
|
m[i+2] = lvls[i+(10*page)]:upper()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
createMenu(m)
|
|
|
|
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 = {}
|
2022-05-22 02:06:58 +00:00
|
|
|
m[0], m[1] = "customs", "MENU"
|
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 = {}
|
2022-05-22 02:06:58 +00:00
|
|
|
m[0], m[1], m[2] = "edits", "MENU", "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-06-12 07:40:12 +00:00
|
|
|
|
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-29 05:53:46 +00:00
|
|
|
map = "data/level.json"
|
|
|
|
addMapSave("data/level.json")
|
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
|
|
|
|
2022-05-13 04:34:12 +00:00
|
|
|
elseif name == "EXTRAS" then
|
2022-04-23 21:48:23 +00:00
|
|
|
local m = {}
|
2022-05-18 05:09:02 +00:00
|
|
|
--barpos = 160
|
|
|
|
--logopos = -112
|
2022-05-22 02:06:58 +00:00
|
|
|
m[0],m[1], m[2], m[3], m[4], m[5] = "extras", "MENU", "MUSIC BOX", "END CUTSCENE", "START CUTSCENE", "LEVEL SELECT"
|
2022-05-18 05:09:02 +00:00
|
|
|
if playdate.file.exists("bonusLevels.rocketbytes") then
|
2022-05-20 17:01:59 +00:00
|
|
|
m[6] = "EXTRA LEVELS"
|
2022-05-18 05:09:02 +00:00
|
|
|
end
|
2022-04-23 21:48:23 +00:00
|
|
|
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()
|
2022-05-22 02:06:58 +00:00
|
|
|
elseif name == "LEVEL SELECT" then
|
|
|
|
dataLoad()
|
2022-04-27 02:40:39 +00:00
|
|
|
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-05-22 02:06:58 +00:00
|
|
|
elseif name == "BACK" or name == "CANCEL" or name == "MENU" then
|
2022-04-23 21:48:23 +00:00
|
|
|
createMenu(mainmenu)
|
2022-06-12 07:40:12 +00:00
|
|
|
elseif menu == "edits" then
|
|
|
|
mode = "editor"
|
|
|
|
menu = nil
|
|
|
|
editLoadName(name)
|
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-05-22 02:06:58 +00:00
|
|
|
elseif menu == "data" then
|
|
|
|
addMap("data/"..name, true)
|
|
|
|
mode = "play"
|
2022-04-23 21:48:23 +00:00
|
|
|
end
|
2022-04-24 03:25:48 +00:00
|
|
|
end
|