Tectoon

[TFM] Ghost em construção!

Jul 6th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local ghost={}
  2. local movements = {}
  3. a = 0
  4. e = 0
  5. reiniciar_a = false
  6. function eventLoop()
  7.     for i=1,5 do
  8.         a = a + 1
  9.         reiniciar_a = true
  10.         for n,e in pairs(ghost) do 
  11.             e.ispresent = false
  12.             if movements[n][a+15] then
  13.                 mov = movements[n][a+15]           
  14.                 tfm.exec.displayParticle(3,mov[1],mov[2],0,0,0,0,nil)
  15.                 e.x, e.y = mov[1],mov[2]   
  16.                 reiniciar_a = false
  17.                 e.ispresent = true
  18.             elseif e.id then
  19.                 tfm.exec.explosion(e.x, e.y, 90, 100, true)
  20.                 tfm.exec.displayParticle(10,e.x, e.y,0,0,0,0,nil)  
  21.                 ghostGetMovement(n)                        
  22.                 e.id = false
  23.             end        
  24.         end
  25.         if reiniciar_a then
  26.             a = 0
  27.         end
  28.         e = e + 0.5
  29.         if e%20 == 0 then      
  30.             spawnItemTo()      
  31.         end
  32.     end
  33. end
  34.  
  35. function spawnItemTo()
  36. local items = {10}
  37.     for n,e in pairs(ghost) do
  38.         if e.ispresent then
  39.             tbl = getRandomName() or {0,400,200}
  40.             local dx = tbl[2] - e.x
  41.             local dy = tbl[3] - e.y
  42.             local angle = math.atan2(dy, dx)       
  43.             local vx = math.cos(angle)
  44.             local vy = math.sin(angle)         
  45.             itemSpawn = items[math.random(#items)]
  46.             if itemSpawn == 10 then
  47.                 items[2] = 10
  48.             end
  49.             tfm.exec.addShamanObject(itemSpawn, e.x+20 * vx, (e.y-20) + 20 * vy, angle*180/math.pi, 50 * vx, 20 * vy, false)
  50.         end
  51.     end
  52. end
  53.  
  54. function ghostGetMovement(ide) 
  55.     if ghost[ide] then
  56.         ghost[ide].id = true
  57.         x1,y1 = ghost[ide].x,ghost[ide].y  
  58.         tbl = getRandomName() --or {0,400,200}
  59.         x2,y2 = math.random(tbl[2]),math.random(tbl[3])      
  60.         local distance = getDistance(x1,y1,x2,y2)
  61.         local numb = math.floor(distance/3)
  62.         local angle = getAngle(x1,y1,x2,y2)        
  63.            for i=0,numb do                      
  64.                 local X = x1+math.cos(angle)*(i*3)
  65.                 local Y = y1+math.sin(angle)*(i*3)             
  66.                 movements[ide][i] = {X,Y}
  67.             end    
  68.     end
  69. end
  70.  
  71. function getRandomName()
  72.     local c = {}
  73.     for name, player in pairs(tfm.get.room.playerList) do
  74.         if not player.isDead then
  75.             c[#c+1] = {name,player.x,player.y}
  76.         end
  77.     end
  78.     return c[math.random(#c)]
  79. end
  80.  
  81. function getDistance(x1,y1,x2,y2)
  82.         return math.sqrt(math.abs(x1-x2)^2+math.abs(y1-y2)^2)
  83. end
  84.  
  85. function getAngle(x1,y1,x2,y2)      
  86.         return math.atan2(y2-y1,x2-x1)
  87. end
  88.  
  89. 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