particles

This commit is contained in:
Martijn de Boer 2022-10-13 19:34:18 +02:00
parent e355e5d3fe
commit 5d6c97d086
No known key found for this signature in database
GPG key ID: 9D2E42402DD372D1
3 changed files with 49 additions and 13 deletions

View file

@ -7,7 +7,8 @@ multilily = lily.loadMulti({
{lily.newImage, "assets/captains/john-danger.png"},
{lily.newImage, "assets/ships/blackstar-5.png"},
{lily.newImage, "assets/ships/excalibur-iv.png"},
{lily.newImage, "assets/ships/decorator.png"}
{lily.newImage, "assets/ships/decorator.png"},
{lily.newImage, "assets/ships/particle.png"}
})
multilily:onComplete(function(_, lilies)
gameLogo = lilies[1][1]
@ -19,6 +20,7 @@ multilily:onComplete(function(_, lilies)
CaptainSteve.ship.image = lilies[7][1]
CaptainRobert.ship.image = lilies[8][1]
CaptainJohn.ship.image = lilies[9][1]
boosterParticle = lilies[10][1]
windowWidth = love.graphics.getWidth()
windowHeight = love.graphics.getHeight()

BIN
assets/ships/particle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

View file

@ -6,15 +6,39 @@ end
function GameScene:init()
GameScene:playerChanged(currentPlayer)
movementDelta = 0
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
)
end
function GameScene:update(dt)
pSystem:update(dt)
GameScene:updateInput(dt)
GameScene:updateBounds(dt)
end
function GameScene:draw()
love.graphics.setColor(255,255,255, 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,
@ -58,7 +82,7 @@ function GameScene:playerChanged(to)
currentPlayer.py = windowHeight/2
currentPlayer.rot = 0
currentPlayer.acc = 0
currentPlayer.bounds = { x1= 20, y1= 20, x2= windowWidth-30, y2= windowHeight - 86}
currentPlayer.bounds = { x1= 20, y1= 20, x2= windowWidth-20, y2= windowHeight - 86}
end
function GameScene:updateInput(dt)
@ -70,7 +94,6 @@ function GameScene:updateInput(dt)
local isLeft = false
local isDown = false
local isRight = false
local rotation = 0
--local hAxis, vAxis, hAxis2, vAxis2 = love.joystick.getAxes(1)
--local axisMargin = 0.5
@ -81,25 +104,31 @@ function GameScene:updateInput(dt)
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
rotation = 315
currentPlayer.rot = 315
particleRot = 45
elseif isUp and isRight then
rotation = 45
currentPlayer.rot = 45
particleRot = 135
elseif isUp then
rotation = 0
currentPlayer.rot = 0
particleRot = 90
elseif isDown and isLeft then
rotation = 225
currentPlayer.rot = 225
particleRot = 315
elseif isDown and isRight then
rotation = 135
currentPlayer.rot = 135
particleRot = 225
elseif isDown then
rotation = 180
currentPlayer.rot = 180
particleRot = 270
elseif isLeft then
rotation = 270
currentPlayer.rot = 270
particleRot = 0
elseif isRight then
rotation = 90
currentPlayer.rot = 90
particleRot = 180
end
currentPlayer.rot = rotation
if isUp or isDown or isLeft or isRight then
currentPlayer.acc = currentPlayer.acc + currentPlayer.accIncr
elseif currentPlayer.acc > 0 then
@ -108,6 +137,11 @@ function GameScene:updateInput(dt)
currentPlayer.acc = math.clamp(0, currentPlayer.acc, 1)
if currentPlayer.acc > 0 then
pSystem:setDirection(particleRot*(math.pi/180))
pSystem:emit( 64 * currentPlayer.acc )
end
if isUp then
currentPlayer.py = currentPlayer.py - (currentPlayer.speed*currentPlayer.acc)
end