2022-10-13 16:06:52 +02:00
GameScene = Object.extend ( Object )
function GameScene : new ( )
end
function GameScene : init ( )
2022-10-13 18:18:27 +02:00
GameScene : playerChanged ( currentPlayer )
movementDelta = 0
2022-10-13 19:34:18 +02:00
2022-10-15 17:39:32 +02:00
love.audio . setPosition ( windowWidth / 2 , windowHeight / 2 , 0 )
2022-10-13 19:34:18 +02:00
pSystem = love.graphics . newParticleSystem ( boosterParticle , 128 )
pSystem : setParticleLifetime ( 0 , 0.6 )
pSystem : setLinearAcceleration ( 0 , 20 , 0 , 25 )
pSystem : setSpeed ( 40 , 50 )
pSystem : setRotation ( 10 , 20 )
pSystem : setSpin ( 10 , 20 )
pSystem : setRadialAcceleration ( 10 , 20 )
pSystem : setTangentialAcceleration ( 10 , 20 )
pSystem : setSizeVariation ( 0.3 )
pSystem : setSizes ( 1 , 0.9 , 0.8 , 0.7 , 0.5 , 0.3 , 0.1 , 0.05 )
pSystem : setColors (
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 0.8 ,
1 , 1 , 1 , 0.6 ,
1 , 1 , 1 , 0.5 ,
1 , 1 , 1 , 0.4 ,
1 , 1 , 1 , 0.3
)
2022-10-13 20:59:14 +02:00
2022-10-15 17:39:32 +02:00
eSystem = love.graphics . newParticleSystem ( explosionParticle , 64 )
eSystem : setParticleLifetime ( 0 , 0.7 )
eSystem : setLinearAcceleration ( - 2 , - 2 , 2 , 2 )
eSystem : setSpeed ( 2 , 8 )
eSystem : setRotation ( 1 , 7 )
eSystem : setSpin ( 1 , 2 )
eSystem : setRadialAcceleration ( 10 , 20 )
eSystem : setTangentialAcceleration ( 10 , 20 )
eSystem : setSizeVariation ( 0.9 )
eSystem : setSizes ( 0.1 , 0.2 , 0.4 , 0.6 , 0.8 , 1.0 , 0.6 , 0.1 )
eSystem : setColors (
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 ,
1 , 1 , 1 , 0.8 ,
1 , 1 , 1 , 0.6 ,
1 , 1 , 1 , 0.4 ,
1 , 1 , 1 , 0.3
)
GameScene.explosionObj = { angle = 100 , radius = 100 }
GameScene.godsrayObj = { weight = 0 }
2022-10-13 20:59:14 +02:00
currentPlanet : init ( )
currentPlanet : draw ( )
2022-10-13 16:06:52 +02:00
end
function GameScene : update ( dt )
2022-10-13 20:59:14 +02:00
2022-10-15 17:39:32 +02:00
if currentPlayer.death == false and currentPlanet.hasGeneratedMap == true then
pSystem : update ( dt )
GameScene : updateInput ( dt )
GameScene : updateBounds ( dt )
GameScene : checkCollisions ( )
else
eSystem : update ( dt )
2022-10-13 20:59:14 +02:00
end
2022-10-15 17:39:32 +02:00
currentPlanet : update ( dt )
self.updateEffects ( ) ;
2022-10-13 16:06:52 +02:00
end
function GameScene : draw ( )
2022-10-15 17:39:32 +02:00
love.graphics . setColor ( 1 , 1 , 1 , 1 )
2022-10-13 20:59:14 +02:00
if currentPlanet ~= nil and currentPlanet.canvas ~= nil then
love.graphics . draw ( currentPlanet.canvas , 0 , 0 )
end
2022-10-15 17:39:32 +02:00
if currentPlayer.death == false then
love.graphics . setColor ( 1 , 1 , 1 , 1 )
love.graphics . draw ( pSystem , currentPlayer.px - 2 , currentPlayer.py )
love.graphics . draw ( pSystem , currentPlayer.px + 2 , currentPlayer.py )
love.graphics . draw (
currentPlayer.ship . image ,
currentPlayer.px ,
currentPlayer.py ,
currentPlayer.rot * ( math.pi / 180 ) ,
1 , 1 ,
currentPlayer.ship . image : getWidth ( ) / 2 ,
currentPlayer.ship . image : getHeight ( ) / 2
)
else
love.graphics . draw ( eSystem , currentPlayer.px , currentPlayer.py )
end
2022-10-13 16:06:52 +02:00
end
function GameScene : drawHud ( )
2022-10-15 17:39:32 +02:00
love.graphics . setColor ( 1 , 1 , 1 , 1 )
2022-10-13 16:06:52 +02:00
love.graphics . draw ( gameHud , 0 , 600 - 66 )
love.graphics . setColor ( 255 , 255 , 255 , 0.75 )
2022-10-13 18:18:27 +02:00
love.graphics . draw ( currentPlayer.image , 14 , 550 , 0 , 0.5 , 0.5 )
2022-10-13 16:06:52 +02:00
love.graphics . setColor ( text.r , text.g , text.b , text.alpha )
love.graphics . print ( currentPlayer.name , 48 , 550 )
2022-10-13 18:18:27 +02:00
love.graphics . print ( currentPlayer : getShipname ( ) , 48 , 566 )
2022-10-13 16:06:52 +02:00
2022-10-15 17:39:32 +02:00
love.graphics . print (
" glbl: " .. currentPlayer.px .. " , " .. currentPlayer.py .. " s: " .. currentPlayer.ship . speed .. " a: " .. currentPlayer.acc ,
10 , 10
)
local deathval = " 0 "
if currentPlayer.death then
deathval = " 1 "
end
love.graphics . print ( " death: " .. deathval , 10 , 24 )
2022-10-13 16:06:52 +02:00
end
function GameScene : keypressed ( key , unicode )
if key == " 1 " then
2022-10-13 18:18:27 +02:00
GameScene : playerChanged ( CaptainSteve )
2022-10-13 16:06:52 +02:00
elseif key == " 2 " then
2022-10-13 18:18:27 +02:00
GameScene : playerChanged ( CaptainRobert )
2022-10-13 16:06:52 +02:00
elseif key == " 3 " then
2022-10-13 18:18:27 +02:00
GameScene : playerChanged ( CaptainJohn )
2022-10-13 16:06:52 +02:00
end
end
2022-10-13 18:18:27 +02:00
function GameScene : playerChanged ( to )
currentPlayer = to
2022-10-15 17:39:32 +02:00
currentPlayer.px = math.floor ( windowWidth / 2 )
currentPlayer.py = math.floor ( windowHeight / 2 )
2022-10-13 18:18:27 +02:00
currentPlayer.rot = 0
currentPlayer.acc = 0
2022-10-13 19:34:18 +02:00
currentPlayer.bounds = { x1 = 20 , y1 = 20 , x2 = windowWidth - 20 , y2 = windowHeight - 86 }
2022-10-15 17:39:32 +02:00
currentPlayer.death = false
2022-10-13 18:18:27 +02:00
end
function GameScene : updateInput ( dt )
movementDelta = movementDelta + dt
if ( movementDelta > 0.02 ) then
movementDelta = 0
local isUp = false
local isLeft = false
local isDown = false
local isRight = false
--local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1)
--local axisMargin = 0.5
isUp = love.keyboard . isDown ( " w " ) -- or (not (vAxis == nil) and vAxis < -(1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 1)
isDown = love.keyboard . isDown ( " s " ) -- or (not (vAxis == nil) and vAxis > (1-axisMargin)) or (not (vAxis2 == nil) and vAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 2)
isLeft = love.keyboard . isDown ( " a " ) -- or (not (hAxis == nil) and hAxis < -(1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 < -(1-axisMargin)) or love.joystick.isDown(1, 3)
isRight = love.keyboard . isDown ( " d " ) -- or (not (hAxis == nil) and hAxis > (1-axisMargin)) or (not (hAxis2 == nil) and hAxis2 > (1-axisMargin)) or love.joystick.isDown(1, 4)
if isUp and isLeft then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 315
particleRot = 45
2022-10-13 18:18:27 +02:00
elseif isUp and isRight then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 45
particleRot = 135
2022-10-13 18:18:27 +02:00
elseif isUp then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 0
particleRot = 90
2022-10-13 18:18:27 +02:00
elseif isDown and isLeft then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 225
particleRot = 315
2022-10-13 18:18:27 +02:00
elseif isDown and isRight then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 135
particleRot = 225
2022-10-13 18:18:27 +02:00
elseif isDown then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 180
particleRot = 270
2022-10-13 18:18:27 +02:00
elseif isLeft then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 270
particleRot = 0
2022-10-13 18:18:27 +02:00
elseif isRight then
2022-10-13 19:34:18 +02:00
currentPlayer.rot = 90
particleRot = 180
2022-10-13 18:18:27 +02:00
end
if isUp or isDown or isLeft or isRight then
2022-10-15 17:39:32 +02:00
currentPlayer.acc = currentPlayer.acc + currentPlayer.ship . accIncr
2022-10-13 18:18:27 +02:00
elseif currentPlayer.acc > 0 then
2022-10-15 17:39:32 +02:00
currentPlayer.acc = currentPlayer.acc - currentPlayer.ship . accIncr
2022-10-13 18:18:27 +02:00
end
currentPlayer.acc = math.clamp ( 0 , currentPlayer.acc , 1 )
2022-10-13 19:34:18 +02:00
if currentPlayer.acc > 0 then
pSystem : setDirection ( particleRot * ( math.pi / 180 ) )
pSystem : emit ( 64 * currentPlayer.acc )
end
2022-10-13 18:18:27 +02:00
if isUp then
2022-10-15 17:39:32 +02:00
currentPlayer.py = math.floor ( currentPlayer.py - ( currentPlayer.ship . speed * currentPlayer.acc ) )
2022-10-13 18:18:27 +02:00
end
if isDown then
2022-10-15 17:39:32 +02:00
currentPlayer.py = math.floor ( currentPlayer.py + ( currentPlayer.ship . speed * currentPlayer.acc ) )
2022-10-13 18:18:27 +02:00
end
if isLeft then
2022-10-15 17:39:32 +02:00
currentPlayer.px = math.floor ( currentPlayer.px - ( currentPlayer.ship . speed * currentPlayer.acc ) )
2022-10-13 18:18:27 +02:00
end
if isRight then
2022-10-15 17:39:32 +02:00
currentPlayer.px = math.floor ( currentPlayer.px + ( currentPlayer.ship . speed * currentPlayer.acc ) )
2022-10-13 18:18:27 +02:00
end
end
end
function GameScene : updateBounds ( dt )
2022-10-15 17:39:32 +02:00
currentPlayer.px = math.floor ( math.clamp ( currentPlayer.bounds . x1 , currentPlayer.px , currentPlayer.bounds . x2 ) )
currentPlayer.py = math.floor ( math.clamp ( currentPlayer.bounds . y1 , currentPlayer.py , currentPlayer.bounds . y2 ) )
end
function GameScene : checkCollisions ( )
-- Get basic alpha blended collision
local cp = currentPlanet.canvas : newImageData ( nil , nil , currentPlayer.px , currentPlayer.py , 1 , 1 ) : getPixel ( 0 , 0 )
if cp == 0 then
currentPlayer.death = true
self : generateExplosion ( currentPlayer.px , currentPlayer.py )
end
end
function GameScene : generateExplosion ( px , py )
GameScene : generateExplosionSound ( px , py )
GameScene.explosionObj = { angle = 100 , radius = 100 }
GameScene.godsrayObj = { weight = 0 }
2022-10-15 17:45:43 +02:00
flux.to ( GameScene.explosionObj , 0.5 , { angle = GameScene : variance ( 100 , 90 ) , radius = GameScene : variance ( 1600 , 150 ) } ) : ease ( " quintout " ) : after ( GameScene.explosionObj , 0.5 , { angle = 100 , radius = 100 } )
flux.to ( GameScene.godsrayObj , 0.5 , { weight = GameScene : variance ( 100 , 50 ) } ) : ease ( " quintout " ) : after ( GameScene.godsrayObj , 0.5 , { weight = 1 } )
2022-10-15 17:39:32 +02:00
eSystem : emit ( 32 )
end
function GameScene : updateEffects ( )
effect.chromasep . angle = math.floor ( GameScene.explosionObj . angle / 100 )
effect.chromasep . radius = math.floor ( GameScene.explosionObj . radius / 100 )
effect.godsray . weight = GameScene.godsrayObj . weight / 100
end
function GameScene : generateExplosionSound ( px , py )
local sound = sfxr.newSound ( )
sound : resetParameters ( )
sound.waveform = sfxr.WAVEFORM . NOISE
sound.frequency . start = GameScene : variance ( 0.19907648104897 , 150 )
sound.frequency . slide = - 0.057634852747835
sound.repeatspeed = 0
sound.envelope . attack = 0
sound.envelope . sustain = GameScene : variance ( 0.30484231377123 , 150 )
sound.envelope . punch = GameScene : variance ( 0.7393770288859 , 150 )
sound.envelope . decay = 0.43495283918775
sound.phaser . offset = GameScene : variance ( 0.53418301267674 , 150 )
sound.phaser . sweep = - 0.26648187020582
sound.vibrato . depth = GameScene : variance ( 0.24860915303688 , 150 )
sound.vibrato . speed = 0.44703997451237
sound.change . speed = 0.83105037145914
sound.change . amount = - 0.66873272021076
local soundData = sound : generateSoundData ( )
local source = love.audio . newSource ( soundData )
source : setVolume ( 2 )
source : setPosition ( px , py )
source : play ( )
end
function GameScene : variance ( seed , variance )
return seed * ( ( math.random ( 100 - ( variance / 2 ) , 100 + ( variance / 2 ) ) ) / 100 )
2022-10-13 18:18:27 +02:00
end