From e08a469ad322a52ec4d1112bb521f2a45ab2090d Mon Sep 17 00:00:00 2001 From: PossiblyAxolotl Date: Sat, 23 Apr 2022 15:48:23 -0600 Subject: [PATCH] menu sys more doned and also saving :))) --- Source/Main.lua | 11 ++++----- Source/Map.lua | 5 ++++ Source/Menu.lua | 48 +++++++++++++++++++++++++++++++++++--- Source/gfx/bigrocket.png | Bin 0 -> 312 bytes Source/gfx/bytes.png | Bin 0 -> 499 bytes Source/gfx/play.png | Bin 229 -> 0 bytes Source/levels/level.json | 1 - Source/levels/level1.json | 2 +- 8 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 Source/gfx/bigrocket.png create mode 100644 Source/gfx/bytes.png delete mode 100644 Source/gfx/play.png delete mode 100644 Source/levels/level.json diff --git a/Source/Main.lua b/Source/Main.lua index 7efcea1..cf2e923 100644 --- a/Source/Main.lua +++ b/Source/Main.lua @@ -5,6 +5,7 @@ import "Map" import "Menu" mode = "menu" +map = "levels/level1.json" local gfx = playdate.graphics local disp = playdate.display @@ -18,20 +19,16 @@ song1:play(0, 1) gfx.setColor(gfx.kColorWhite) -- {"START NEW GAME","CONTINUE","USER LEVELS", "EXIT"} -local mainmenu = {} -if playdate.datastore.read("savegame") then - mainmenu[4],mainmenu[3],mainmenu[2],mainmenu[1], mainmenu[0] = "START NEW GAME", "CONTINE", "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 + createMenu(mainmenu) local menu = playdate.getSystemMenu() local menuItem, error = menu:addMenuItem("Main Menu", function() + mainMenuCreation() createMenu(mainmenu) end) -addMap("levels/level.json") +--addMap("levels/level.json") function playdate.update() if mode == "menu" then diff --git a/Source/Map.lua b/Source/Map.lua index 5080254..8ba217f 100644 --- a/Source/Map.lua +++ b/Source/Map.lua @@ -3,6 +3,11 @@ local tileTable = gfx.imagetable.new("gfx/tiles") local tilemap = gfx.tilemap.new() tilemap:setImageTable(tileTable) +function addMapSave(_file) + playdate.datastore.write({level=_file},"savegame") + addMap(_file) +end + function addMap(_file) local level = json.decodeFile(_file) tilemap:setSize(level.dimensions.x,level.dimensions.y) diff --git a/Source/Menu.lua b/Source/Menu.lua index f89ef08..350cc3f 100644 --- a/Source/Menu.lua +++ b/Source/Menu.lua @@ -8,7 +8,22 @@ local menuitems = {} local menu = null local imgCursor = gfx.image.new("gfx/cursor") +local imgBytes = gfx.image.new("gfx/bytes") assert(imgCursor) +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() function createMenu(items) killPlayer() @@ -40,10 +55,37 @@ function updateMenu() 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 -end \ No newline at end of file + 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 diff --git a/Source/gfx/bigrocket.png b/Source/gfx/bigrocket.png new file mode 100644 index 0000000000000000000000000000000000000000..e6e09f8c98aeb507465409ad1be2d6e10bb966da GIT binary patch literal 312 zcmV-80muG{P)^!y50Npd{7lSI+V9GDTxa z>PuiW5uv}RY;3kA6P{b7cJo2ttcA(~#yD-cZ$FH*DZRQNY}mz5grQ)tuA1A^bwlFY#S%1*1eLB6}P~QQXh@_II1mvFi3Z$XLDX?6Z(D zEIKqi-(R#gw>Kxl6i|4l>pyt3B)bTzmFt3`B>8r!Ml3%Ua|Y?2VRUz(*%qfAP|L zBOOgX5@d{CcI7<1j3RMn??H7u-;iey*JQMPn2MR@l!l$6<(rJ0$hwb7^E!pkHTmuN z=tMNrTtz=GZ9c4aMDw_N0)-!UcDfQYgUl9j64BY|3VwF)lh`^tz2of3NVF5tX!V>U zrHG6iV+-6))asRebXe<~5mB{b3z5=Bb5_7X7)GlQE8@& zK%0YVM`kCQkm|3@_1MgNVh_?2w6ea6-nOXnDV;cTqrV~oqw34Q6p08@MBcHMqPH`- zveS!QIumB)D?7cP@a(i2r3h)QnX5dhPW3{{o*~ p*$qO7_y-&Gh+&cc`c+hsfESaB%%66N7;pdp002ovPDHLkV1lu&?X~~_ literal 0 HcmV?d00001 diff --git a/Source/gfx/play.png b/Source/gfx/play.png deleted file mode 100644 index ed6115408b4265b9488d815f746acd1ff5e38d06..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 229 zcmV^P)eJ-N24Xc43%hr<$>{yg_;{y!SfqeX{Fb fXUNaKx4gjvxW7g