Zerveorus

#Maze

Nov 16th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.69 KB | None | 0 0
  1. local squares = {}
  2.  
  3. local gameFinished = false
  4.  
  5. local lastId = 0
  6. local mice = {}
  7. local players = 0
  8.  
  9. local skipVotes = 0
  10.  
  11. local text = 0
  12. local version = 0.2
  13. local help = "<br><font color='#DCD17A'> \> Bienvenido al laberinto!! Para escapar ve al cuadro rojo y preciona espacio dentro de el, debo advertirte que el camino no es fácil<br><font color='#F8883F'>\> Tienes un salto extra que puedes usar con espacio también , pero sólo uno por ronda! úsalo con sabiduría<br><font color='#DC9669'>\> Si el laberinto es demasiado para ti puedes usar el comando !skip para votar por cambiar de mapa (Se muestra arriba del mapa, ahí encontrarás el mínimo de votos para cambiar de mapa también)<br><font color='#BB79FF'> \> Version: "..version.."</font>"
  14. local welcome = "<br><font color='#26A247'>Bienvenido a #maze, para obtener información coloca !help</font><br><J>Minijuego en desarrollo</J>"
  15.  
  16. function main()
  17. tfm.exec.disableAutoTimeLeft()
  18. tfm.exec.disableAutoShaman()
  19. tfm.exec.disableAfkDeath()
  20. tfm.exec.disableAutoNewGame()
  21. system.disableChatCommandDisplay("start")
  22.     for name in next,tfm.get.room.playerList do
  23.         eventNewPlayer(name)
  24.     end
  25. end
  26.  
  27. function render()
  28. local id = 0
  29.     for i = 0,800,45 do
  30.         for o = 0,400,45 do
  31.             a = {id = id,x = i,y = o}
  32.             table.insert(squares,a)
  33.             id = id + 1
  34.         end
  35.     end
  36. end
  37. render()
  38.  
  39. function eventNewGame()
  40.     gameFinished = false
  41.     skipVotes = 0
  42.     for name in next,tfm.get.room.playerList do
  43.         mice[name].vote = false
  44.         mice[name].jump = false
  45.     end
  46. end
  47.  
  48. function eventNewPlayer(name)
  49. players = players +1
  50. lastId = lastId +1
  51.     if not mice[name] then
  52.         mice[name] = {
  53.             id = lastId,
  54.             vote = false,
  55.             jump = false
  56.         }
  57.     tfm.exec.chatMessage(welcome,name)
  58. end
  59. end
  60.  
  61. function eventPlayerLeft(name)
  62.     players = players -1
  63. end
  64.  
  65.  
  66. function spawn_ground(id,x,y)
  67. if id == 8 or id == 154 then return end
  68. local angle
  69. local a = math.random(1,2)
  70. local angle = a == 1 and 90 or 0
  71. local body = {
  72. type = 0 ,
  73. width = 20 ,
  74. height = 35 ,
  75. friction = 0.35 ,
  76. angle = angle ,
  77. }
  78. if a == 1 then
  79.     body.friction = 10
  80.     body.type = 4
  81.     else
  82.     body.height = 40
  83. end
  84.     tfm.exec.addPhysicObject(id,x+20,y+20,body)
  85. end
  86.  
  87. function start()
  88. text = math.floor(players/3)
  89. tfm.exec.newGame('<C><P /><Z><S><S L="800" H="20" X="400" Y="390" T="0" P="0,0,0.3,0.2,0,0,0,0" /></S><D /><O /></Z></C>')
  90. for j =1,#squares,1 do
  91. --ui.addTextArea(j,"",nil,squares[j].x,squares[j].y,40,40,0x0010FC,0x000000,0.5)
  92.     if j ~= 8 or j ~= 154 then
  93.     local i =  math.random(1,10)
  94.         if i == 2 then
  95.             spawn_ground(j,squares[j].x,squares[j].y)
  96.         elseif i == 1 then
  97.             spawn_ground(j,squares[j].x,squares[j].y)
  98.         elseif i == 3 then
  99.             spawn_ground(j,squares[j].x,squares[j].y)
  100.         elseif i == 4 then
  101.             spawn_ground(j,squares[j].x,squares[j].y)
  102.         end
  103.     end
  104. end
  105. ui.addTextArea(1000,"",nil,squares[8].x,squares[8].y,40,40,0x0010FC,0x000000,0.3,true)
  106. ui.addTextArea(1001,"",nil,squares[154].x,squares[154].y,40,40,0xFC0B00,0x000000,0.3,true)
  107.     for name in next,tfm.get.room.playerList do
  108.         tfm.exec.movePlayer(name,20,335)
  109.         system.bindKeyboard(name,32,true)
  110.     end
  111. end
  112.  
  113. function eventPlayerWon(name)
  114.     if not gameFinished then
  115.         gameFinished = true
  116.         tfm.exec.setGameTime(5)
  117.     end
  118. end
  119.  
  120. function eventKeyboard(name,key,down,px,py)
  121. if key == 32 then
  122.     if px > squares[154].x and px < squares[154].x+40 then
  123.         if py > squares[154].y and py < squares[154].y+40 then
  124.             tfm.exec.giveCheese(name)
  125.             tfm.exec.playerVictory(name)
  126.         end
  127.     end
  128.     if not mice[name].jump then
  129.         tfm.exec.movePlayer (name,0,0,true, 0, -60,true)
  130.         mice[name].jump = true
  131.     end
  132. end
  133. end
  134.  
  135. function eventChatCommand(name,command)
  136. local a = {}
  137. for i in command:gmatch('[^%s]+') do
  138.     table.insert(a,i)
  139. end
  140. if string.lower(a[1]) == "skip" and not mice[name].vote then
  141.     skipVotes = skipVotes +1
  142.     mice[name].vote = true
  143. elseif a[1] == "help" then
  144.     tfm.exec.chatMessage(help,name)
  145. end
  146. if a[1] == "show" then
  147.     local x = tonumber(a[2])
  148.     print("id = "..squares[x].id.."<br>x = "..squares[x].x.."<br>y = "..squares[x].y)
  149. elseif a[1] == "me" then
  150.     print("x = "..tfm.get.room.playerList[name].x.."<br>y = "..tfm.get.room.playerList[name].y)
  151. elseif a[1] == "start" and name == "Miiiclaroo" or name == "Zaxox" then
  152.     start()
  153. end
  154. end
  155.  
  156. function endGame()
  157. if not gameFinished then
  158.         gameFinished = true
  159.         tfm.exec.setGameTime(5)
  160. end
  161. end
  162.  
  163. function eventLoop(t,tr)
  164.     if tr <= 0 then
  165.         if gameFinished then
  166.             start()
  167.         else
  168.             gameFinished = true
  169.             tfm.exec.setGameTime(5)
  170.         end
  171.     end
  172.     check()
  173. end
  174.  
  175. function check()
  176.     if text <= 0 then
  177.         text = 1
  178.     end
  179.     if text > 0 then
  180.         if skipVotes >= text then
  181.             endGame()
  182.         end
  183.     end
  184.     ui.addTextArea(1002,skipVotes.." / "..text,nil,380,25,40,0,0x0010FC,0x000000,0.3,true)
  185. end
  186.  
  187.    
  188. main()
Advertisement
Add Comment
Please, Sign In to add comment