Improve enemy shots

This commit is contained in:
Juhani Krekelä 2023-06-04 22:20:30 +03:00
parent bac76b95dc
commit d4d6584ef8
1 changed files with 19 additions and 3 deletions

View File

@ -367,10 +367,26 @@ function updateEnemies(dt)
if enemy.until_shoot < 0 then
enemy.until_shoot = enemy_min_shoot + math.random() * (enemy_max_shoot - enemy_min_shoot)
if unreflected_missiles < unreflected_missiles_allowed then
local target = cities[math.random(1, #cities)]
local inaccuracy = math.random() * 2 * enemy_inaccuracy - enemy_inaccuracy
local speed = missile_speed_min + math.random() * (missile_speed_max - missile_speed_min)
spawnMissile(enemy.x, enemy.y, target.x + inaccuracy, target.y, speed)
local inaccuracy = math.random() * 2 * enemy_inaccuracy - enemy_inaccuracy
local behaviour = math.random(0, 7)
if behaviour == 0 then
spawnMissile(enemy.x, enemy.y, enemy.x + inaccuracy, 1, speed)
elseif behaviour <= 5 then
local target = cities[math.random(1, #cities)]
for i = 1, 7 do
if target.alive then
break
end
target = cities[math.random(1, #cities)]
end
spawnMissile(enemy.x, enemy.y, target.x + inaccuracy, target.y, speed)
else
local angle = (math.random() * 140 - 70) * math.pi / 180
local x = enemy.x + math.sin(angle)
local y = enemy.y + math.cos(angle)
spawnMissile(enemy.x, enemy.y, x, y, speed)
end
end
end