moving asteroids

This commit is contained in:
Donald Ball 2025-11-14 16:33:24 -05:00
parent 5e47a5773c
commit 3ba30a2fb1

View file

@ -13,6 +13,24 @@ function love.load()
bullets = {}
bulletTimerLimit = 0.5
bulletTimer = bulletTimerLimit
asteroids = {
{
x = 100,
y = 100,
},
{
x = arenaWidth - 100,
y = 100,
},
{
x = arenaWidth / 2,
y = arenaHeight - 100,
}
}
for asteroidIndex, asteroid in ipairs(asteroids) do
asteroid.angle = love.math.random() * (2 * math.pi)
end
end
function love.update(dt)
@ -58,6 +76,12 @@ function love.update(dt)
})
end
end
for asteroidIndex, asteroid in ipairs(asteroids) do
local asteroidSpeed = 20
asteroid.x = (asteroid.x + math.cos(asteroid.angle) * asteroidSpeed * dt) % arenaWidth
asteroid.y = (asteroid.y + math.cos(asteroid.angle) * asteroidSpeed * dt) % arenaHeight
end
end
function love.draw()
@ -80,6 +104,11 @@ function love.draw()
love.graphics.setColor(0, 1, 0)
love.graphics.circle('fill', bullet.x, bullet.y, 5)
end
for asteroidIndex, asteroid in ipairs(asteroids) do
love.graphics.setColor(1, 1, 0)
love.graphics.circle('fill', asteroid.x, asteroid.y, 80)
end
end
end