fixed loading finally

This commit is contained in:
PossiblyAxolotl 2022-04-23 17:54:00 -06:00
parent e08a469ad3
commit 4393d2aa87
7 changed files with 37 additions and 10 deletions

View file

@ -3,8 +3,10 @@ local tileTable <const> = gfx.imagetable.new("gfx/tiles")
local tilemap <const> = gfx.tilemap.new() local tilemap <const> = gfx.tilemap.new()
tilemap:setImageTable(tileTable) tilemap:setImageTable(tileTable)
function addMapSave(_file) function addMapSave(_file)
playdate.datastore.write({level=_file},"savegame") playdate.datastore.write({savedLevel=_file},"savegame")
addMap(_file) addMap(_file)
end end
@ -15,7 +17,7 @@ function addMap(_file)
tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t) tilemap:setTileAtPosition(level.tiles[i].x,level.tiles[i].y,level.tiles[i].t)
end end
addPlayer(level.rocket.x,level.rocket.y) addPlayer(level.rocket.x,level.rocket.y, level.bigrocket.x, level.bigrocket.y)
gfx.sprite.addWallSprites(tilemap, {0,1}) gfx.sprite.addWallSprites(tilemap, {0,1})

View file

@ -15,12 +15,12 @@ assert(imgBytes)
mainmenu = {} mainmenu = {}
function mainMenuCreation() function mainMenuCreation()
mainmenu = {} 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" mainmenu[3],mainmenu[2],mainmenu[1], mainmenu[0] = "START NEW GAME", "USER LEVELS", "ABOUT THE CREATOR", "mainNoPlay"
end
if playdate.datastore.read("savegame") then
map = playdate.datastore.read("savegame").savedLevel
mainmenu[4], mainmenu[0] = "CONTINUE", "mainPlay"
end
end end
mainMenuCreation() mainMenuCreation()
@ -75,7 +75,7 @@ function menuButtonPress(name)
createMenu(m) createMenu(m)
elseif name == "START NEW GAME" or name == "CONFIRM" then elseif name == "START NEW GAME" or name == "CONFIRM" then
addMapSave("levels/level1.json") addMapSave("levels/level.json")
elseif name == "CONTINUE" then elseif name == "CONTINUE" then
addMap(map) addMap(map)

View file

@ -3,6 +3,7 @@ import "CoreLibs/math"
local velocity = {x=0,y=0} local velocity = {x=0,y=0}
local lerpmnt <const> = 0.5 local lerpmnt <const> = 0.5
local grav <const> = 0.2 local grav <const> = 0.2
scale = 1
local exists = false local exists = false
local active = false local active = false
@ -13,11 +14,20 @@ local sprRocket = gfx.sprite.new(imgRocket)
sprRocket:setCollideRect(7, 7, 14, 14) sprRocket:setCollideRect(7, 7, 14, 14)
local startpos = {x=0,y=0} local startpos = {x=0,y=0}
function addPlayer(_x,_y) local imgBigRocket = gfx.image.new("gfx/bigrocket")
assert(imgBigRocket)
local sprBigRocket = gfx.sprite.new(imgBigRocket)
sprBigRocket:setCollideRect(8,8,48,48)
sprBigRocket:setGroups({2})
function addPlayer(_x,_y,__x,__y)
exists = true exists = true
scale = 1
active = false active = false
velocity = {x=0,y=0} velocity = {x=0,y=0}
startpos = {x= _x,y=_y} startpos = {x= _x,y=_y}
sprBigRocket:moveTo(__x,__y)
sprBigRocket:add()
sprRocket:moveTo(_x,_y) sprRocket:moveTo(_x,_y)
sprRocket:add() sprRocket:add()
end end
@ -29,6 +39,11 @@ function killPlayer()
gfx.setDrawOffset(0,0) gfx.setDrawOffset(0,0)
end end
local function playerWin()
active = false
exists = false
end
local function die() local function die()
active = false active = false
velocity = {x=0,y=0} velocity = {x=0,y=0}
@ -64,5 +79,15 @@ function updatePlayer()
gfx.setDrawOffset(playdate.math.lerp(cx,(-sprRocket.x + 200), lerpmnt), playdate.math.lerp(cy,(-sprRocket.y + 120), lerpmnt)) gfx.setDrawOffset(playdate.math.lerp(cx,(-sprRocket.x + 200), lerpmnt), playdate.math.lerp(cy,(-sprRocket.y + 120), lerpmnt))
end end
updateExit()
sprRocket:setScale(scale,scale)
sprRocket:setRotation(playdate.getCrankPosition()) sprRocket:setRotation(playdate.getCrankPosition())
end end
function updateExit()
if sprBigRocket:alphaCollision(sprRocket) then
playerWin()
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 B

After

Width:  |  Height:  |  Size: 531 B

File diff suppressed because one or more lines are too long

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

@ -0,0 +1 @@
{"bigrocket":{"x":73.333333,"y":144.79638},"dimensions":{"x":22,"y":17},"rocket":{"x":276.27907,"y":144.651163},"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}]}