menu sys more doned and also saving :)))

This commit is contained in:
PossiblyAxolotl 2022-04-23 15:48:23 -06:00
parent e4959d6236
commit e08a469ad3
8 changed files with 55 additions and 12 deletions

View file

@ -5,6 +5,7 @@ import "Map"
import "Menu"
mode = "menu"
map = "levels/level1.json"
local gfx <const> = playdate.graphics
local disp <const> = 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

View file

@ -3,6 +3,11 @@ local tileTable <const> = gfx.imagetable.new("gfx/tiles")
local tilemap <const> = 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)

View file

@ -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
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

BIN
Source/gfx/bigrocket.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

BIN
Source/gfx/bytes.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 B

View file

@ -1 +0,0 @@
{"dimensions":{"x":22,"y":17},"rocket":{"x":70.4,"y":125.6},"tiles":[{"t":2,"x":2,"y":1},{"t":2,"x":14,"y":1},{"t":2,"x":14,"y":5},{"t":2,"x":22,"y":5},{"t":2,"x":8,"y":6},{"t":2,"x":2,"y":12},{"t":2,"x":8,"y":12},{"t":2,"x":11,"y":12},{"t":2,"x":14,"y":12},{"t":2,"x":8,"y":17},{"t":2,"x":22,"y":17},{"t":3,"x":3,"y":1},{"t":3,"x":4,"y":1},{"t":3,"x":5,"y":1},{"t":3,"x":6,"y":1},{"t":3,"x":7,"y":1},{"t":3,"x":8,"y":1},{"t":3,"x":9,"y":1},{"t":3,"x":10,"y":1},{"t":3,"x":11,"y":1},{"t":3,"x":12,"y":1},{"t":3,"x":13,"y":1},{"t":3,"x":15,"y":5},{"t":3,"x":16,"y":5},{"t":3,"x":17,"y":5},{"t":3,"x":18,"y":5},{"t":3,"x":19,"y":5},{"t":3,"x":20,"y":5},{"t":3,"x":21,"y":5},{"t":3,"x":3,"y":12},{"t":3,"x":4,"y":12},{"t":3,"x":5,"y":12},{"t":3,"x":6,"y":12},{"t":3,"x":7,"y":12},{"t":3,"x":9,"y":12},{"t":3,"x":10,"y":12},{"t":3,"x":9,"y":17},{"t":3,"x":10,"y":17},{"t":3,"x":11,"y":17},{"t":3,"x":12,"y":17},{"t":3,"x":13,"y":17},{"t":3,"x":14,"y":17},{"t":3,"x":15,"y":17},{"t":3,"x":16,"y":17},{"t":3,"x":17,"y":17},{"t":3,"x":18,"y":17},{"t":3,"x":19,"y":17},{"t":3,"x":20,"y":17},{"t":3,"x":21,"y":17},{"t":4,"x":2,"y":2},{"t":4,"x":14,"y":2},{"t":4,"x":2,"y":3},{"t":4,"x":14,"y":3},{"t":4,"x":2,"y":4},{"t":4,"x":14,"y":4},{"t":4,"x":2,"y":5},{"t":4,"x":2,"y":6},{"t":4,"x":14,"y":6},{"t":4,"x":22,"y":6},{"t":4,"x":2,"y":7},{"t":4,"x":8,"y":7},{"t":4,"x":14,"y":7},{"t":4,"x":22,"y":7},{"t":4,"x":2,"y":8},{"t":4,"x":8,"y":8},{"t":4,"x":14,"y":8},{"t":4,"x":22,"y":8},{"t":4,"x":2,"y":9},{"t":4,"x":8,"y":9},{"t":4,"x":14,"y":9},{"t":4,"x":22,"y":9},{"t":4,"x":2,"y":10},{"t":4,"x":8,"y":10},{"t":4,"x":14,"y":10},{"t":4,"x":22,"y":10},{"t":4,"x":2,"y":11},{"t":4,"x":8,"y":11},{"t":4,"x":14,"y":11},{"t":4,"x":22,"y":11},{"t":4,"x":22,"y":12},{"t":4,"x":8,"y":13},{"t":4,"x":22,"y":13},{"t":4,"x":8,"y":14},{"t":4,"x":22,"y":14},{"t":4,"x":8,"y":15},{"t":4,"x":22,"y":15},{"t":4,"x":8,"y":16},{"t":4,"x":22,"y":16}]}

View file

@ -1 +1 @@
{"tiles":[{"x":1,"y":1,"t":2},{"x":2,"y":1,"t":3},{"x":3,"y":1,"t":3},{"x":4,"y":1,"t":2}],"dimensions":{"x":4,"y":2}}
{"bigrocket":{"x":70.4,"y":125.6},"dimensions":{"x":22,"y":17},"rocket":{"x":70.4,"y":125.6},"tiles":[{"t":2,"x":2,"y":1},{"t":2,"x":14,"y":1},{"t":2,"x":14,"y":5},{"t":2,"x":22,"y":5},{"t":2,"x":8,"y":6},{"t":2,"x":2,"y":12},{"t":2,"x":8,"y":12},{"t":2,"x":11,"y":12},{"t":2,"x":14,"y":12},{"t":2,"x":8,"y":17},{"t":2,"x":22,"y":17},{"t":3,"x":3,"y":1},{"t":3,"x":4,"y":1},{"t":3,"x":5,"y":1},{"t":3,"x":6,"y":1},{"t":3,"x":7,"y":1},{"t":3,"x":8,"y":1},{"t":3,"x":9,"y":1},{"t":3,"x":10,"y":1},{"t":3,"x":11,"y":1},{"t":3,"x":12,"y":1},{"t":3,"x":13,"y":1},{"t":3,"x":15,"y":5},{"t":3,"x":16,"y":5},{"t":3,"x":17,"y":5},{"t":3,"x":18,"y":5},{"t":3,"x":19,"y":5},{"t":3,"x":20,"y":5},{"t":3,"x":21,"y":5},{"t":3,"x":3,"y":12},{"t":3,"x":4,"y":12},{"t":3,"x":5,"y":12},{"t":3,"x":6,"y":12},{"t":3,"x":7,"y":12},{"t":3,"x":9,"y":12},{"t":3,"x":10,"y":12},{"t":3,"x":9,"y":17},{"t":3,"x":10,"y":17},{"t":3,"x":11,"y":17},{"t":3,"x":12,"y":17},{"t":3,"x":13,"y":17},{"t":3,"x":14,"y":17},{"t":3,"x":15,"y":17},{"t":3,"x":16,"y":17},{"t":3,"x":17,"y":17},{"t":3,"x":18,"y":17},{"t":3,"x":19,"y":17},{"t":3,"x":20,"y":17},{"t":3,"x":21,"y":17},{"t":4,"x":2,"y":2},{"t":4,"x":14,"y":2},{"t":4,"x":2,"y":3},{"t":4,"x":14,"y":3},{"t":4,"x":2,"y":4},{"t":4,"x":14,"y":4},{"t":4,"x":2,"y":5},{"t":4,"x":2,"y":6},{"t":4,"x":14,"y":6},{"t":4,"x":22,"y":6},{"t":4,"x":2,"y":7},{"t":4,"x":8,"y":7},{"t":4,"x":14,"y":7},{"t":4,"x":22,"y":7},{"t":4,"x":2,"y":8},{"t":4,"x":8,"y":8},{"t":4,"x":14,"y":8},{"t":4,"x":22,"y":8},{"t":4,"x":2,"y":9},{"t":4,"x":8,"y":9},{"t":4,"x":14,"y":9},{"t":4,"x":22,"y":9},{"t":4,"x":2,"y":10},{"t":4,"x":8,"y":10},{"t":4,"x":14,"y":10},{"t":4,"x":22,"y":10},{"t":4,"x":2,"y":11},{"t":4,"x":8,"y":11},{"t":4,"x":14,"y":11},{"t":4,"x":22,"y":11},{"t":4,"x":22,"y":12},{"t":4,"x":8,"y":13},{"t":4,"x":22,"y":13},{"t":4,"x":8,"y":14},{"t":4,"x":22,"y":14},{"t":4,"x":8,"y":15},{"t":4,"x":22,"y":15},{"t":4,"x":8,"y":16},{"t":4,"x":22,"y":16}]}