Advertisement
Guest User

Untitled

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