2022-04-17 19:27:36 +00:00
|
|
|
import "CoreLibs/graphics"
|
|
|
|
import "CoreLibs/sprites"
|
2022-04-24 03:25:48 +00:00
|
|
|
import "CoreLibs/ui"
|
2022-04-19 21:22:15 +00:00
|
|
|
import "Player"
|
2022-04-19 21:32:18 +00:00
|
|
|
import "Map"
|
2022-04-22 18:48:45 +00:00
|
|
|
import "Menu"
|
2022-04-24 05:03:32 +00:00
|
|
|
import "Saws"
|
2022-04-27 02:40:39 +00:00
|
|
|
import "Editor"
|
2022-04-22 18:48:45 +00:00
|
|
|
|
2022-04-23 06:54:45 +00:00
|
|
|
mode = "menu"
|
2022-05-12 22:04:00 +00:00
|
|
|
map = "data/saw.rocketbyte"
|
2022-04-19 21:32:18 +00:00
|
|
|
|
2022-05-07 20:31:34 +00:00
|
|
|
deaths = 0
|
2022-05-15 00:31:57 +00:00
|
|
|
energy = 0
|
|
|
|
totalEnergy = 0
|
|
|
|
|
|
|
|
showEnergy = false
|
2022-05-07 20:31:34 +00:00
|
|
|
|
2022-04-22 18:02:47 +00:00
|
|
|
local gfx <const> = playdate.graphics
|
2022-04-19 21:32:18 +00:00
|
|
|
local disp <const> = playdate.display
|
2022-04-23 05:50:57 +00:00
|
|
|
local font <const> = gfx.font.new("gfx/big")
|
2022-05-15 00:31:57 +00:00
|
|
|
small = gfx.font.new("gfx/font(1)")
|
2022-04-22 18:48:45 +00:00
|
|
|
|
2022-05-15 00:31:57 +00:00
|
|
|
dev = false
|
2022-05-07 20:31:34 +00:00
|
|
|
|
2022-04-17 19:27:36 +00:00
|
|
|
gfx.setFont(font)
|
|
|
|
gfx.setBackgroundColor(gfx.kColorBlack)
|
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
song = playdate.sound.fileplayer.new("sfx/song1")
|
2022-05-12 22:04:00 +00:00
|
|
|
song:setVolume(0)
|
2022-05-14 16:34:53 +00:00
|
|
|
song:setVolume(0.5,0.5, 1)
|
2022-04-27 02:40:39 +00:00
|
|
|
song:play(0)
|
|
|
|
|
2022-05-15 00:31:57 +00:00
|
|
|
local imgSkull = gfx.image.new("gfx/skullEmoji")
|
|
|
|
local imgLightning = gfx.image.new("gfx/lightning")
|
|
|
|
assert(imgSkull)
|
|
|
|
assert(imgLightning)
|
2022-04-17 19:27:36 +00:00
|
|
|
|
2022-04-22 18:48:45 +00:00
|
|
|
gfx.setColor(gfx.kColorWhite)
|
2022-04-23 05:50:57 +00:00
|
|
|
-- {"START NEW GAME","CONTINUE","USER LEVELS", "EXIT"}
|
2022-04-23 21:48:23 +00:00
|
|
|
|
2022-04-24 03:25:48 +00:00
|
|
|
mainMenuCreation()
|
|
|
|
|
2022-04-23 05:50:57 +00:00
|
|
|
createMenu(mainmenu)
|
2022-04-22 18:48:45 +00:00
|
|
|
|
2022-04-23 06:54:45 +00:00
|
|
|
local menu = playdate.getSystemMenu()
|
2022-05-12 22:04:00 +00:00
|
|
|
local menuButton, error = menu:addMenuItem("Game Menu", function()
|
2022-05-07 20:31:34 +00:00
|
|
|
if mode == "game" then
|
|
|
|
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
|
|
|
|
end
|
2022-05-15 00:31:57 +00:00
|
|
|
totalEnergy = 0
|
|
|
|
showEnergy = false
|
|
|
|
energy = 0
|
2022-04-23 21:48:23 +00:00
|
|
|
mainMenuCreation()
|
2022-04-23 06:54:45 +00:00
|
|
|
createMenu(mainmenu)
|
|
|
|
end)
|
2022-04-17 19:27:36 +00:00
|
|
|
|
2022-05-12 22:04:00 +00:00
|
|
|
local devButton, error = menu:addCheckmarkMenuItem("dev stats", false, function(value)
|
|
|
|
dev = value
|
|
|
|
end)
|
|
|
|
|
2022-04-23 21:48:23 +00:00
|
|
|
--addMap("levels/level.json")
|
2022-04-17 19:27:36 +00:00
|
|
|
|
2022-05-12 22:04:00 +00:00
|
|
|
playdate.ui.crankIndicator:start()
|
|
|
|
|
2022-05-15 00:31:57 +00:00
|
|
|
function playdate.keyPressed(key)
|
|
|
|
if key == "D" then
|
|
|
|
dev = not dev
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-19 21:22:15 +00:00
|
|
|
function playdate.update()
|
2022-04-22 18:48:45 +00:00
|
|
|
if mode == "menu" then
|
|
|
|
updateMenu()
|
2022-04-17 19:27:36 +00:00
|
|
|
|
2022-05-07 20:31:34 +00:00
|
|
|
elseif mode == "game" or mode == "play" then
|
2022-05-14 16:34:53 +00:00
|
|
|
song:setVolume(0.5)
|
2022-04-22 18:48:45 +00:00
|
|
|
updatePlayer()
|
|
|
|
gfx.sprite.update()
|
2022-05-09 04:31:57 +00:00
|
|
|
|
2022-05-07 20:31:34 +00:00
|
|
|
local ox, oy = gfx.getDrawOffset()
|
2022-05-15 00:31:57 +00:00
|
|
|
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
|
2022-05-12 22:04:00 +00:00
|
|
|
|
|
|
|
if playdate.isCrankDocked() then
|
|
|
|
playdate.ui.crankIndicator:update()
|
|
|
|
end
|
|
|
|
|
2022-04-27 02:40:39 +00:00
|
|
|
elseif mode == "newproj" then
|
|
|
|
gfx.clear()
|
|
|
|
updateNewproj()
|
2022-04-22 18:48:45 +00:00
|
|
|
end
|
2022-05-07 20:31:34 +00:00
|
|
|
if dev then
|
|
|
|
local ox, oy = gfx.getDrawOffset()
|
2022-05-15 00:31:57 +00:00
|
|
|
playdate.drawFPS(0,228)
|
|
|
|
small:drawText(math.floor( playdate.getCrankPosition() ), -ox, -oy + 218)
|
2022-05-07 20:31:34 +00:00
|
|
|
end
|
2022-04-24 18:15:38 +00:00
|
|
|
updateSaws()
|
2022-05-07 20:31:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function playdate.gameWillTerminate()
|
|
|
|
if mode == "game" then
|
|
|
|
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
|
|
|
|
end
|
2022-04-17 19:27:36 +00:00
|
|
|
end
|