Rocket-Bytes/Source/Cutscenes.lua
2022-07-20 19:54:15 -06:00

172 lines
No EOL
5 KiB
Lua

local gfx <const> = playdate.graphics
local imgBigRocket = gfx.image.new("gfx/bigrocket")
local tabBigRocket = gfx.imagetable.new("gfx/bigrocketfire")
local tabSmallRocket = gfx.imagetable.new("gfx/fire")
assert(imgBigRocket)
assert(tabBigRocket)
assert(tabSmallRocket)
local shake = 0
local animBigRocket = gfx.animation.loop.new(200,tabBigRocket)
local animRocket = gfx.animation.loop.new(200,tabSmallRocket)
local sprCutsceneBigRocket = gfx.sprite.new(tabBigRocket[1])
sprCutsceneBigRocket:setRotation(90)
-- cutscene 1
local gotoGame = false
local showFuelMeter = false
local transfer = true
local fuelshowncount = -1
local scene1Blip = playdate.sound.sampleplayer.new("sfx/cutsceneblip")
scene1Blip:setVolume(0.7)
local scene1Explosion = playdate.sound.sampleplayer.new("sfx/cutsceneexplosion")
local fuelTimer
function beginStartCutscene(_gotoGame)
mode = "startCutscene"
fuelshowncount = -1
gotoGame = _gotoGame
--sprCutsceneBigRocket:moveTo(51,120)
sprCutsceneBigRocket:moveTo(-sprCutsceneBigRocket.height,120)
transfer = true
sprCutsceneBigRocket:setScale(1.5)
sprCutsceneBigRocket:add()
playdate.timer.new(1000, function()
local brAnimator = gfx.animator.new(4000, playdate.geometry.point.new(-sprCutsceneBigRocket.height,120),playdate.geometry.point.new(200,120), playdate.easingFunctions.outQuad)
sprCutsceneBigRocket:setAnimator(brAnimator)
end
)
createStars(-10)
end
function updateStartCutscene()
playdate.timer.updateTimers()
gfx.clear()
gfx.setDrawOffset(math.random(-3,3)*shake,math.random(-3,3)*shake)
sprCutsceneBigRocket:setImage(animBigRocket:image())
gfx.sprite.update()
processStars(-10,-10)
processExplosions()
if fuelshowncount == -1 and sprCutsceneBigRocket.x == 200 then
fuelshowncount = 0
fuelTimer = playdate.timer.new(500, function ()
fuelshowncount+=1
showFuelMeter = not showFuelMeter
if showFuelMeter then scene1Blip:play() end
end)
fuelTimer.repeats = true
fuelTimer:reset()
fuelTimer:start()
end
if fuelshowncount == 5 then -- when the fuel blinking is done
fuelTimer.repeats = false
fuelshowncount = 6
local dietimer = playdate.timer.new(1000, function ()
explode(200,120)
shake = 3
showFuelMeter =false
song:stop()
scene1Explosion:play()
local falltimer = playdate.timer.new(700, function ()
local a = gfx.animator.new(3000, playdate.geometry.point.new(200,120),playdate.geometry.point.new(200,240+sprCutsceneBigRocket.width),playdate.easingFunctions.inBack)
sprCutsceneBigRocket:setAnimator(a)
end)
end)
end
if sprCutsceneBigRocket.y == 240+sprCutsceneBigRocket.width and transfer then
transfer = false
local gametimer = playdate.timer.new(1000,function ()
if gotoGame then
map = "data/1. HOOK.json"
addMapSave("data/1. HOOK.json")
else
createMenu(mainmenu)
song:play(0)
end
applyStarSpeed(10,0)
end)
end
if showFuelMeter then
gfx.setLineWidth(2)
gfx.setColor(gfx.kColorWhite)
gfx.drawRect(194,35,70,10)
gfx.drawText("FUEL",131,32)
end
if shake > 0 then shake -= .1 elseif shake < 0 then shake = 0 end
end
-- end custscene
local imgEndPlatform = gfx.image.new("gfx/endplatform")
assert(imgEndPlatform)
local scene = 1
local platformY = -imgEndPlatform.height
local endRocketY = 0
function beginEndCutscene()
mode = "endCutscene"
song:stop()
song:load("sfx/song4")
playdate.timer.new(3200, function ()
scene = 2
end)
playdate.timer.new(9600, function ()
shake = 5
scene = 3
applyStarSpeed(0,5)
end)
playdate.timer.new(16000, function ()
applyStarSpeed(0,5)
scene = 4
shake = 3
explode(200,150)
end)
song:play()
end
function processEndCutscene()
playdate.timer.updateTimers()
gfx.clear()
gfx.setDrawOffset(math.random(-3,3)*shake,math.random(-3,3)*shake)
processStars(-10,-10)
if scene == 2 then
platformY = playdate.math.lerp(platformY,130,0.1)
endRocketY = platformY-imgBigRocket.height*1.5
imgBigRocket:drawScaled(200-imgBigRocket.width*0.75,endRocketY,1.5)
imgEndPlatform:draw(0,platformY)
elseif scene == 3 then
animBigRocket:image():drawScaled(200-imgBigRocket.width*0.75,endRocketY,1.5)
endRocketY = playdate.math.lerp(endRocketY, 120 - (imgBigRocket.width *0.75),0.1)
if platformY ~= 280 then
platformY = playdate.math.lerp(platformY,280,0.05)
imgEndPlatform:draw(0,platformY)
end
elseif scene == 4 then
animBigRocket:image():drawScaled(200-imgBigRocket.width*0.75,120-imgBigRocket.height*0.75,1.5)
end
if shake > 0 then shake -= .1 elseif shake < 0 then shake = 0 end
processExplosions()
end