Rocket-Bytes/Source/Menu.lua

365 lines
10 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
2022-05-09 04:31:57 +00:00
local sidebar <const> = gfx.image.new("gfx/sidebar")
2022-07-25 00:35:23 +00:00
local small <const> = gfx.font.new("gfx/small")
2022-05-09 04:31:57 +00:00
local barpos = 0
local barposLerp = 160
local logopos = 0
local logposLerp = -122
local index = 0
local menuitems = {}
local menu = null
2022-04-27 02:40:39 +00:00
page = 0
local imgCursor = gfx.image.new("gfx/cursor")
local imgBytes = gfx.image.new("gfx/bytes")
2022-08-01 05:40:47 +00:00
local imgQRs = gfx.image.new("gfx/links")
assert(imgCursor)
assert(imgBytes)
assert(imgQRs)
local sfxAccept = playdate.sound.sampleplayer.new("sfx/accept")
local sfxSelect = playdate.sound.sampleplayer.new("sfx/select")
sfxAccept:setVolume(0.5)
sfxSelect:setVolume(0.5)
mainmenu = {}
function mainMenuCreation()
barposLerp = 160
logposLerp = -122
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
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-08-01 06:58:11 +00:00
if invert ~= true then playdate.display.setInverted(false) end
2022-05-18 05:09:02 +00:00
2022-05-09 04:31:57 +00:00
controlX = -80
2022-05-18 05:09:02 +00:00
index = 0.5
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"
end
2022-04-22 18:48:45 +00:00
function updateMenu()
gfx.clear(gfx.kColorBlack)
processStars(-10,-10)
2022-08-01 06:58:11 +00:00
2022-04-22 18:48:45 +00:00
-- input
local change, aChange = playdate.getCrankChange()
2022-04-24 18:47:37 +00:00
if playdate.buttonJustPressed(playdate.kButtonUp) then
sfxSelect:play()
index -= 1
2022-04-24 18:47:37 +00:00
elseif playdate.buttonJustPressed(playdate.kButtonDown) then
index += 1
sfxSelect:play()
2022-04-22 18:48:45 +00:00
end
2022-08-01 06:58:11 +00:00
if menuitems[1].name == "NO GRAVITY" then
local str = {[true]="TRUE",[false]="FALSE"}
page = -1
2022-08-14 00:48:19 +00:00
2022-08-14 00:54:57 +00:00
gfx.drawText("INVERTED: ".."\nGRAVITY: "..getGrav(),0,0)
2022-08-01 06:58:11 +00:00
else
sidebar:draw(barposLerp,0)
imgBytes:draw(logposLerp,0)
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
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
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
end
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-06-20 05:56:43 +00:00
menuButtonPress(menuitems[#menuitems - math.floor(index)].name,#menuitems - math.floor(index))
sfxAccept:play()
2022-04-27 02:40:39 +00:00
elseif playdate.buttonJustPressed(playdate.kButtonB) or playdate.buttonJustPressed(playdate.kButtonLeft) then
menuButtonPress("BACK")
sfxAccept:play()
end
if menu == "qrs" then
imgQRs:draw(0,0)
2022-07-25 00:35:23 +00:00
small:drawText("BY POSSIBLYAXOLOTL :)".."\nV."..playdate.metadata.version,0,0)
end
end
2022-05-22 02:06:58 +00:00
local function dataLoad()
barpos = 160
logopos = -112
2022-09-26 05:14:41 +00:00
local lvls = {"1. HOOK.json","2. ROCKET.json","3. HUT.json","4. SPINNER.json","5. SHUTTLE.json","6. SHELL.json","7. PYRAMID.json","8. KITCHEN.json","9. LADDER.json","10. CITY.json","11. FLOWER.json", "12. BOXES.json","13. SNAKE.json","14. TOWER.json","15. ESCAPE.json"}
2022-05-22 02:06:58 +00:00
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 = {}
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-09-26 05:14:41 +00:00
songlist = {"BACK","POV: YOU ARE A ROCKET","A LONELY, LOST SHIP", "LEVEL COMPLETE", "GAME COMPLETE", "CHIPVIBE2", "ORANGER CHIP","WACKMAN","HAUNTED HOUS", "SPOOKY ZONE"}
2022-06-20 05:56:43 +00:00
songlist[0] = "musicbox"
function menuButtonPress(name, index)
2022-05-09 04:31:57 +00:00
logopos = 0
barpos = 0
miniExplode(controlX - 17 --[[+ (playdate.graphics.getTextSize(name) / 2)]] ,controlY + (243 - (20 * #menuitems)))
2022-09-26 05:14:41 +00:00
if name == "START NEW GAME" then
local m = {}
m[0], m[1], m[2] = "newgame", "CANCEL", "CONFIRM"
createMenu(m)
2022-09-26 05:14:41 +00:00
elseif name == "START HALLOWEEN GAME" then
local m = {}
m[0], m[1], m[2] = "halgame", "CANCEL", "CONFIRM"
createMenu(m)
elseif name == "START NEW GAME" or name == "CONFIRM" then
2022-09-26 05:14:41 +00:00
if menu ~= "halgame" then
deaths = 0
beginStartCutscene(true)
else
mode = "hgame"
map = "data/H1. CAVEYARD.json"
addMapSave("data/H1. CAVEYARD.json")
end
elseif name == "CONTINUE" then
addMap(map)
2022-09-26 05:14:41 +00:00
dat = playdate.datastore.read("savegame")
dat.mode = dat.mode or "game"
mode = dat.mode
2022-08-01 06:58:11 +00:00
elseif name == "NO GRAVITY" then
setGrav(0)
barpos = 160
logopos = -112
elseif name == "NEGATIVE GRAVITY" then
setGrav(-0.2)
barpos = 160
logopos = -112
elseif name == "REGULAR GRAVITY" then
setGrav(0.2)
barpos = 160
logopos = -112
2022-08-09 19:51:07 +00:00
elseif name == "CHANGE MUSIC" then
setEditor("music")
mode = "editor"
elseif name == "START CUTSCENE" then
2022-07-30 02:51:08 +00:00
local m = {"BACK","WATCH START CUTSCENE"}
2022-07-23 20:42:51 +00:00
m[0] = "dat"
createMenu(m)
elseif name == "END CUTSCENE" then
2022-07-30 02:51:08 +00:00
local m = {"BACK","WATCH END CUTSCENE"}
2022-07-23 20:42:51 +00:00
m[0] = "dat"
createMenu(m)
elseif name == "WATCH START CUTSCENE" then
beginStartCutscene(false)
elseif name == "WATCH END CUTSCENE" then
beginEndCutscene()
2022-08-01 06:58:11 +00:00
elseif name == "RESUME" then
mode = "editor"
elseif name == "INVERT COLOURS" then
barpos = 160
logopos = -112
playdate.display.setInverted(not playdate.display.getInverted())
2022-05-13 04:34:12 +00:00
elseif name == "EXTRAS" then
local m = {}
2022-09-26 05:14:41 +00:00
barpos = 160
logopos = -112
2022-07-23 20:42:51 +00:00
--m[0],m[1], m[2], m[3], m[4], m[5], m[6] = "extras", "BACK", "MUSIC BOX", "LINKS", "END CUTSCENE", "START CUTSCENE", "LEVEL SELECT"
2022-09-26 05:14:41 +00:00
m[0],m[1], m[2], m[3], m[4], m[5], m[6],m[7] = "extras", "BACK","LINKS","END CUTSCENE", "START CUTSCENE", "MUSIC BOX", "LEVEL SELECT", "START HALLOWEEN GAME"
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
createMenu(m)
elseif name == "LINKS" then
local m = {}
m[0],m[1] = "qrs", "BACK"
createMenu(m)
logopos = -112
barpos = 160
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()
2022-07-25 00:35:23 +00:00
elseif menu =="data" then
dataLoad()
2022-04-24 18:47:37 +00:00
else
editLoad()
end
2022-04-24 03:25:48 +00:00
elseif name == "BACK" or name == "CANCEL" then
2022-06-20 05:56:43 +00:00
if menu == "musicbox" then
local m = {}
2022-09-26 05:14:41 +00:00
m[0],m[1], m[2], m[3], m[4], m[5], m[6],m[7] = "extras", "BACK","LINKS","END CUTSCENE", "START CUTSCENE", "MUSIC BOX", "LEVEL SELECT", "START HALLOWEEN GAME"
2022-06-20 05:56:43 +00:00
if playdate.file.exists("bonusLevels.rocketbytes") then
m[6] = "EXTRA LEVELS"
2022-09-26 05:14:41 +00:00
barpos = 160
logopos = -112
2022-06-20 05:56:43 +00:00
end
song:stop()
song:load("sfx/song1")
song:play(0)
2022-06-27 06:21:44 +00:00
local m = {}
2022-09-26 05:14:41 +00:00
barpos = 160
logopos = -112
m[0],m[1], m[2], m[3], m[4], m[5], m[6],m[7] = "extras", "BACK","LINKS","END CUTSCENE", "START CUTSCENE", "MUSIC BOX", "LEVEL SELECT", "START HALLOWEEN GAME"
2022-06-27 06:21:44 +00:00
createMenu(m)
2022-07-23 20:42:51 +00:00
elseif menu == "qrs" or menu == "data" or menu == "dat" then
local m = {}
2022-09-26 05:14:41 +00:00
m[0],m[1], m[2], m[3], m[4], m[5], m[6],m[7] = "extras", "BACK","LINKS","END CUTSCENE", "START CUTSCENE", "MUSIC BOX", "LEVEL SELECT", "START HALLOWEEN GAME"
2022-08-09 19:51:07 +00:00
createMenu(m)
2022-09-26 05:14:41 +00:00
barpos = 160
logopos = -112
2022-08-09 19:51:07 +00:00
elseif menu == nil then
2022-06-27 06:21:44 +00:00
else
createMenu(mainmenu)
2022-06-20 05:56:43 +00:00
end
2022-06-27 06:21:44 +00:00
2022-06-20 05:56:43 +00:00
elseif name == "MUSIC BOX" then
logopos = -112
barpos = 160
song:stop()
createMenu(songlist)
elseif menu == "edits" then
mode = "editor"
menu = nil
editLoadName(name)
2022-06-20 05:56:43 +00:00
elseif menu == "musicbox" then
logopos = -112
barpos = 160
mode = "music"
2022-06-28 23:30:32 +00:00
songTitle = songlist[index]
2022-06-20 05:56:43 +00:00
song:stop()
song:load("sfx/song"..index - 1)
song:play(0)
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"
end
2022-04-24 03:25:48 +00:00
end