expiring bullets
This commit is contained in:
parent
0dbf971a79
commit
419f858b1b
1 changed files with 11 additions and 4 deletions
9
main.lua
9
main.lua
|
|
@ -32,12 +32,18 @@ function love.update(dt)
|
||||||
shipX = (shipX + shipSpeedX * dt) % arenaWidth
|
shipX = (shipX + shipSpeedX * dt) % arenaWidth
|
||||||
shipY = (shipY + shipSpeedY * dt) % arenaHeight
|
shipY = (shipY + shipSpeedY * dt) % arenaHeight
|
||||||
|
|
||||||
for bulletIndex, bullet in ipairs(bullets) do
|
for bulletIndex = #bullets, 1, -1 do
|
||||||
|
local bullet = bullets[bulletIndex]
|
||||||
|
bullet.timeLeft = bullet.timeLeft - dt
|
||||||
|
if bullet.timeLeft <= 0 then
|
||||||
|
table.remove(bullets, bulletIndex)
|
||||||
|
else
|
||||||
local bulletSpeed = 500
|
local bulletSpeed = 500
|
||||||
bullet.x = (bullet.x + math.cos(bullet.angle) * bulletSpeed * dt) % arenaWidth
|
bullet.x = (bullet.x + math.cos(bullet.angle) * bulletSpeed * dt) % arenaWidth
|
||||||
bullet.y = (bullet.y + math.sin(bullet.angle) * bulletSpeed * dt) % arenaHeight
|
bullet.y = (bullet.y + math.sin(bullet.angle) * bulletSpeed * dt) % arenaHeight
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function love.keypressed(key)
|
function love.keypressed(key)
|
||||||
if key == 's' then
|
if key == 's' then
|
||||||
|
|
@ -45,6 +51,7 @@ function love.keypressed(key)
|
||||||
x = shipX + math.cos(shipAngle) * shipRadius,
|
x = shipX + math.cos(shipAngle) * shipRadius,
|
||||||
y = shipY + math.sin(shipAngle) * shipRadius,
|
y = shipY + math.sin(shipAngle) * shipRadius,
|
||||||
angle = shipAngle,
|
angle = shipAngle,
|
||||||
|
timeLeft = 4,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue