Improve missile spawning
This commit is contained in:
parent
17efb22113
commit
29d65a9cf2
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue