The basic concept involves setting up a turret, or a number of automated turrets, the turrets will automatically locate the closest target and open fire, then move onto the next closest turret. At this stage I haven't even thought about not shooting at something behind a wall...
These are the fragments that I have cobbled together thus far;
These two will return the distance or angle between two known points by inputting the x/y coordinates of both;
Code: Select all
-- Returns the distance between two points.
function distance(x1,y1, x2,y2)
return ((x2-x1)^2+(y2-y1)^2)^0.5 end
-- Returns the angle between two points in radians...(?)
function angle(x1,y1, x2,y2)
return math.atan2(y2-y1, x2-x1) end
Code: Select all
function turretdist()
for i,t in ipairs (turrets) do
for j,e in ipairs (enemies) do
love.graphics.print("Distance: "..distance(t.x,t.y,e.x,e.y),20,10+(j*10)+(i*20)) --fudged y coordinates, but it works
end
end
end
I haven't really got any programming experience so any help is really appreciated; am I going about this the right way? Or am I completely mad...