HOLY SHIT I FIXED THE CRASH FR THIS TIME

This commit is contained in:
PossiblyAxolotl 2022-06-12 01:40:12 -06:00
parent 4ff84eb6ba
commit a2d5a9d92d
3 changed files with 17 additions and 28 deletions

View file

@ -6,7 +6,6 @@ local gfx <const> = playdate.graphics
local prevtext = "" local prevtext = ""
local levelname = nil local levelname = nil
local inverted = false local inverted = false
gfx.setLineWidth(5)
local tileTable <const> = gfx.imagetable.new("gfx/tiles") local tileTable <const> = gfx.imagetable.new("gfx/tiles")
local tilemapEditor = gfx.tilemap.new() local tilemapEditor = gfx.tilemap.new()
@ -20,7 +19,6 @@ local w, h = imgtiles:getSize()
imgtiles:moveTo(w/2,h/2) imgtiles:moveTo(w/2,h/2)
local bool2int = {[true]=1,[false]=0} local bool2int = {[true]=1,[false]=0}
local menu = playdate.getSystemMenu()
local toolTipButton local toolTipButton
local altClrButton local altClrButton
@ -83,36 +81,27 @@ end
function editLoadName(name) function editLoadName(name)
song:stop() song:stop()
mode = "editor" mode = "editor"
playdate.wait(0.1)
local data = json.decodeFile("levels/"..name) local data = json.decodeFile("levels/"..name)
playdate.wait(0.1)
powers = data.fuel powers = data.fuel
sawblades = data.saws sawblades = data.saws
playerPos = {x = data.rocket.x, y = data.rocket.y} playerPos = {x = data.rocket.x, y = data.rocket.y}
exitPos = {x = data.bigrocket.x, y = data.bigrocket.y} exitPos = {x = data.bigrocket.x, y = data.bigrocket.y}
position = {x = (data.rocket.x + 6) / 16, y = (data.rocket.y + 4)/16} position = {x = (data.rocket.x + 6) / 16, y = (data.rocket.y + 4)/16}
playdate.wait(0.1)
levelname = name:match("(.+)%..+$") levelname = name:match("(.+)%..+$")
inverted = data.inverted inverted = data.inverted
playdate.display.setInverted(data.inverted) playdate.display.setInverted(data.inverted)
saveTime = 0 saveTime = 0
playdate.wait(0.1)
-- loading tiles -- loading tiles
for tile = 1, #tiles, 1 do
tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0)
end
playdate.wait(0.1)
for tile = 1, #data.tiles, 1 do for tile = 1, #data.tiles, 1 do
tilemapEditor:setTileAtPosition(data.tiles[tile].x,data.tiles[tile].y,data.tiles[tile].t) tilemapEditor:setTileAtPosition(data.tiles[tile].x,data.tiles[tile].y,data.tiles[tile].t)
tiles[tile] = {x=data.tiles[tile].x,y=data.tiles[tile].y,t=data.tiles[tile].t} tiles[tile] = {x=data.tiles[tile].x,y=data.tiles[tile].y,t=data.tiles[tile].t}
end end
playdate.wait(0.1) altClrButton = playdate.getSystemMenu():addCheckmarkMenuItem("alt colours",inverted, function(value)
altClrButton = menu:addCheckmarkMenuItem("alt colours",inverted, function(value)
playdate.display.setInverted(value) playdate.display.setInverted(value)
inverted = value inverted = value
end) end)
toolTipButton = menu:addMenuItem("save", function() toolTipButton = playdate.getSystemMenu():addMenuItem("save", function()
editSave() editSave()
end) end)
@ -127,7 +116,6 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
else else
song:stop() song:stop()
mode = "editor" mode = "editor"
playdate.wait(0.1)
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}
@ -135,20 +123,16 @@ function playdate.keyboard.keyboardWillHideCallback(ok)
playdate.display.setInverted(false) playdate.display.setInverted(false)
saveTime = 0 saveTime = 0
song:stop() song:stop()
mode = "editor" playdate.getSystemMenu():addCheckmarkMenuItem("alt colours",false, function(value)
playdate.wait(0.1)
altClrButton, error = menu:addCheckmarkMenuItem("alt colours",false, function(value)
playdate.display.setInverted(value) playdate.display.setInverted(value)
inverted = value inverted = value
end) end)
toolTipButton, error = menu:addMenuItem("save",false, function() playdate.getSystemMenu():addMenuItem("save",false, function()
editSave() editSave()
end) end)
playdate.wait(0.1)
levelname = playdate.keyboard.text:upper() levelname = playdate.keyboard.text:upper()
imgtiles:add() imgtiles:add()
playdate.wait(0.1)
end end
end end
@ -410,7 +394,9 @@ function editClose()
playdate.display.setInverted(false) playdate.display.setInverted(false)
imgtiles = gfx.sprite.new(tilemapEditor) imgtiles = gfx.sprite.new(tilemapEditor)
imgtiles:remove() imgtiles:remove()
playdate.getSystemMenu():removeMenuItem(toolTipButton) if #playdate.getSystemMenu():getMenuItems() > 1 then
playdate.getSystemMenu():removeMenuItem(altClrButton) playdate.getSystemMenu():removeMenuItem(playdate.getSystemMenu():getMenuItems()[3])
playdate.getSystemMenu():removeMenuItem(playdate.getSystemMenu():getMenuItems()[2])
end
end end

View file

@ -182,6 +182,7 @@ end
function menuButtonPress(name) function menuButtonPress(name)
logopos = 0 logopos = 0
barpos = 0 barpos = 0
if name == "START NEW GAME" and menu == "mainPlay" then if name == "START NEW GAME" and menu == "mainPlay" then
local m = {} local m = {}
m[0], m[1], m[2] = "newgame", "CANCEL", "CONFIRM" m[0], m[1], m[2] = "newgame", "CANCEL", "CONFIRM"
@ -226,14 +227,15 @@ function menuButtonPress(name)
elseif name == "BACK" or name == "CANCEL" or name == "MENU" then elseif name == "BACK" or name == "CANCEL" or name == "MENU" then
createMenu(mainmenu) createMenu(mainmenu)
elseif menu == "edits" then
mode = "editor"
menu = nil
editLoadName(name)
elseif menu == "customs" then elseif menu == "customs" then
addMap("levels/"..name, true) addMap("levels/"..name, true)
mode = "play" mode = "play"
elseif menu == "data" then elseif menu == "data" then
addMap("data/"..name, true) addMap("data/"..name, true)
mode = "play" mode = "play"
elseif menu == "edits" then
editLoadName(name)
end end
end end

View file

@ -63,7 +63,7 @@ function addPlayer(_x,_y,__x,__y)
end end
function killPlayer() function killPlayer()
rocketfly = nil song:setFinishCallback(nil)
exists = false exists = false
active = false active = false
sprRocket:remove() sprRocket:remove()
@ -94,24 +94,25 @@ local function playerWin()
end) end)
song:setFinishCallback(function() song:setFinishCallback(function()
song:setFinishCallback(nil)
if next then if next then
map = next map = next
end end
totalEnergy = 0 totalEnergy = 0
showEnergy = false showEnergy = false
energy = 0 energy = 0
killBlades()
killPlayer() killPlayer()
removeMap() removeMap()
killBlades()
if mode == "game" and next then if mode == "game" and next then
playdate.datastore.delete("savegame") playdate.datastore.delete("savegame")
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame") playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
next = nil next = nil
addMapSave(map) addMapSave(map)
else else
next = nil
mainMenuCreation() mainMenuCreation()
createMenu(mainmenu) createMenu(mainmenu)
next = nil
end end
end) end)