From 29d65a9cf2cd9af6139b7255c4bd902083dce4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Fri, 2 Jun 2023 16:32:53 +0300 Subject: [PATCH] Improve missile spawning --- bundle/main.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bundle/main.lua b/bundle/main.lua index 6b79bde..89c741f 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -52,8 +52,9 @@ function love.load() setScreenDimensions(width, height) movePaddle(0) spawnCities() - spawnMissile(0.5, 0.1, -0.1, -0.2) - spawnMissile(0.5, 0.1, 0.1, 0.1) + spawnMissile(0.5, 0.1, cities[3].x, cities[3].y, 0.2) + spawnMissile(0.1, 0.3, cities[7].x, cities[7].y, 0.2) + spawnMissile(0.1, 0.3, cities[3].x, cities[3].y, 0.1) end function spawnCities() @@ -71,7 +72,12 @@ function spawnCities() end end -function spawnMissile(x, y, dx, dy) +function spawnMissile(x, y, target_x, target_y, speed) + local dx = target_x - x + local dy = target_y - y + local length = math.sqrt(dx * dx + dy * dy) + local dx = dx / length * speed + local dy = dy / length * speed table.insert(missiles, { x = x, y = y,