Advertisement
podoko_Lua

joint drawing [v0.9]

Jun 6th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1.  
  2. --[[ Joint drawing [v0.9]
  3.        
  4.         !color ff00ff           => changer la couleur (mettez un code hexadecimal)
  5.         !alpha xx               => changer la transparence de ses joints (entre 0 et 1)
  6.         !line xx                => Changer l'épaisseur de ses joints
  7.        
  8.  
  9. ]]--
  10.  
  11. function init ()
  12.    
  13.     info = {}
  14.     for name in pairs(tfm.get.room.playerList) do eventNewPlayer(name) end
  15.     eventNewGame()
  16.    
  17.    
  18. end
  19.  
  20.  
  21. function eventNewPlayer(name)
  22.    
  23.     system.bindMouse(name, true)
  24.     tfm.exec.bindKeyboard(name, 8, true, true)
  25.     info[name] = { prop = { color=0xffffff, alpha=0.8, line=10, foreground=true}}
  26.    
  27. end
  28.  
  29.  
  30.  
  31. function eventMouse (name, x, y)
  32.    
  33.     if info[name].prop.point1 then
  34.        
  35.         info[name].prop.point2 = tostring(x)..','..tostring(y)
  36.         addJoint(name)
  37.         info[name].prop.point1 = nil
  38.     else
  39.         info[name].prop.point1 = tostring(x)..','..tostring(y)
  40.     end
  41.    
  42. end
  43.  
  44. function eventKeyboard(name, key, down, x, y)
  45.     if key == 8 then delJoint(#joint) end
  46. end
  47.  
  48. function eventChatCommand(name, command)
  49.     if command:sub(0,5) == "color" then
  50.         info[name].prop.color = tonumber('0x'..command:sub(7))
  51.     elseif command:sub(0,4) == "line" then
  52.         info[name].prop.line = tonumber(command:sub(6))
  53.     elseif command:sub(0,5) == "alpha" then
  54.         info[name].prop.alpha = tonumber(command:sub(7))
  55.     end
  56. end
  57.  
  58.  
  59. function addJoint (name)
  60.    
  61.    
  62.     table.insert(joint, info[name].prop)
  63.     tfm.exec.addJoint (#joint, 1, 1, info[name].prop)
  64.    
  65. end
  66.  
  67. function delJoint(id)
  68.    
  69.     if id ~= 0 then
  70.         tfm.exec.removeJoint (id)
  71.         table.remove(joint, id)
  72.     end
  73.    
  74. end
  75.  
  76. function eventNewGame ()
  77.    
  78.     joint = {}
  79.     tfm.exec.addPhysicObject(1, -500,-500, {['type']=1})
  80.    
  81. end
  82.  
  83.  
  84.  
  85.  
  86. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement