diff --git a/bundle/main.lua b/bundle/main.lua index 41e2bbe..fbe2216 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -10,8 +10,7 @@ local missile_radius = 0.005 local missile_trail_length = 7 local cities = {} -local city_width = 0.07 -local city_height = 0.05 +local city_radius = 0.05 local explosions = {} local explosion_radius = 0.05 @@ -66,7 +65,7 @@ function spawnCities() cities = {} for i = 1, number_of_cities do local city_x = ((i - 0.5) / number_of_cities) * (1 - 2*wall_thickness) + wall_thickness - local city_y = 1 - city_height/2 + local city_y = 1 table.insert(cities, { x = city_x, @@ -141,11 +140,10 @@ function updateMissiles(dt) 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 + local dx = city.x - missile.x + local dy = city.y - missile.y + 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 @@ -266,10 +264,9 @@ function drawCities() love.graphics.setColor(1, 1, 1) for _, city in ipairs(cities) do if city.alive then - local x, y = toScreenCoordinates(city.x - city_width/2, city.y - city_height/2) - local width = toScreenSize(city_width) - local height = toScreenSize(city_height) - love.graphics.rectangle('fill', x, y, width, height) + local x, y = toScreenCoordinates(city.x, city.y) + local radius = toScreenSize(city_radius) + love.graphics.circle('fill', x, y, radius) end end end