DarkDracoon

Snake!

Jun 8th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. tfm.exec.disableAutoShaman(true)
  2. tfm.exec.disableAutoNewGame(true)
  3. tfm.exec.disableAfkDeath(true)
  4.  
  5. snakeColor = "0xFF0F00"
  6. foodColor = "0xFFFF00"
  7.  
  8. gameOver = false
  9. username = "Dracopta"
  10. score = "0"
  11.  
  12. snakeUI = {type = 12, height = 10, width = 10, color = snakeColor}
  13. foodUI = {type = 12, height = 10, width = 10, color = foodColor}
  14.  
  15. ID = 1
  16. main = {X=100,Y = 200, lenght = 2}
  17. colors = {[0] = 0}
  18. snakeTail = {[1] = {X = 9999, Y= 9999}}
  19. food = {X = 999, Y = 999}
  20. pX = main.X
  21. pY = main.Y
  22. dirY = 0
  23. dirX = 0
  24.  
  25. function colorCell(pX,pY)
  26. ID = ID+1
  27. tfm.exec.addPhysicObject(ID, pX, pY, snakeUI)
  28. snakeTail[ID] = {X = pX, Y= pY}
  29. if ID >= main.lenght then
  30. ID = 1
  31. end
  32. end
  33.  
  34.  
  35. function addFood()
  36. food.X = math.floor(math.random()*77)*10+20
  37. food.Y = math.floor(math.random()*33)*10+20
  38. tfm.exec.addPhysicObject(-1, food.X, food.Y, foodUI)
  39. end
  40.  
  41. function eventLoop()
  42. if gameOver == false then
  43. pY = pY+dirY
  44. pX = pX+dirX
  45. tfm.exec.addPhysicObject(0, pX, pY, snakeUI)
  46. colorCell(pX,pY)
  47. if pX >= 790 then pX = 10
  48. elseif pX <= 10 then pX = 790
  49. elseif pY >= 390 then pY = 10
  50. elseif pY <= 10 then pY = 390
  51. end
  52.  
  53. if pX == food.X and pY == food.Y then
  54. main.lenght = main.lenght+1
  55. score = score+1
  56. ui.addTextArea(1, "<font size='16' color='#00f0f0'>Pontuação:</font> <font size='14' color='#00ff00'>" .. score .."</font>", nil, 165, 46, 130, 30, 0x003366, 0x0000cc, 0.1);
  57. tfm.exec.setUIMapName("<font color='#00f0f0'>Pontuação:</font> <font color='#00ff00'>" .. score .."</font> <font color='#ffffff'>Controlador:</font> <font color='#ff0ff0'>" ..username.."</font></ br>")
  58. addFood()
  59. end
  60. end
  61. end
  62.  
  63. function eventKeyboard(player,keyCode,down,posX,posY)
  64. dirX = 0
  65. dirY = 0
  66. if keyCode == 76 then
  67. dirX = 10
  68. elseif keyCode == 74 then
  69. dirX = -10
  70. elseif keyCode == 73 then
  71. dirY = -10
  72. elseif keyCode == 75 then
  73. dirY = 10
  74. end
  75. end
  76.  
  77. tfm.exec.bindKeyboard(username,73,true,true)
  78. tfm.exec.bindKeyboard(username,74,true,true)
  79. tfm.exec.bindKeyboard(username,75,true,true)
  80. tfm.exec.bindKeyboard(username,76,true,true)
  81.  
  82.  
  83. tfm.exec.newGame("@5099136")
  84. addFood()
  85. tfm.exec.setUIMapName("<font color='#00f0f0'>Pontuação:</font> <font color='#00ff00'>" .. score .."</font> <font color='#ffffff'>Controlador:</font> <font color='#0fffff'>" ..username.."</font></ br>")
  86. ui.addTextArea(1, "<font size='16' color='#00f0f0'>Pontuação:</font> <font size='15' color='#00ff00'>" .. score .."</font>", nil, 165, 46, 130, 30, 0x003366, 0x0000cc, 0.1);
Advertisement
Add Comment
Please, Sign In to add comment