Filexdoj

maze

Mar 29th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.06 KB | None | 0 0
  1. local startx = 869
  2. local starty = 392
  3. local movementx = 0
  4. local movementy = 0
  5. local numberOfLines = 1
  6. local lines = {
  7.     {869, 392, 869, 392}
  8. }
  9. local mainRectangle = {478, 391, 433, 233}
  10. local obsticles = {
  11.     {478, 391, 103, 56},
  12.     {492, 462, 103, 56},
  13.     {478, 548, 148, 76},
  14.     {626, 391, 87, 127},
  15.     {653, 539, 70, 85},
  16.     {751, 391, 70, 85},
  17.     {763, 493, 148, 76},
  18.     {780, 577, 41, 47}
  19. }
  20. function moveAndCheckSystem()
  21.     checkIfFail()
  22.     lines[numberOfLines][3] = lines[numberOfLines][3] + movementx
  23.     lines[numberOfLines][4] = lines[numberOfLines][4] + movementy
  24. end
  25. local moveAndCheckTimer = setTimer(moveAndCheckSystem, 200, 0)
  26.  
  27. function checkIfFail()
  28.     if movementx ~= 0 then
  29.         for k, v in pairs(obsticles) do
  30.             if lines[numberOfLines][4] >= v[2] and lines[numberOfLines][4] <= v[2] + v[4] then
  31.                 if lines[numberOfLines][3] >= v[1] and lines[numberOfLines][3] <= v[1] + v[3] then
  32.                     removeEventHandler("onClientRender", getRootElement(), game)
  33.                     removeEventHandler("onClientKey", getRootElement(), onMoveKey)
  34.                     killTimer(moveAndCheckTimer)
  35.                 end
  36.             end
  37.         end
  38.     elseif movementy ~= 0 then
  39.         for k, v in pairs(obsticles) do
  40.             if lines[numberOfLines][3] >= v[1] and lines[numberOfLines][3] <= v[1] + v[3] then
  41.                 if lines[numberOfLines][4] >= v[2] and lines[numberOfLines][4] <= v[2] + v[4] then
  42.                     removeEventHandler("onClientRender", getRootElement(), game)
  43.                     removeEventHandler("onClientKey", getRootElement(), onMoveKey)
  44.                     killTimer(moveAndCheckTimer)
  45.                 end
  46.             end
  47.         end
  48.     end
  49. end
  50.  
  51. function newLine()
  52.     local previousLine = numberOfLines
  53.     numberOfLines = numberOfLines + 1
  54.     lines[numberOfLines] = {
  55.         lines[previousLine][3],
  56.         lines[previousLine][4],
  57.         lines[previousLine][3],
  58.         lines[previousLine][4]
  59.     }
  60.     iprint(lines[numberOfLines])
  61. end
  62.  
  63. function game()
  64.     for _index, lineCoordinates in pairs(lines) do
  65.         dxDrawLine(
  66.             lineCoordinates[1],
  67.             lineCoordinates[2],
  68.             lineCoordinates[3],
  69.             lineCoordinates[4],
  70.             tocolor(0, 0, 0, 250),
  71.             2,
  72.             false
  73.         )
  74.     end
  75.  
  76.     dxDrawRectangle(
  77.         mainRectangle[1],
  78.         mainRectangle[2],
  79.         mainRectangle[3],
  80.         mainRectangle[4],
  81.         tocolor(0, 0, 0, 100),
  82.         false
  83.     )
  84.     dxDrawRectangle(
  85.         obsticles[1][1],
  86.         obsticles[1][2],
  87.         obsticles[1][3],
  88.         obsticles[1][4],
  89.         tocolor(255, 255, 255, 100),
  90.         false
  91.     )
  92.     dxDrawRectangle(
  93.         obsticles[2][1],
  94.         obsticles[2][2],
  95.         obsticles[2][3],
  96.         obsticles[2][4],
  97.         tocolor(255, 255, 255, 100),
  98.         false
  99.     )
  100.     dxDrawRectangle(
  101.         obsticles[3][1],
  102.         obsticles[3][2],
  103.         obsticles[3][3],
  104.         obsticles[3][4],
  105.         tocolor(255, 255, 255, 100),
  106.         false
  107.     )
  108.     dxDrawRectangle(
  109.         obsticles[4][1],
  110.         obsticles[4][2],
  111.         obsticles[4][3],
  112.         obsticles[4][4],
  113.         tocolor(255, 255, 255, 100),
  114.         false
  115.     )
  116.     dxDrawRectangle(
  117.         obsticles[5][1],
  118.         obsticles[5][2],
  119.         obsticles[5][3],
  120.         obsticles[5][4],
  121.         tocolor(255, 255, 255, 100),
  122.         false
  123.     )
  124.     dxDrawRectangle(
  125.         obsticles[6][1],
  126.         obsticles[6][2],
  127.         obsticles[6][3],
  128.         obsticles[6][4],
  129.         tocolor(255, 255, 255, 100),
  130.         false
  131.     )
  132.     dxDrawRectangle(
  133.         obsticles[7][1],
  134.         obsticles[7][2],
  135.         obsticles[7][3],
  136.         obsticles[7][4],
  137.         tocolor(255, 255, 255, 100),
  138.         false
  139.     )
  140.     dxDrawRectangle(
  141.         obsticles[8][1],
  142.         obsticles[8][2],
  143.         obsticles[8][3],
  144.         obsticles[8][4],
  145.         tocolor(255, 255, 255, 100),
  146.         false
  147.     )
  148. end
  149. addEventHandler("onClientRender", getRootElement(), game)
  150.  
  151. function onMoveKey(key, PoR)
  152.     if PoR == false then
  153.         if key == "arrow_u" then
  154.             if movementy ~= 0 then
  155.                 return
  156.             else
  157.                 newLine()
  158.                 movementx = 0
  159.                 movementy = -10
  160.             end
  161.         elseif key == "arrow_d" then
  162.             if movementy ~= 0 then
  163.                 return
  164.             else
  165.                 newLine()
  166.                 movementx = 0
  167.                 movementy = 10
  168.             end
  169.         elseif key == "arrow_l" then
  170.             if movementx ~= 0 then
  171.                 return
  172.             else
  173.                 newLine()
  174.                 movementx = -10
  175.                 movementy = 0
  176.             end
  177.         elseif key == "arrow_r" then
  178.             if movementx ~= 0 then
  179.                 return
  180.             else
  181.                 newLine()
  182.                 movementx = 10
  183.                 movementy = 0
  184.             end
  185.         end
  186.     end
  187. end
  188. addEventHandler("onClientKey", getRootElement(), onMoveKey)
Advertisement
Add Comment
Please, Sign In to add comment