moving bullets

This commit is contained in:
Donald Ball 2025-11-13 16:29:57 -05:00
parent b692e75773
commit 0dbf971a79

View file

@ -13,15 +13,6 @@ function love.load()
bullets = {} bullets = {}
end end
function love.keypressed(key)
if key == 's' then
table.insert(bullets, {
x = shipX + math.cos(shipAngle) * shipRadius,
y = shipY + math.sin(shipAngle) * shipRadius,
})
end
end
function love.update(dt) function love.update(dt)
local turnSpeed = 10 local turnSpeed = 10
if love.keyboard.isDown('right') then if love.keyboard.isDown('right') then
@ -40,6 +31,22 @@ 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
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
function love.keypressed(key)
if key == 's' then
table.insert(bullets, {
x = shipX + math.cos(shipAngle) * shipRadius,
y = shipY + math.sin(shipAngle) * shipRadius,
angle = shipAngle,
})
end
end end
function love.draw() function love.draw()