Every second the enemy fires the function triSpreadAimed()
Code: Select all
function triSpreadAimed(enemy,amount,spread,speed)
local v = enemies[enemy]
if v == nil then
return
end
if v ~= nil then
for i = 1, amount do
local a = math.deg(math.atan2(player.y - v.y, player.x - v.x)) + 360 -- angle
a2 = a + spread
a3 = a - spread
bulletsCreate(v.x, v.y, a,20,speed, i) -- v.x = enemy x coordinate
bulletsCreate(v.x, v.y, a2,20, speed, i) -- v.y = enemy y coordinate
bulletsCreate(v.x, v.y, a3,20,speed, i) -- i = bullet ID
wait(0.2)
end
end
end
Code: Select all
function bulletsCreate(x,y,angle,speed,img,id)
bulletCount = bulletCount +1
bullet = {}
bullet.img = img
bullet.x = x
bullet.y = y
bullet.s = speed
bullet.a = angle
bullet.p = 'test'
bullet.id = id
table.insert(bullets, bullet)
end
Code: Select all
function updateBullets(dt)
for i,b in ipairs(bullets) do
fireTest(b,dt)
bulletRemove(i,b)
end
end
Code: Select all
function fireTest(b,dt)
for i = 1, b.id do
b.x = b.x + math.cos(math.rad(b.a)) * (dt * b.s)
b.y = b.y + math.sin(math.rad(b.a)) * (dt * b.s)
end
end