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