Need some help with particle systems and things
Posted: Mon Apr 20, 2015 12:15 am
I've been messing around with making a game, simple space. Heres what I have:
This is what happens:
[youtube]https://www.youtube.com/watch?v=1j9WyrvdZx8[/youtube]
Code: Select all
player = {}
player.x = 400
player.y = 400
player.r = 0
player.image = nil
player.rspeed = 2
player.speed = 100
particles = {}
particles.fire = {}
particles.fire.buffer = 32
particles.fire.system = nil
function love.load()
love.graphics.setBackgroundColor( 50, 50, 50)
player.image = love.graphics.newImage("player.png")
particles.fire.image = love.graphics.newImage("fire.png")
particles.fire.system = love.graphics.newParticleSystem(particles.fire.image, particles.fire.buffer);
particles.fire.system:setParticleLifetime(2, 3); -- Particles live at least 2s and at most 5s.
particles.fire.system:setEmissionRate(5);
particles.fire.system:setSizeVariation(1);
particles.fire.system:setLinearAcceleration(-20, 0, 0, 0); -- Random movement in all directions.
end
function love.update(dt)
particles.fire.system:update(dt);
if love.keyboard.isDown('up') then
player.x = player.x + math.cos(player.r) * player.speed * dt
player.y = player.y + math.sin(player.r) * player.speed * dt
end
if love.keyboard.isDown('down') then
player.x = player.x - math.cos(player.r) * player.speed * dt
player.y = player.y - math.sin(player.r) * player.speed * dt
end
if love.keyboard.isDown('left') then
player.r = player.r - player.rspeed * dt
end
if love.keyboard.isDown('right') then
player.r = player.r + player.rspeed * dt
end
end
function love.draw(dt)
love.graphics.draw(player.image, player.x, player.y, player.r, 1, 1, 32, 27)
love.graphics.draw(particles.fire.system, player.x - 8, player.y - 16, player.r);
end
[youtube]https://www.youtube.com/watch?v=1j9WyrvdZx8[/youtube]