Rocket-Bytes/Source/Main.lua

181 lines
4.4 KiB
Lua
Raw Normal View History

-- PossiblyAxolotl
-- Created May 10th, 2022
-- Rocket Bytes
2022-04-17 19:27:36 +00:00
import "CoreLibs/graphics"
import "CoreLibs/sprites"
2022-07-17 01:37:12 +00:00
import "CoreLibs/math"
import "CoreLibs/animation"
import "CoreLibs/animator"
import "CoreLibs/timer"
import "CoreLibs/easing"
import "CoreLibs/keyboard"
2022-04-24 03:25:48 +00:00
import "CoreLibs/ui"
import "Cutscenes"
import "Particles"
2022-06-20 05:56:43 +00:00
import "Musicbox"
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-15 05:42:52 +00:00
map = "data/level.rocketbyte"
2022-04-19 21:32:18 +00:00
2022-07-30 02:51:08 +00:00
function playdate.deviceDidUnlock()
if playdate.buttonIsPressed(playdate.kButtonDown) and playdate.buttonIsPressed(playdate.kButtonB) then
mode = "partTest"
end
end
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-05-15 05:42:52 +00:00
next = nil
local gfx <const> = playdate.graphics
2022-04-19 21:32:18 +00:00
local disp <const> = playdate.display
local font <const> = gfx.font.new("gfx/big")
local symbols <const> = gfx.font.new("gfx/symbols")
2022-04-22 18:48:45 +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-20 17:01:59 +00:00
song:setVolume(0.5)
--song:setVolume(0.5,0.5, 1)
2022-04-27 02:40:39 +00:00
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-24 03:25:48 +00:00
mainMenuCreation()
createMenu(mainmenu)
2022-04-22 18:48:45 +00:00
tutorial = nil
2022-04-23 06:54:45 +00:00
local menu = playdate.getSystemMenu()
2022-05-20 17:01:59 +00:00
menuButton, error = menu:addMenuItem("game menu", function()
2022-05-07 20:31:34 +00:00
if mode == "game" then
2022-05-22 02:06:58 +00:00
playdate.datastore.delete("savegame.json")
2022-05-07 20:31:34 +00:00
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
2022-08-01 06:58:11 +00:00
elseif mode == "editor" or page == -1 then
2022-05-20 17:01:59 +00:00
editClose()
2022-05-31 23:10:00 +00:00
song:play(0)
2022-07-30 02:51:08 +00:00
elseif mode == "startCutscene" or mode == "endCutscene" then
local ts = playdate.timer.allTimers()
song:stop()
song:load("sfx/song1")
createStars()
for i = 1, #ts, 1 do
ts[i]:remove()
end
song:play()
2022-05-31 23:10:00 +00:00
end
if mode =="game" or mode == "play" then
killPlayer()
removeMap()
2022-06-12 03:08:20 +00:00
killBlades()
2022-05-07 20:31:34 +00:00
end
2022-07-30 02:51:08 +00:00
if mode ~= "music"then
2022-06-28 23:30:32 +00:00
totalEnergy = 0
showEnergy = false
energy = 0
mainMenuCreation()
createMenu(mainmenu)
2022-07-23 20:42:51 +00:00
elseif mode == "music" then
2022-06-28 23:30:32 +00:00
song:stop()
paused = false
playbackRate = 1.0
createMenu(songlist)
end
2022-04-23 06:54:45 +00:00
end)
2022-04-17 19:27:36 +00:00
playdate.ui.crankIndicator:start()
if playdate.file.exists("levels") == false then
playdate.file.mkdir("levels")
end
2022-07-17 01:37:12 +00:00
if playdate.file.exists("levels/BONUS LEVEL 1.json") == false then
local data = json.decodeFile("bdata/bl1.json")
2022-07-17 01:37:12 +00:00
playdate.datastore.write(data,"levels/BONUS LEVEL 1")
data = json.decodeFile("bdata/bl2.json")
2022-07-17 01:37:12 +00:00
playdate.datastore.write(data,"levels/BONUS LEVEL 2")
data = json.decodeFile("bdata/bl3.json")
2022-07-17 01:37:12 +00:00
playdate.datastore.write(data,"levels/BONUS LEVEL 3")
end
2022-05-18 05:09:02 +00:00
2022-07-17 01:37:12 +00:00
song:play(0)
function playdate.update()
2022-04-22 18:48:45 +00:00
if mode == "menu" then
updateMenu()
processExplosions()
2022-07-30 02:51:08 +00:00
elseif mode == "partTest" then
testParts()
elseif mode == "startCutscene" or mode == "startCutsceneReplay" then
updateStartCutscene()
elseif mode == "endCutscene" then
processEndCutscene()
2022-06-20 05:56:43 +00:00
elseif mode == "music" then
updateBox()
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()
processStars(sprRocket.x-210,sprRocket.y-130)
processExplosions()
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
if playdate.isCrankDocked() then
playdate.ui.crankIndicator:update()
end
if tutorial then
symbols:drawText("AOu",-ox+2,-oy + 202)
end
2022-04-27 02:40:39 +00:00
elseif mode == "newproj" then
gfx.clear()
updateNewproj()
2022-05-20 17:01:59 +00:00
elseif mode == "editor" then
2022-05-22 02:06:58 +00:00
2022-05-20 17:01:59 +00:00
editUpdate()
if playdate.isCrankDocked() then
playdate.ui.crankIndicator:update()
end
2022-04-22 18:48:45 +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
2022-05-22 02:06:58 +00:00
playdate.datastore.delete("savegame.json")
2022-05-07 20:31:34 +00:00
playdate.datastore.write({savedLevel=map,savedDeaths=deaths},"savegame")
end
2022-05-22 17:27:01 +00:00
end
function playdate.debugDraw()
gfx.setDrawOffset(0,0)
gfx.drawText("DEBUG ON",0,220)
print(playdate.graphics.sprite.spriteCount())
end