125 lines
No EOL
2.9 KiB
Lua
125 lines
No EOL
2.9 KiB
Lua
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 <const> = playdate.graphics
|
|
local disp <const> = playdate.display
|
|
local font <const> = gfx.font.new("gfx/big")
|
|
small = gfx.font.new("gfx/font(1)")
|
|
|
|
dev = false
|
|
|
|
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)
|
|
-- {"START NEW GAME","CONTINUE","USER LEVELS", "EXIT"}
|
|
|
|
mainMenuCreation()
|
|
|
|
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()
|
|
end
|
|
totalEnergy = 0
|
|
showEnergy = false
|
|
energy = 0
|
|
mainMenuCreation()
|
|
createMenu(mainmenu)
|
|
end)
|
|
|
|
--local devButton, error = menu:addCheckmarkMenuItem("dev stats", false, function(value)
|
|
-- dev = value
|
|
--end)
|
|
|
|
--addMap("levels/level.json")
|
|
|
|
playdate.ui.crankIndicator:start()
|
|
|
|
if playdate.file.exists("levels") == false then playdate.file.mkdir("levels") end
|
|
|
|
function playdate.keyPressed(key)
|
|
if key == "D" then
|
|
dev = not dev
|
|
end
|
|
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
|
|
if dev then
|
|
local ox, oy = gfx.getDrawOffset()
|
|
playdate.drawFPS(0,228)
|
|
small:drawText(math.floor( playdate.getCrankPosition() ), -ox, -oy + 218)
|
|
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 |