Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ghost={}
- local movements = {}
- a = 0
- e = 0
- reiniciar_a = false
- function eventLoop()
- for i=1,5 do
- a = a + 1
- reiniciar_a = true
- for n,e in pairs(ghost) do
- e.ispresent = false
- if movements[n][a+15] then
- mov = movements[n][a+15]
- tfm.exec.displayParticle(3,mov[1],mov[2],0,0,0,0,nil)
- e.x, e.y = mov[1],mov[2]
- reiniciar_a = false
- e.ispresent = true
- elseif e.id then
- tfm.exec.explosion(e.x, e.y, 90, 100, true)
- tfm.exec.displayParticle(10,e.x, e.y,0,0,0,0,nil)
- ghostGetMovement(n)
- e.id = false
- end
- end
- if reiniciar_a then
- a = 0
- end
- e = e + 0.5
- if e%20 == 0 then
- spawnItemTo()
- end
- end
- end
- function spawnItemTo()
- local items = {10}
- for n,e in pairs(ghost) do
- if e.ispresent then
- tbl = getRandomName() or {0,400,200}
- local dx = tbl[2] - e.x
- local dy = tbl[3] - e.y
- local angle = math.atan2(dy, dx)
- local vx = math.cos(angle)
- local vy = math.sin(angle)
- itemSpawn = items[math.random(#items)]
- if itemSpawn == 10 then
- items[2] = 10
- end
- tfm.exec.addShamanObject(itemSpawn, e.x+20 * vx, (e.y-20) + 20 * vy, angle*180/math.pi, 50 * vx, 20 * vy, false)
- end
- end
- end
- function ghostGetMovement(ide)
- if ghost[ide] then
- ghost[ide].id = true
- x1,y1 = ghost[ide].x,ghost[ide].y
- tbl = getRandomName() --or {0,400,200}
- x2,y2 = math.random(tbl[2]),math.random(tbl[3])
- local distance = getDistance(x1,y1,x2,y2)
- local numb = math.floor(distance/3)
- local angle = getAngle(x1,y1,x2,y2)
- for i=0,numb do
- local X = x1+math.cos(angle)*(i*3)
- local Y = y1+math.sin(angle)*(i*3)
- movements[ide][i] = {X,Y}
- end
- end
- end
- function getRandomName()
- local c = {}
- for name, player in pairs(tfm.get.room.playerList) do
- if not player.isDead then
- c[#c+1] = {name,player.x,player.y}
- end
- end
- return c[math.random(#c)]
- end
- function getDistance(x1,y1,x2,y2)
- return math.sqrt(math.abs(x1-x2)^2+math.abs(y1-y2)^2)
- end
- function getAngle(x1,y1,x2,y2)
- return math.atan2(y2-y1,x2-x1)
- end
- table.foreach({1,2,3,4,5},function(a) ghost[a]={x=math.random(800),y = math.random(400),id=true,ispresent=true} movements[a]={}; ghostGetMovement(a) end)
Advertisement
Add Comment
Please, Sign In to add comment