Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. gameName = "Labirinto" -- nome do mapa
  2.  
  3. tfm.exec.disableAutoShaman(true)
  4. tfm.exec.disableAutoNewGame(true)
  5. tfm.exec.disableAfkDeath(true)
  6.  
  7. place = 0
  8.  
  9. function init_matrix(wD, hG)
  10. local result = {}
  11. for y = 0, hG - 1 do
  12. for x = 0, wD - 1 do
  13. result[y * wD + x] = 1
  14. end
  15. result[y * wD + 0] = 0
  16. result[y * wD + wD - 1] = 0
  17. end
  18. for x = 0, wD - 1 do
  19. result[0 * wD + x] = 0
  20. result[(hG - 1) * wD + x] = 0
  21. end
  22. return result
  23. end
  24.  
  25. function setMap(matrix, wD, hG)
  26. place = 0
  27. xml = '<C><P H="740" Ca="" N="" L="2200" /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" X="1201" L="2500" o="0" H="760" c="4" Y="367" T="12" /><S P="0,0,0.3,0.2,0,0,0,0" L="2200" o="0" H="40" X="1100" N="" Y="0" T="12" /><S P="0,0,0.3,0.2,0,0,0,0" L="2240" o="0" H="40" X="1100" N="" Y="760" T="12" /><S P="0,0,0.3,0.2,90,0,0,0" L="760" o="0" H="40" X="2200" N="" Y="360" T="12" /><S m="" P="0,0,0.3,0.2,90,0,0,0" L="760" o="0" H="40" X="0" N="" Y="360" T="12" />'
  28. xmlEnd = '</S><D><DS Y="40" X="80" /><T X="2082" Y="735" D="" /><F Y="732" X="2080" /></D><O /></Z></C>'
  29. color = string.format("%X", math.random(0x000000, 0xFFFFFF))
  30. invColor = string.format("%06x", 0xffffff - tonumber(color, 16))
  31. for y = 0, hG - 1 do
  32. for x = 0, wD - 1 do
  33. if matrix[y * wD + x] == 0 then
  34. r = ""
  35. else
  36. angle = {0}
  37. xml = xml..string.format('<S H="40" P="0,0,3,0.2,%s,0,0,0" L="40" X="%s" Y="%s" o="%s" T="12" />',angle[math.random(#angle)], x*40,y*40,color)
  38. end
  39. end
  40. end
  41. xml = xml..xmlEnd
  42. tfm.exec.newGame(xml)
  43. tfm.exec.setGameTime('330')
  44. end
  45.  
  46. function eventNewPlayer(p)
  47. tfm.exec.respawnPlayer(p)
  48. end
  49.  
  50. function genMaze(matrix, wD, hG, x, y)
  51. local r = math.random(0, 3)
  52. matrix[y * wD + x] = 0
  53. for i = 0, 3 do
  54. local d = (i + r) % 4
  55. local dx = 0
  56. local dy = 0
  57. if d == 0 then
  58. dx = 1
  59. elseif d == 1 then
  60. dx = -1
  61. elseif d == 2 then
  62. dy = 1
  63. else
  64. dy = -1
  65. end
  66. local nx = x + dx
  67. local ny = y + dy
  68. local nx2 = nx + dx
  69. local ny2 = ny + dy
  70. if matrix[ny * wD + nx] == 1 then
  71. if matrix[ny2 * wD + nx2] == 1 then
  72. matrix[ny * wD + nx] = 0
  73. genMaze(matrix, wD, hG, nx2, ny2)
  74. end
  75. end
  76. end
  77. end
  78.  
  79. wD = 55
  80. hG = 20
  81.  
  82. function eventPlayerWon(p)
  83. place = place+1
  84. if place == 1 then
  85. tfm.exec.setGameTime(10)
  86. end
  87. end
  88.  
  89. function eventLoop(t,r)
  90. if r <= 0 then
  91. matrix = init_matrix(wD, hG)
  92. genMaze(matrix, wD, hG, 2, 2)
  93. matrix[wD + 2] = 0
  94. matrix[(hG - 2) * wD + wD - 3] = 0
  95. setMap(matrix, wD, hG)
  96. end
  97. end
  98. tfm.exec.setGameTime(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement