added deathcount and autosave deaths

This commit is contained in:
PossiblyAxolotl 2022-05-07 14:31:34 -06:00
parent ea730a5f0d
commit 6274779d46
8 changed files with 54 additions and 19 deletions

View file

@ -10,10 +10,14 @@ import "Editor"
mode = "menu"
map = "levels/level1.json"
deaths = 0
local gfx <const> = playdate.graphics
local disp <const> = playdate.display
local font <const> = gfx.font.new("gfx/big")
dev = true
gfx.setFont(font)
gfx.setBackgroundColor(gfx.kColorBlack)
@ -31,6 +35,9 @@ createMenu(mainmenu)
local menu = playdate.getSystemMenu()
local menuItem, error = menu:addMenuItem("Main Menu", function()
if mode == "game" then
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
end
mainMenuCreation()
createMenu(mainmenu)
end)
@ -41,15 +48,29 @@ function playdate.update()
if mode == "menu" then
updateMenu()
elseif mode == "game" then
elseif mode == "game" or mode == "play" then
updatePlayer()
gfx.clear(gfx.kColorBlack)
gfx.sprite.update()
drawTiles()
local ox, oy = gfx.getDrawOffset()
gfx.drawText(deaths,-ox + 1,-oy + 1)
elseif mode == "newproj" then
gfx.clear()
updateNewproj()
end
if dev then
local ox, oy = gfx.getDrawOffset()
playdate.drawFPS(0,20)
gfx.drawText(playdate.getCrankPosition(), -ox, -oy + 35)
gfx.drawText(deaths, -ox, -oy + 55)
end
updateSaws()
end
function playdate.gameWillTerminate()
if mode == "game" then
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
end
end

View file

@ -3,15 +3,23 @@ local tileTable <const> = gfx.imagetable.new("gfx/tiles")
local tilemap <const> = gfx.tilemap.new()
tilemap:setImageTable(tileTable)
local tiles = {}
function addMapSave(_file)
playdate.datastore.write({savedLevel=_file},"savegame")
addMap(_file)
playdate.datastore.write({savedLevel=_file,savedDeaths=deaths},"savegame")
addMap(_file, false)
mode = "game"
end
function addMap(_file)
function addMap(_file, rs)
if rs then deaths = 0 end
if #tiles > 0 then
for i = 1, #tiles, 1 do
tiles[i]:remove()
end
end
local level = json.decodeFile(_file)
tilemap:setSize(level.dimensions.x,level.dimensions.y)
for i = 1, #level.tiles, 1 do
tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t)
@ -21,9 +29,7 @@ function addMap(_file)
if level.rotators then loadSpins(level.rotators) end
addPlayer(level.rocket.x,level.rocket.y, level.bigrocket.x, level.bigrocket.y)
gfx.sprite.addWallSprites(tilemap, {0,1})
mode = "game"
tiles = gfx.sprite.addWallSprites(tilemap, {0,1})
end
function drawTiles()

View file

@ -20,6 +20,7 @@ function mainMenuCreation()
if playdate.datastore.read("savegame") then
map = playdate.datastore.read("savegame").savedLevel
deaths = playdate.datastore.read("savegame").savedDeaths
mainmenu[5], mainmenu[0] = "CONTINUE", "mainPlay"
end
end
@ -27,7 +28,9 @@ end
function createMenu(items)
killBlades()
killPlayer()
if playdate.getReduceFlashing() == false then
controlX = -80
end
index = 0
menuitems = {}
local _y =220
@ -84,7 +87,7 @@ local function customLoad()
local m = {}
m[0], m[1] = "customs", "BACK"
if #lvls - ((7*page)) <= 0 then page = 0 end
if #lvls < 7 then
if #lvls <= 7 then
for i = 1, #lvls, 1 do
m[i+1] = lvls[i]:upper()
end
@ -98,21 +101,19 @@ local function customLoad()
end
createMenu(m)
index = #lvls
end
function editLoad()
local lvls = playdate.file.listFiles("levels")
local m = {}
m[0], m[1], m[2] = "edits", "BACK", "CREATE NEW"
if #lvls - ((6*page)) <= 0 then page = 0 end
if #lvls < 6 then
if #lvls - (1 + (6*page)) <= 0 then page = 0 end
if #lvls <= 7 then
for i = 1, #lvls, 1 do
m[i+2] = lvls[i]:upper()
end
elseif lvls[1 + (6*page)] then
m[2] = "NEXT PAGE"
m[3] = "NEXT PAGE"
for i = 1, 6, 1 do
if lvls[i+(6*page)] then
m[i+3] = lvls[i+(6*page)]:upper()
@ -121,8 +122,6 @@ function editLoad()
end
createMenu(m)
index = #lvls
end
function menuButtonPress(name)
@ -132,10 +131,12 @@ function menuButtonPress(name)
createMenu(m)
elseif name == "START NEW GAME" or name == "CONFIRM" then
deaths = 0
addMapSave("levels/level.json")
elseif name == "CONTINUE" then
addMap(map)
mode = "game"
elseif name == "ABOUT THE CREATOR" then
local m = {}
@ -162,6 +163,7 @@ function menuButtonPress(name)
createMenu(mainmenu)
elseif menu == "customs" then
addMap("levels/"..name)
addMap("levels/"..name, true)
mode = "play"
end
end

View file

@ -36,6 +36,7 @@ function addPlayer(_x,_y,__x,__y)
sprBigRocket:add()
sprRocket:moveTo(_x,_y)
sprRocket:add()
sprRocket:setVisible(true)
end
function killPlayer()
@ -52,6 +53,7 @@ local function playerWin()
end
local function die()
deaths +=1
active = false
velocity = {x=0,y=0}
sprRocket:moveTo(startpos.x, startpos.y)

View file

@ -0,0 +1 @@
{"bigrocket":{"x":480,"y":159.276018},"dimensions":{"x":34,"y":13},"rocket":{"x":92.55814,"y":160.930233},"saws":[{"ends":{"x":228.110627,"y":142.396299},"speed":2,"start":{"x":141.474654,"y":139.631336}},{"ends":{"x":520,"y":30},"speed":3,"start":{"x":430,"y":70}}],"tiles":[{"t":2,"x":1,"y":1},{"t":2,"x":14,"y":1},{"t":2,"x":18,"y":1},{"t":2,"x":34,"y":1},{"t":2,"x":14,"y":3},{"t":2,"x":18,"y":3},{"t":2,"x":15,"y":4},{"t":2,"x":17,"y":4},{"t":2,"x":5,"y":5},{"t":2,"x":8,"y":5},{"t":2,"x":11,"y":5},{"t":2,"x":15,"y":5},{"t":2,"x":17,"y":5},{"t":2,"x":16,"y":6},{"t":2,"x":21,"y":6},{"t":2,"x":22,"y":6},{"t":2,"x":26,"y":6},{"t":2,"x":27,"y":6},{"t":2,"x":23,"y":7},{"t":2,"x":25,"y":7},{"t":2,"x":24,"y":8},{"t":2,"x":16,"y":9},{"t":2,"x":1,"y":13},{"t":2,"x":8,"y":13},{"t":2,"x":21,"y":13},{"t":2,"x":27,"y":13},{"t":2,"x":34,"y":13},{"t":3,"x":2,"y":1},{"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":1},{"t":3,"x":16,"y":1},{"t":3,"x":17,"y":1},{"t":3,"x":19,"y":1},{"t":3,"x":20,"y":1},{"t":3,"x":21,"y":1},{"t":3,"x":22,"y":1},{"t":3,"x":23,"y":1},{"t":3,"x":24,"y":1},{"t":3,"x":25,"y":1},{"t":3,"x":26,"y":1},{"t":3,"x":27,"y":1},{"t":3,"x":28,"y":1},{"t":3,"x":29,"y":1},{"t":3,"x":30,"y":1},{"t":3,"x":31,"y":1},{"t":3,"x":32,"y":1},{"t":3,"x":33,"y":1},{"t":3,"x":6,"y":5},{"t":3,"x":7,"y":5},{"t":3,"x":9,"y":5},{"t":3,"x":10,"y":5},{"t":3,"x":2,"y":13},{"t":3,"x":3,"y":13},{"t":3,"x":4,"y":13},{"t":3,"x":5,"y":13},{"t":3,"x":6,"y":13},{"t":3,"x":7,"y":13},{"t":3,"x":9,"y":13},{"t":3,"x":10,"y":13},{"t":3,"x":11,"y":13},{"t":3,"x":12,"y":13},{"t":3,"x":13,"y":13},{"t":3,"x":14,"y":13},{"t":3,"x":15,"y":13},{"t":3,"x":16,"y":13},{"t":3,"x":17,"y":13},{"t":3,"x":18,"y":13},{"t":3,"x":19,"y":13},{"t":3,"x":20,"y":13},{"t":3,"x":22,"y":13},{"t":3,"x":23,"y":13},{"t":3,"x":24,"y":13},{"t":3,"x":25,"y":13},{"t":3,"x":26,"y":13},{"t":3,"x":28,"y":13},{"t":3,"x":29,"y":13},{"t":3,"x":30,"y":13},{"t":3,"x":31,"y":13},{"t":3,"x":32,"y":13},{"t":3,"x":33,"y":13},{"t":4,"x":1,"y":2},{"t":4,"x":14,"y":2},{"t":4,"x":18,"y":2},{"t":4,"x":34,"y":2},{"t":4,"x":1,"y":3},{"t":4,"x":34,"y":3},{"t":4,"x":1,"y":4},{"t":4,"x":34,"y":4},{"t":4,"x":1,"y":5},{"t":4,"x":34,"y":5},{"t":4,"x":1,"y":6},{"t":4,"x":8,"y":6},{"t":4,"x":34,"y":6},{"t":4,"x":1,"y":7},{"t":4,"x":8,"y":7},{"t":4,"x":16,"y":7},{"t":4,"x":21,"y":7},{"t":4,"x":27,"y":7},{"t":4,"x":34,"y":7},{"t":4,"x":1,"y":8},{"t":4,"x":8,"y":8},{"t":4,"x":16,"y":8},{"t":4,"x":21,"y":8},{"t":4,"x":27,"y":8},{"t":4,"x":34,"y":8},{"t":4,"x":1,"y":9},{"t":4,"x":8,"y":9},{"t":4,"x":21,"y":9},{"t":4,"x":27,"y":9},{"t":4,"x":34,"y":9},{"t":4,"x":1,"y":10},{"t":4,"x":8,"y":10},{"t":4,"x":21,"y":10},{"t":4,"x":27,"y":10},{"t":4,"x":34,"y":10},{"t":4,"x":1,"y":11},{"t":4,"x":8,"y":11},{"t":4,"x":21,"y":11},{"t":4,"x":27,"y":11},{"t":4,"x":34,"y":11},{"t":4,"x":1,"y":12},{"t":4,"x":8,"y":12},{"t":4,"x":21,"y":12},{"t":4,"x":27,"y":12},{"t":4,"x":34,"y":12}]}

View file

@ -0,0 +1 @@
{"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}]}

1
Source/levels/a.json Normal file
View file

@ -0,0 +1 @@
{"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}]}

1
Source/levels/winw.json Normal file
View file

@ -0,0 +1 @@
{"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}]}