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
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 16:06:52 +02:00
end
function GameScene : update ( dt )
2022-10-13 19:34:18 +02:00
pSystem : update ( dt )
2022-10-13 18:18:27 +02:00
GameScene : updateInput ( dt )
GameScene : updateBounds ( dt )
2022-10-13 16:06:52 +02:00
end
function GameScene : draw ( )
2022-10-13 18:18:27 +02:00
love.graphics . setColor ( 255 , 255 , 255 , 1 )
2022-10-13 19:34:18 +02:00
love.graphics . draw ( pSystem , currentPlayer.px - 2 , currentPlayer.py )
love.graphics . draw ( pSystem , currentPlayer.px + 2 , currentPlayer.py )
2022-10-13 18:18:27 +02:00
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
)
2022-10-13 16:06:52 +02:00
2022-10-13 18:18:27 +02:00
love.graphics . print ( currentPlayer.px .. " , " .. currentPlayer.py .. " s: " .. currentPlayer.speed .. " a: " .. currentPlayer.acc , 10 , 10 )
2022-10-13 16:06:52 +02:00
end
function GameScene : drawHud ( )
love.graphics . setColor ( 255 , 255 , 255 , 1 )
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
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
currentPlayer.px = windowWidth / 2
currentPlayer.py = windowHeight / 2
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-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
currentPlayer.acc = currentPlayer.acc + currentPlayer.accIncr
elseif currentPlayer.acc > 0 then
currentPlayer.acc = currentPlayer.acc - currentPlayer.accIncr
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
currentPlayer.py = currentPlayer.py - ( currentPlayer.speed * currentPlayer.acc )
end
if isDown then
currentPlayer.py = currentPlayer.py + ( currentPlayer.speed * currentPlayer.acc )
end
if isLeft then
currentPlayer.px = currentPlayer.px - ( currentPlayer.speed * currentPlayer.acc )
end
if isRight then
currentPlayer.px = currentPlayer.px + ( currentPlayer.speed * currentPlayer.acc )
end
end
end
function GameScene : updateBounds ( dt )
currentPlayer.px = math.clamp ( currentPlayer.bounds . x1 , currentPlayer.px , currentPlayer.bounds . x2 )
currentPlayer.py = math.clamp ( currentPlayer.bounds . y1 , currentPlayer.py , currentPlayer.bounds . y2 )
end