Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
1,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. tfm.exec.disableAutoNewGame(true)
  2. local map = '@6219515'
  3. local level = 1
  4. local loss = 1
  5. local height = 30
  6. local branchwidth = 5
  7. local joint = {alpha = 0.9, foreground = true, color = 0xFFFFFF}
  8. local id = 0
  9.  
  10. local args = {400,760,0,-1,height}
  11. local togrow = {}
  12. local growtime = os.time()*565
  13.  
  14. cmds = {'new','stop','start'}
  15. for _, cm in pairs(cmds) do
  16.     system.disableChatCommandDisplay(cm, true)
  17. end
  18.  
  19. function grow(x,y,dx,dy,w,isbranch)
  20.     id = id+1
  21.     width = w-level*loss;
  22.     joint.line = width
  23.    
  24.     level = level+1
  25.     joint.point1 = x..','..y
  26.     x = x+dx
  27.     y = y+dy
  28.    
  29.     dx = math.floor(dx+math.sin(math.random()+level)*branchwidth)
  30.     dy = -math.abs(math.floor(dy+math.cos(math.random()+level)*branchwidth))
  31.  
  32.     args = {x,y,dx,dy,w}
  33.     joint.point2 = x..','..y
  34.     tfm.exec.addJoint(id, 1, 1, joint)
  35.     perc = math.random(0, 100)
  36.     if level > (height/2)/2 then
  37.         if perc < 60 and width > 1 then
  38.             table.insert(togrow, {x, y, 4, width})
  39.         end
  40.     end
  41.     if width > 0 then
  42.         grow(args[1],args[2],args[3],args[4],args[5], isbranch)
  43.     end
  44. end
  45.  
  46. function eventChatCommand(player, cmd)
  47.     if cmd == "start" then
  48.         growtime = os.time()
  49.        
  50.     elseif cmd == "stop" then
  51.         growtime = os.time()*5665
  52.        
  53.     elseif cmd == "new" then
  54.         growtime = os.time()*5665
  55.         togrow = {}
  56.         level = 1
  57.         args = {400,760,0,-1,40}
  58.         newTree()
  59.         id = 0
  60.     end
  61. end
  62.  
  63. function newgrow()
  64.     if (#togrow > 1) then
  65.         d = math.random(#togrow)
  66.         ar = togrow[d]
  67.         table.remove(togrow, d)
  68.         --grow(ar[1], ar[2], math.floor(2*math.sin(math.random()+ar[3])), math.ceil(2*math.cos(math.random()+ar[3])), ar[4]+level, true);
  69.         grow(ar[1], ar[2], 0, 1, ar[4]+level, true);
  70.     end
  71. end
  72.  
  73. function eventLoop()
  74.     if growtime < os.time()-100 then
  75.         newgrow()
  76.         growtime = os.time()
  77.     end
  78. end
  79.  
  80. function newTree()
  81.     tfm.exec.newGame(map)
  82.     tfm.exec.addPhysicObject(1, 200, 400, {type = 12})
  83.     grow(args[1],args[2],args[3],args[4],args[5], false)
  84. end
  85.  
  86. newTree()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement