fixed crash when saving big levels

This commit is contained in:
PossiblyAxolotl 2022-05-31 17:10:00 -06:00
parent b84ea25a15
commit cda688a90f
5 changed files with 57 additions and 16 deletions

View file

@ -75,7 +75,7 @@ function updateNewproj()
end end
function editLoadName(name) function editLoadName(name)
removeMap() song:stop()
local data = json.decodeFile("levels/"..name) local data = json.decodeFile("levels/"..name)
powers = data.fuel powers = data.fuel
playerPos = {x = data.rocket.x, y = data.rocket.y} playerPos = {x = data.rocket.x, y = data.rocket.y}
@ -113,7 +113,7 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
playdate.wait(0.3) playdate.wait(0.3)
editLoad() editLoad()
else else
removeMap() song:stop()
position = {x=89,y=93} position = {x=89,y=93}
playerPos = {x=1562,y=1564} playerPos = {x=1562,y=1564}
exitPos = {x = 1616, y = 1536} exitPos = {x = 1616, y = 1536}
@ -160,7 +160,7 @@ function editSave()
end end
function editUpdate() function editUpdate()
--print(math.floor( tileIndex ) )
local change, aChange = playdate.getCrankChange() local change, aChange = playdate.getCrankChange()
tileIndex += change * 0.01 tileIndex += change * 0.01
@ -168,8 +168,12 @@ function editUpdate()
if editor == "main" then if editor == "main" then
if tileIndex > 7.9 then tileIndex = 0 end if tileIndex > 7.9 then tileIndex = 0 end
if tileIndex < 0 then tileIndex = 7.9 end if tileIndex < 0 then tileIndex = 7.9 end
curY = math.floor( tileIndex ) * 28 +7 curY = math.floor( tileIndex ) * 28 +7
elseif editor == "tiles" then
if tileIndex < 0 then tileIndex = 0 end
curY = (math.floor( tileIndex ) % 8) * 28 +7
end end
curYlerp = playdate.math.lerp(curYlerp, curY, 0.4) curYlerp = playdate.math.lerp(curYlerp, curY, 0.4)
@ -177,11 +181,22 @@ function editUpdate()
positionLerp.y = playdate.math.lerp(positionLerp.y, position.y * 16, 0.5) positionLerp.y = playdate.math.lerp(positionLerp.y, position.y * 16, 0.5)
if playdate.buttonJustPressed(playdate.kButtonA) then if playdate.buttonJustPressed(playdate.kButtonA) then
if editor == "main" then if editor == "tiles" then
if math.floor( tileIndex ) == 0 then if math.floor( tileIndex ) == 0 then
editor = "main"
else
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,math.floor( tileIndex ) + 1)
tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=math.floor( tileIndex ) + 1}
imgtiles = gfx.sprite.new(tilemapEditor)
end
elseif editor == "main" then
if math.floor( tileIndex ) == 0 then
--[[
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2) tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2)
tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2} tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2}
imgtiles = gfx.sprite.new(tilemapEditor) imgtiles = gfx.sprite.new(tilemapEditor)
]]
editor = "tiles"
elseif math.floor(tileIndex) == 1 then elseif math.floor(tileIndex) == 1 then
powers[#powers+1] = {x=((position.x + 11) * 16)-7, y=((position.y + 7) * 16)-5} powers[#powers+1] = {x=((position.x + 11) * 16)-7, y=((position.y + 7) * 16)-5}
elseif math.floor(tileIndex) == 4 then elseif math.floor(tileIndex) == 4 then
@ -195,8 +210,16 @@ function editUpdate()
end end
if playdate.buttonJustPressed(playdate.kButtonB) then if playdate.buttonJustPressed(playdate.kButtonB) then
if editor == "main" then if editor == "tiles" then
if math.floor( tileIndex ) == 0 then tilemapEditor:setTileAtPosition(position.x+12,position.y+8,0)
for tile = 1, #tiles, 1 do
if tiles[tile].x == position.x + 12 and tiles[tile].y == position.y+8 then
table.remove(tiles,tile)
break
end
end
elseif editor == "main" then
--[[if math.floor( tileIndex ) == 0 then
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,0) tilemapEditor:setTileAtPosition(position.x+12,position.y+8,0)
for tile = 1, #tiles, 1 do for tile = 1, #tiles, 1 do
if tiles[tile].x == position.x + 12 and tiles[tile].y == position.y+8 then if tiles[tile].x == position.x + 12 and tiles[tile].y == position.y+8 then
@ -204,8 +227,8 @@ function editUpdate()
break break
end end
end end
imgtiles = gfx.sprite.new(tilemapEditor) imgtiles = gfx.sprite.new(tilemapEditor)]]
elseif math.floor(tileIndex) == 1 then if math.floor(tileIndex) == 1 then
for power = 1, #powers, 1 do for power = 1, #powers, 1 do
if powers[power].x == ((position.x + 11) * 16)-7 and powers[power].y == ((position.y + 7) * 16)-5 then if powers[power].x == ((position.x + 11) * 16)-7 and powers[power].y == ((position.y + 7) * 16)-5 then
table.remove(powers,power) table.remove(powers,power)
@ -271,7 +294,9 @@ function editUpdate()
gfx.drawLine(360,0,360,240) gfx.drawLine(360,0,360,240)
-- draw changes -- draw changes
if editor == "main" then if editor == "tiles" then
gfx.drawText("A TO PLACE \nB TO DELETE",0,0)
elseif editor == "main" then
imgMus:draw(366, 176) imgMus:draw(366, 176)
imgAdd:draw(366,8) imgAdd:draw(366,8)
imgLine:draw(366,64) imgLine:draw(366,64)
@ -306,7 +331,7 @@ function editUpdate()
if saveTime > 0 then if saveTime > 0 then
saveTime -= 0.1 saveTime -= 0.1
animFloppy:draw(2,16) animFloppy:draw(2,210)
end end
end end
@ -316,6 +341,8 @@ function editClose()
tiles[tile] = nil tiles[tile] = nil
end end
powers = {} powers = {}
editor = "main"
tileIndex = 0
playdate.display.setInverted(false) playdate.display.setInverted(false)
imgtiles = gfx.sprite.new(tilemapEditor) imgtiles = gfx.sprite.new(tilemapEditor)
imgtiles:remove() imgtiles:remove()

View file

@ -46,11 +46,16 @@ createMenu(mainmenu)
local menu = playdate.getSystemMenu() local menu = playdate.getSystemMenu()
menuButton, error = menu:addMenuItem("game menu", function() menuButton, error = menu:addMenuItem("game menu", function()
if mode == "game" then if mode == "game" then
removeMap()
playdate.datastore.delete("savegame.json") playdate.datastore.delete("savegame.json")
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame") playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
elseif mode == "editor" then elseif mode == "editor" then
editClose() editClose()
song:play(0)
end
if mode =="game" or mode == "play" then
killPlayer()
removeMap()
end end
totalEnergy = 0 totalEnergy = 0
showEnergy = false showEnergy = false

View file

@ -10,6 +10,8 @@ local grav <const> = 0.2
scale = 1 scale = 1
local dead = false local dead = false
local rocketfly = nil
local exists = false local exists = false
local active = false local active = false
local gfx <const> = playdate.graphics local gfx <const> = playdate.graphics
@ -49,6 +51,7 @@ function addPlayer(_x,_y,__x,__y)
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:moveTo(__x,__y)
sprBigRocket:removeAnimator()
sprBigRocket:setImage(imgBigRocket) sprBigRocket:setImage(imgBigRocket)
sprBigRocket:add() sprBigRocket:add()
sprRocket:moveTo(_x,_y) sprRocket:moveTo(_x,_y)
@ -60,12 +63,16 @@ function addPlayer(_x,_y,__x,__y)
end end
function killPlayer() function killPlayer()
rocketfly = nil
exists = false exists = false
active = false active = false
sprRocket:remove() sprRocket:remove()
sprRocket:removeAnimator()
sprBigRocket:remove() sprBigRocket:remove()
sprBigRocket:removeAnimator()
gfx.setDrawOffset(0,0) gfx.setDrawOffset(0,0)
if resetButton ~= nil then playdate.getSystemMenu():removeMenuItem(resetButton) end if resetButton ~= nil then playdate.getSystemMenu():removeMenuItem(resetButton) end
resetButton = nil
end end
local function playerWin() local function playerWin()
@ -79,9 +86,11 @@ local function playerWin()
sprRocket:setAnimator(gfx.animator.new(800, startPos, endPos)) sprRocket:setAnimator(gfx.animator.new(800, startPos, endPos))
rocketfly = playdate.timer.new(6000, function(timer) rocketfly = playdate.timer.new(6000, function(timer)
local stPos = playdate.geometry.point.new(sprBigRocket.x, sprBigRocket.y) if dead then
local ndPos = playdate.geometry.point.new(sprBigRocket.x, sprBigRocket.y - 1000) local stPos = playdate.geometry.point.new(sprBigRocket.x, sprBigRocket.y)
sprBigRocket:setAnimator(gfx.animator.new(3000,stPos,ndPos, playdate.easingFunctions.inCubic)) local ndPos = playdate.geometry.point.new(sprBigRocket.x, sprBigRocket.y - 1000)
sprBigRocket:setAnimator(gfx.animator.new(3000,stPos,ndPos, playdate.easingFunctions.inCubic))
end
end) end)
song:setFinishCallback(function() song:setFinishCallback(function()
@ -97,7 +106,7 @@ local function playerWin()
next = nil next = nil
killBlades() killBlades()
killPlayer() killPlayer()
addMapSave(map, false) addMapSave(map)
else else
mainMenuCreation() mainMenuCreation()
createMenu(mainmenu) createMenu(mainmenu)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 537 B

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 B

After

Width:  |  Height:  |  Size: 471 B