Have explosions destroy things
This commit is contained in:
parent
f09fb27a11
commit
38ecbee541
|
@ -98,6 +98,7 @@ function spawnExplosion(x, y)
|
|||
table.insert(explosions, {
|
||||
x = x,
|
||||
y = y,
|
||||
radius = 0,
|
||||
remaining = explosion_duration,
|
||||
})
|
||||
end
|
||||
|
@ -145,10 +146,9 @@ function updateMissiles(dt)
|
|||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if city.alive and distance < city_radius then
|
||||
spawnExplosion(missile.x, missile.y)
|
||||
-- Destroy city
|
||||
city.alive = false
|
||||
-- Destroy missile
|
||||
missile.alive = false
|
||||
-- Freeze the missile in-place
|
||||
missile.dx = 0
|
||||
missile.dy = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -178,8 +178,36 @@ end
|
|||
function updateExplosions(dt)
|
||||
local i = 1
|
||||
while i <= #explosions do
|
||||
explosions[i].remaining = explosions[i].remaining - dt
|
||||
if explosions[i].remaining < 0 then
|
||||
local explosion = explosions[i]
|
||||
|
||||
local completeness = (explosion_duration - explosion.remaining) / explosion_duration
|
||||
explosion.radius = completeness ^ 1.5 * explosion_radius
|
||||
|
||||
-- Destroy missiles within range
|
||||
for _, missile in ipairs(missiles) do
|
||||
local dx = missile.x - explosion.x
|
||||
local dy = missile.x - explosion.x
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius then
|
||||
missile.alive = false
|
||||
end
|
||||
end
|
||||
|
||||
explosion.remaining = explosion.remaining - dt
|
||||
|
||||
if explosion.remaining < explosion_duration * 0.2 then
|
||||
-- Destroy cities within range
|
||||
for _, city in ipairs(cities) do
|
||||
local dx = city.x - explosion.x
|
||||
local dy = city.x - explosion.x
|
||||
local distance = math.sqrt(dx * dx + dy * dy)
|
||||
if distance < explosion.radius + city_radius then
|
||||
city.alive = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if explosion.remaining < 0 then
|
||||
table.remove(explosions, i)
|
||||
else
|
||||
i = i + 1
|
||||
|
@ -273,10 +301,9 @@ end
|
|||
|
||||
function drawExplosions()
|
||||
for _, explosion in ipairs(explosions) do
|
||||
local completeness = (explosion_duration - explosion.remaining) / explosion_duration
|
||||
love.graphics.setColor(1, 0, 0)
|
||||
local x, y = toScreenCoordinates(explosion.x, explosion.y)
|
||||
local radius = toScreenSize(completeness ^ 1.5 * explosion_radius)
|
||||
local radius = toScreenSize(explosion.radius)
|
||||
love.graphics.circle('fill', x, y, radius)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue