Make cities destroyable
This commit is contained in:
parent
a2bbb127c3
commit
17efb22113
|
@ -80,7 +80,8 @@ function spawnMissile(x, y, dx, dy)
|
|||
reflected = false,
|
||||
history = {
|
||||
{x = x, y = y}
|
||||
}
|
||||
},
|
||||
alive = true
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -121,6 +122,19 @@ function updateMissiles(dt)
|
|||
collided = true
|
||||
end
|
||||
|
||||
for _, city in ipairs(cities) do
|
||||
local city_left = city.x - city_width/2
|
||||
local city_right = city.x + city_width/2
|
||||
local city_top = city.y - city_height/2
|
||||
local city_bottom = city.y + city_height/2
|
||||
if city.alive and city_left <= missile.x and missile.x <= city_right and city_top <= missile.y and missile.y <= city_bottom then
|
||||
-- Destroy city
|
||||
city.alive = false
|
||||
-- Destroy missile
|
||||
missile.alive = false
|
||||
end
|
||||
end
|
||||
|
||||
if collided then
|
||||
table.insert(missile.history, 1, {
|
||||
x = missile.x,
|
||||
|
@ -135,8 +149,8 @@ function updateMissiles(dt)
|
|||
|
||||
local i = 1
|
||||
while i <= #missiles do
|
||||
if missiles[i].y > 1 + missile_radius then
|
||||
-- Went off the bottom of the screen, delete
|
||||
if missiles[i].y > 1 + missile_radius or not missiles[i].alive then
|
||||
-- Went off the bottom of the screen or exploded, delete
|
||||
table.remove(missiles, i)
|
||||
else
|
||||
i = i +1
|
||||
|
|
Loading…
Reference in New Issue