Advertisement
Eshkation-

Snake !

Jun 22nd, 2014
1,334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. tfm.exec.disableAutoShaman(true)
  2. tfm.exec.disableAutoNewGame(true)
  3. tfm.exec.disableAfkDeath(true)
  4.  
  5. gameOver = false
  6. username = "Eshkation" -- Mude para seu nick
  7.  
  8.  
  9. snakeUI = {type = 12, height = 10, width = 10, color = 0x02F700}
  10. foodUI = {type = 12, height = 10, width = 10, color = 0xF95555}
  11.  
  12. ID = 1
  13. main = {X=100,Y = 200, lenght = 2}
  14. colors = {[0] = 0}
  15. snakeTail = {[1] = {X = 9999, Y= 9999}}
  16. food = {X = 999, Y = 999}
  17. pX = main.X
  18. pY = main.Y
  19. dirY = 0
  20. dirX = 0
  21.  
  22. function colorCell(pX,pY)
  23. ID = ID+1
  24. tfm.exec.addPhysicObject(ID, pX, pY, snakeUI)
  25. snakeTail[ID] = {X = pX, Y= pY}
  26. if ID >= main.lenght then
  27. ID = 1
  28. end
  29. end
  30.  
  31.  
  32. function addFood()
  33. food.X = math.floor(math.random()*77)*10
  34. food.Y = math.floor(math.random()*33)*10
  35. tfm.exec.addPhysicObject(-1, food.X, food.Y, foodUI)
  36. end
  37.  
  38. function eventLoop()
  39. if gameOver == false then
  40. pY = pY+dirY
  41. pX = pX+dirX
  42. tfm.exec.addPhysicObject(0, pX, pY, snakeUI)
  43. colorCell(pX,pY)
  44. if pX >= 790 then pX = 10
  45. elseif pX <= 10 then pX = 790
  46. elseif pY >= 390 then pY = 10
  47. elseif pY <= 10 then pY = 390
  48. end
  49.  
  50. if pX == food.X and pY == food.Y then
  51. main.lenght = main.lenght+1
  52. addFood()
  53. end
  54. end
  55. end
  56.  
  57. function eventKeyboard(player,keyCode,down,posX,posY)
  58. dirX = 0
  59. dirY = 0
  60. if keyCode == 76 then
  61.     dirX = 10
  62. elseif keyCode == 74 then
  63.     dirX = -10
  64. elseif keyCode == 73 then
  65.     dirY = -10
  66. elseif keyCode == 75 then
  67.     dirY = 10
  68. end
  69. end
  70.  
  71. tfm.exec.bindKeyboard(username,73,true,true)
  72. tfm.exec.bindKeyboard(username,74,true,true)
  73. tfm.exec.bindKeyboard(username,75,true,true)
  74. tfm.exec.bindKeyboard(username,76,true,true)
  75.  
  76.  
  77. tfm.exec.newGame("@5099136")
  78. addFood()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement