From cda688a90f7563164bcbd36528043a5c3a1c0095 Mon Sep 17 00:00:00 2001 From: PossiblyAxolotl Date: Tue, 31 May 2022 17:10:00 -0600 Subject: [PATCH] fixed crash when saving big levels --- Source/Editor.lua | 49 ++++++++++++++++++++++------- Source/Main.lua | 7 ++++- Source/Player.lua | 17 +++++++--- Source/gfx/floppyT-table-30-26.png | Bin 537 -> 719 bytes Source/gfx/tiles-table-16-16.png | Bin 390 -> 471 bytes 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/Source/Editor.lua b/Source/Editor.lua index 2d1fb54..b0f29e5 100644 --- a/Source/Editor.lua +++ b/Source/Editor.lua @@ -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 @@ -168,8 +168,12 @@ function editUpdate() if editor == "main" then if tileIndex > 7.9 then tileIndex = 0 end 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,16 @@ 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 + 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) for tile = 1, #tiles, 1 do if tiles[tile].x == position.x + 12 and tiles[tile].y == position.y+8 then @@ -204,8 +227,8 @@ function editUpdate() break end end - imgtiles = gfx.sprite.new(tilemapEditor) - elseif math.floor(tileIndex) == 1 then + 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() diff --git a/Source/Main.lua b/Source/Main.lua index 46dfed0..bd5baf6 100644 --- a/Source/Main.lua +++ b/Source/Main.lua @@ -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 diff --git a/Source/Player.lua b/Source/Player.lua index bf8489a..7493327 100644 --- a/Source/Player.lua +++ b/Source/Player.lua @@ -10,6 +10,8 @@ local grav = 0.2 scale = 1 local dead = false +local rocketfly = nil + local exists = false local active = false local gfx = 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) - 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)) + 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) diff --git a/Source/gfx/floppyT-table-30-26.png b/Source/gfx/floppyT-table-30-26.png index b2da3f319cd7795386549265752b3cd587317e6f..53a46413f99a1dc9f0f363e283d05ace578065b5 100644 GIT binary patch delta 696 zcmV;p0!RIs1kVMKBYy&xNkl)gtoS4W>yhn!D;f+7F_{PTDE5BGb_!tQc;EPw3AUs$x#tnJtKYWq>W zwf(1V6Vra{-dw*|ca(iUPX+d0LKVk%N^e6yq}RJ&dw)-Nt`Z*Kx6V4Zvgg%-=TuSe zO*iHFzP4`%3jiS4uN|z>xI&w*&`VdeZ&voJR+?-3TYI1St$P)Y-fOMZYj$?oTYKJS z_bU2tdt2w!)_;D(-ix(6R{@XjRQB<_xBlMrp3kBE-p}_@eLGkH0KuMDTQ7eJZQa3o z{LL&Wp!?ZroAYII--nSPh z7j?ec!2$pX_HhR*`}2tOm-|_N2{(Ax(XM6R-d@L5cK0l|vv;?5e=oP&yvpg0TKB(w zUfIC{00?G*1ppAt0t)~j*vHpkWq-F;ZNJsE+JevhXlgIt&3AOYZg21JG8<)|Kdt)a zm3egr=6}_9%qu%s006-(umAvpSzrMG1hc>b00?G*1ppAtC%Nk{cF*$eoV|Q9vfg*~ z^!L#>uX4M3W$a)900f)e!Rq~&fd0Ar*|Kl1-go!(^?N${`E`_@9V`HVV9ysEvzCl= z7dcz?OE0QM^=mKU*7l<=8khE4T@;_|XZKq5voRmv?BhB6{57v~dr^J!Dz?|EZ(arT e?O*`_1p5JHyC6QZo`baj0000i_?8`h-+c42eA+8+^{&ZneEi zH*w4e(yuQ70001(*>?Pkec$&U-+SBsr5wi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