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
function editLoadName(name)
removeMap()
song:stop()
local data = json.decodeFile("levels/"..name)
powers = data.fuel
playerPos = {x = data.rocket.x, y = data.rocket.y}
@ -113,7 +113,7 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
playdate.wait(0.3)
editLoad()
else
removeMap()
song:stop()
position = {x=89,y=93}
playerPos = {x=1562,y=1564}
exitPos = {x = 1616, y = 1536}
@ -160,7 +160,7 @@ function editSave()
end
function editUpdate()
--print(math.floor( tileIndex ) )
local change, aChange = playdate.getCrankChange()
tileIndex += change * 0.01
@ -170,6 +170,10 @@ function editUpdate()
if tileIndex < 0 then tileIndex = 7.9 end
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
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)
if playdate.buttonJustPressed(playdate.kButtonA) then
if editor == "main" then
if editor == "tiles" 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)
tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2}
imgtiles = gfx.sprite.new(tilemapEditor)
]]
editor = "tiles"
elseif math.floor(tileIndex) == 1 then
powers[#powers+1] = {x=((position.x + 11) * 16)-7, y=((position.y + 7) * 16)-5}
elseif math.floor(tileIndex) == 4 then
@ -195,8 +210,7 @@ function editUpdate()
end
if playdate.buttonJustPressed(playdate.kButtonB) then
if editor == "main" then
if math.floor( tileIndex ) == 0 then
if editor == "tiles" 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
@ -204,8 +218,17 @@ function editUpdate()
break
end
end
imgtiles = gfx.sprite.new(tilemapEditor)
elseif math.floor(tileIndex) == 1 then
elseif editor == "main" 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
imgtiles = gfx.sprite.new(tilemapEditor)]]
if math.floor(tileIndex) == 1 then
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
table.remove(powers,power)
@ -271,7 +294,9 @@ function editUpdate()
gfx.drawLine(360,0,360,240)
-- 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)
imgAdd:draw(366,8)
imgLine:draw(366,64)
@ -306,7 +331,7 @@ function editUpdate()
if saveTime > 0 then
saveTime -= 0.1
animFloppy:draw(2,16)
animFloppy:draw(2,210)
end
end
@ -316,6 +341,8 @@ function editClose()
tiles[tile] = nil
end
powers = {}
editor = "main"
tileIndex = 0
playdate.display.setInverted(false)
imgtiles = gfx.sprite.new(tilemapEditor)
imgtiles:remove()

View file

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

View file

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