Last active
January 8, 2019 20:58
-
-
Save Minstfm/aa35e436b5e18982fce6b250c44cbc92 to your computer and use it in GitHub Desktop.
AI Turret
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local sentry = { | |
body = {}, | |
x = 100, | |
y = 200 | |
} | |
local bullet = '' | |
local area = 300 | |
function eventLoop() | |
for n,player in pairs(tfm.get.room.playerList) do | |
px, py = tfm.get.room.playerList[n].x, tfm.get.room.playerList[n].y | |
lx, ly = math.abs(sentry.x-px), math.abs(sentry.y-py) | |
R = area | |
if lx^2 + ly^2 <= R^2 then | |
local c, a, b = math.sqrt(((px-(sentry.x+area))^2)+((py-sentry.y)^2)), math.sqrt(((px-sentry.x)^2)+((py-sentry.y)^2)), area | |
angle = math.deg(math.acos(((c^2)-(a^2)-(b^2))/(-2*a*b))) | |
rad = math.acos(((c^2)-(a^2)-(b^2))/(-2*a*b)) | |
tfm.exec.removeObject(bullet) | |
if px>sentry.x and py>sentry.y then | |
angle, sx, sy = angle, 50*(1.5-rad), 50*(rad) | |
elseif px<sentry.x and py>sentry.y then | |
angle, sx, sy = angle, 50*(1.5-rad), 50*(3-rad) | |
elseif px<sentry.x and py<sentry.y then | |
angle, sx, sy = 360-angle, -50*(1.5-(3-rad)), -50*((3-rad)) | |
elseif px>sentry.x and py<sentry.y then | |
angle, sx, sy = 360-angle, -50*(1.5-(3-rad)),-50*(3-(3-rad)) | |
end | |
bullet = tfm.exec.addShamanObject(35,sentry.x,sentry.y,angle,sx,sy,false) | |
end | |
end | |
for i = 1, 360, 10 do | |
local angle = i*math.pi/180 | |
local mtx, mty = sentry.x+R*math.cos(angle), sentry.y+R*math.sin(angle) | |
tfm.exec.displayParticle(0,mtx,mty,0,0,0,0,nil) | |
end | |
tfm.exec.displayParticle(1,sentry.x,sentry.y,0,0,0,0,nil) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment