import "CoreLibs/graphics" import "CoreLibs/sprites" import "CoreLibs/ui" import "Player" import "Map" import "Menu" import "Saws" import "Editor" mode = "menu" map = "data/level.rocketbyte" deaths = 0 energy = 0 totalEnergy = 0 showEnergy = false next = nil local gfx = playdate.graphics local disp = playdate.display local font = gfx.font.new("gfx/big") small = gfx.font.new("gfx/font(1)") gfx.setFont(font) gfx.setBackgroundColor(gfx.kColorBlack) song = playdate.sound.fileplayer.new("sfx/song1") song:setVolume(0.5) --song:setVolume(0.5,0.5, 1) song:play(0) local imgSkull = gfx.image.new("gfx/skullEmoji") local imgLightning = gfx.image.new("gfx/lightning") assert(imgSkull) assert(imgLightning) gfx.setColor(gfx.kColorWhite) mainMenuCreation() createMenu(mainmenu) local menu = playdate.getSystemMenu() menuButton, error = menu:addMenuItem("game menu", function() if mode == "game" then 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 energy = 0 mainMenuCreation() createMenu(mainmenu) end) playdate.ui.crankIndicator:start() if playdate.file.exists("levels") == false then playdate.file.mkdir("levels") end function playdate.update() if mode == "menu" then updateMenu() elseif mode == "game" or mode == "play" then song:setVolume(0.5) updatePlayer() gfx.sprite.update() local ox, oy = gfx.getDrawOffset() imgSkull:draw(-ox + 1, -oy + 2) gfx.drawText(deaths,-ox + 20,-oy + 2) if showEnergy then imgLightning:draw(-ox + 1, -oy + 20) gfx.drawText(energy.."/"..totalEnergy,-ox + 20,-oy + 20) end if playdate.isCrankDocked() then playdate.ui.crankIndicator:update() end elseif mode == "newproj" then gfx.clear() updateNewproj() elseif mode == "editor" then editUpdate() if playdate.isCrankDocked() then playdate.ui.crankIndicator:update() end end updateSaws() end function playdate.gameWillTerminate() if mode == "game" then playdate.datastore.delete("savegame.json") playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame") end end function playdate.debugDraw() gfx.setDrawOffset(0,0) playdate.drawFPS(0,228) small:drawText(math.floor( playdate.getCrankPosition() ), 0, 218) end