JustDoesGames

Just Walk

May 11th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.98 KB | None | 0 0
  1. --[[ Just Walk ]]--
  2. --[[ Just Does Games ]]--
  3.  
  4. --[[ Init ]]--
  5.  
  6. local sx,sy = term.getSize() if sx ~= 51 or sy ~= 19 or not term.isColor() then print("Display Error.") return end
  7. local px,py = 2,2
  8. local player_color = "lightBlue"
  9. local pallet_0 = {"black","white","red","orange","yellow","green","blue","purple"}
  10. local pallet_loaded = pallet_0
  11. local col_x = {}
  12. local col_y = {}
  13.  
  14. local mp_mem = {}
  15. local currentMapx = 0
  16. local currentMapy = 0
  17. local Dir = "maps"
  18.  
  19. local mp_beta = {"maps/mp_beta/mp_0-0/mp.lua", "maps/mp_beta/mp_0-0/mp_col.lua", "maps/mp_beta/mp_0-1/mp.lua", "maps/mp_beta/mp_0-1/mp_col.lua", "maps/mp_beta/mp_1-0/mp.lua", "maps/mp_beta/mp_1-0/mp_col.lua", "maps/mp_beta/mp_1-1/mp.lua", "maps/mp_beta/mp_1-1/mp_col.lua"}
  20.  
  21. local mp_beta_files = {
  22.  
  23. '234567822222222222222222222222222222222222222222222',
  24. '311111111111111111111111111111111111111111111111111',
  25. '411111111111111111111111111111111111111111111111111',
  26. '511111111111111111111111111111111111111111111111111',
  27. '611111111111111111111111111111111111111111111111111',
  28. '711111111111111111111111111111111111111111111111111',
  29. '811111111111111111111111111111111111111111111111112',
  30. '211111111111111111111111111111111111111111111111112',
  31. '211111111111111111111111111111111111111111111111112',
  32. '211111111111111111111111111111111111111111111111112',
  33. '211111111111111111111111111111111111111111111111112',
  34. '211111111111111111111111111111111111111111111111112',
  35. '211111111111111111111111111111111111111111111111112',
  36. '211111111111111111111111111111111111111111111111111',
  37. '211111111111111111111111111111111111111111111111111',
  38. '211111111111111111111111111111111111111111111111111',
  39. '211111111111111111111111111111111111111111111111111',
  40. '211111111111111111111111111111111111111111111111111',
  41. '211111222222222222222222222222222222222222222111112',
  42. '111111111111111111111111111111111111111111111111111',
  43. '100000000000000000000000000000000000000000000000000',
  44. '100000000000000000000000000000000000000000000000000',
  45. '100000000000000000000000000000000000000000000000000',
  46. '100000000000000000000000000000000000000000000000000',
  47. '100000000000000000000000000000000000000000000000000',
  48. '100000000000000000000000000000000000000000000000001',
  49. '100000000000000000000000000000000000000000000000001',
  50. '100000000000000000000000000000000000000000000000001',
  51. '100000000000000000000000000000000000000000000000001',
  52. '100000000000000000000000000000000000000000000000001',
  53. '100000000000000000000000000000000000000000000000001',
  54. '100000000000000000000000000000000000000000000000001',
  55. '100000000000000000000000000000000000000000000000000',
  56. '100000000000000000000000000000000000000000000000000',
  57. '100000000000000000000000000000000000000000000000000',
  58. '100000000000000000000000000000000000000000000000000',
  59. '100000000000000000000000000000000000000000000000000',
  60. '100000111111111111111111111111111111111111111000001',
  61. '211111222222222222222222222222222222222222222111112',
  62. '211111111111111111111111111111111111111111111111111',
  63. '211111111111111111111111111111111111111111111111111',
  64. '211111111111111111111111111111111111111111111111111',
  65. '211111111111111111111111111111111111111111111111111',
  66. '211111111111111111111111111111111111111111111111111',
  67. '211111111111111111111111111111111111111111111111112',
  68. '211111111111111111111111111111111111111111111111112',
  69. '211111111111111111111111111111111111111111111111112',
  70. '211111111111111111111111111111111111111111111111112',
  71. '211111111111111111111111111111111111111111111111112',
  72. '211111111111111111111111111111111111111111111111112',
  73. '811111111111111111111111111111111111111111111111112',
  74. '711111111111111111111111111111111111111111111111111',
  75. '611111111111111111111111111111111111111111111111111',
  76. '511111111111111111111111111111111111111111111111111',
  77. '411111111111111111111111111111111111111111111111111',
  78. '311111111111111111111111111111111111111111111111111',
  79. '234567822222222222222222222222222222222222222222222',
  80. '100000111111111111111111111111111111111111111000001',
  81. '100000000000000000000000000000000000000000000000000',
  82. '100000000000000000000000000000000000000000000000000',
  83. '100000000000000000000000000000000000000000000000000',
  84. '100000000000000000000000000000000000000000000000000',
  85. '100000000000000000000000000000000000000000000000000',
  86. '100000000000000000000000000000000000000000000000001',
  87. '100000000000000000000000000000000000000000000000001',
  88. '100000000000000000000000000000000000000000000000001',
  89. '100000000000000000000000000000000000000000000000001',
  90. '100000000000000000000000000000000000000000000000001',
  91. '100000000000000000000000000000000000000000000000001',
  92. '100000000000000000000000000000000000000000000000001',
  93. '100000000000000000000000000000000000000000000000000',
  94. '100000000000000000000000000000000000000000000000000',
  95. '100000000000000000000000000000000000000000000000000',
  96. '100000000000000000000000000000000000000000000000000',
  97. '100000000000000000000000000000000000000000000000000',
  98. '111111111111111111111111111111111111111111111111111',
  99. '222222222222222222222222222222222222222222228765432',
  100. '111111111111111111111111111111111111111111111111113',
  101. '111111111111111111111111111111111111111111111111114',
  102. '111111111111111111111111111111111111111111111111115',
  103. '111111111111111111111111111111111111111111111111116',
  104. '111111111111111111111111111111111111111111111111117',
  105. '211111111111111111111111111111111111111111111111118',
  106. '211111111111111111111111111111111111111111111111112',
  107. '211111111111111111111111111111111111111111111111112',
  108. '211111111111111111111111111111111111111111111111112',
  109. '211111111111111111111111111111111111111111111111112',
  110. '211111111111111111111111111111111111111111111111112',
  111. '211111111111111111111111111111111111111111111111112',
  112. '111111111111111111111111111111111111111111111111112',
  113. '111111111111111111111111111111111111111111111111112',
  114. '111111111111111111111111111111111111111111111111112',
  115. '111111111111111111111111111111111111111111111111112',
  116. '111111111111111111111111111111111111111111111111112',
  117. '211111222222222222222222222222222222222222222111112',
  118. '111111111111111111111111111111111111111111111111111',
  119. '000000000000000000000000000000000000000000000000001',
  120. '000000000000000000000000000000000000000000000000001',
  121. '000000000000000000000000000000000000000000000000001',
  122. '000000000000000000000000000000000000000000000000001',
  123. '000000000000000000000000000000000000000000000000001',
  124. '100000000000000000000000000000000000000000000000001',
  125. '100000000000000000000000000000000000000000000000001',
  126. '100000000000000000000000000000000000000000000000001',
  127. '100000000000000000000000000000000000000000000000001',
  128. '100000000000000000000000000000000000000000000000001',
  129. '100000000000000000000000000000000000000000000000001',
  130. '100000000000000000000000000000000000000000000000001',
  131. '000000000000000000000000000000000000000000000000001',
  132. '000000000000000000000000000000000000000000000000001',
  133. '000000000000000000000000000000000000000000000000001',
  134. '000000000000000000000000000000000000000000000000001',
  135. '000000000000000000000000000000000000000000000000001',
  136. '100000111111111111111111111111111111111111111000001',
  137. '211111222222222222222222222222222222222222222111112',
  138. '111111111111111111111111111111111111111111111111112',
  139. '111111111111111111111111111111111111111111111111112',
  140. '111111111111111111111111111111111111111111111111112',
  141. '111111111111111111111111111111111111111111111111112',
  142. '111111111111111111111111111111111111111111111111112',
  143. '211111111111111111111111111111111111111111111111112',
  144. '211111111111111111111111111111111111111111111111112',
  145. '211111111111111111111111111111111111111111111111112',
  146. '211111111111111111111111111111111111111111111111112',
  147. '211111111111111111111111111111111111111111111111112',
  148. '211111111111111111111111111111111111111111111111112',
  149. '211111111111111111111111111111111111111111111111118',
  150. '111111111111111111111111111111111111111111111111117',
  151. '111111111111111111111111111111111111111111111111116',
  152. '111111111111111111111111111111111111111111111111115',
  153. '111111111111111111111111111111111111111111111111114',
  154. '111111111111111111111111111111111111111111111111113',
  155. '222222222222222222222222222222222222222222228765432',
  156. '100000111111111111111111111111111111111111111000001',
  157. '000000000000000000000000000000000000000000000000001',
  158. '000000000000000000000000000000000000000000000000001',
  159. '000000000000000000000000000000000000000000000000001',
  160. '000000000000000000000000000000000000000000000000001',
  161. '000000000000000000000000000000000000000000000000001',
  162. '100000000000000000000000000000000000000000000000001',
  163. '100000000000000000000000000000000000000000000000001',
  164. '100000000000000000000000000000000000000000000000001',
  165. '100000000000000000000000000000000000000000000000001',
  166. '100000000000000000000000000000000000000000000000001',
  167. '100000000000000000000000000000000000000000000000001',
  168. '100000000000000000000000000000000000000000000000001',
  169. '000000000000000000000000000000000000000000000000001',
  170. '000000000000000000000000000000000000000000000000001',
  171. '000000000000000000000000000000000000000000000000001',
  172. '000000000000000000000000000000000000000000000000001',
  173. '000000000000000000000000000000000000000000000000001',
  174. '111111111111111111111111111111111111111111111111111'
  175.  
  176. }
  177.  
  178. if not fs.exists("maps/mp_beta") then
  179.     term.clear() term.setCursorPos(1,1) write("Loading Map Chunks 0 / 8")
  180.     local tmp = 1
  181.     for i=1, #mp_beta do
  182.         local file = fs.open(mp_beta[i], "w")
  183.         for i=1, 19 do
  184.             file.writeLine(tostring(mp_beta_files[tmp]))
  185.             tmp = tmp + 1
  186.         end
  187.         file.close() sleep(.000001)
  188.         term.clear() term.setCursorPos(1,1) write("Loading Map Chunks "..i.." / 8")
  189.     end
  190. end
  191.  
  192.  
  193. --[[ Init ]]--
  194.  
  195.  
  196. --[[ Functions ]]--
  197.  
  198. function clr() term.clear() end
  199. function cp(x,y) term.setCursorPos(x,y) end
  200. function sb(col) term.setBackgroundColor(colors[col]) end
  201. function st(col) term.setTextColor(colors[col]) end
  202.  
  203. function drawPlayer()
  204.     cp(px,py) sb(player_color) write(" ")
  205. end
  206.  
  207. function loadMap(mapDir, pallet)
  208.     mp_mem = {}
  209.     if mapDir ~= nil and fs.exists(mapDir.."/mp.lua") then
  210.         if pallet == nil then pallet = {"black","black","black","black","black","black","black","black","black"} end
  211.         local file = fs.open(mapDir.."/mp.lua", "r")
  212.         clr() cp(1,1)
  213.         for i=1, 19 do
  214.             local map = file.readLine()
  215.             for character in map:gmatch(".") do
  216.                 if type(tonumber(character)) ~= "number" then error("drawMap Requires a Valid Map") end
  217.                 if term.getBackgroundColor ~= pallet[tonumber(character)] then sb(pallet[tonumber(character)]) end write(" ")
  218.                 if #mp_mem == 0 then mp_mem[1] = pallet[tonumber(character)] else mp_mem[#mp_mem+1] = pallet[tonumber(character)] end
  219.             end if i ~= 19 then print("") end
  220.         end
  221.         sb("black") cp(1,1)
  222.     else
  223.  
  224.     end
  225. end
  226.  
  227. function loadCol(mapDir)
  228.     col_x = {}
  229.     col_y = {}
  230.     if mapDir ~= nil and fs.exists(mapDir.."/mp_col.lua") then
  231.         local file = fs.open(mapDir.."/mp_col.lua", "r")
  232.         for i=1, 19 do
  233.             local col = file.readLine() local cnt = 1
  234.             for character in col:gmatch(".") do
  235.                 if type(tonumber(character)) ~= "number" then error("loadCol Requires a Valid Col") end
  236.                 if tonumber(character) == 1 then if #col_x == 0 then col_x[1] = cnt else col_x[#col_x+1] = cnt end if #col_y == 0 then col_y[1] = i else col_y[#col_y+1] = i end end cnt = cnt + 1
  237.             end
  238.         end
  239.     end
  240. end
  241.  
  242. function isCol(x,y)
  243.     for i=1, #col_x do
  244.         if x == col_x[i] then
  245.             if y == col_y[i] then
  246.                 return true
  247.             end
  248.         end
  249.     end
  250.     return false
  251. end
  252.  
  253. function animateScreen(direction)
  254.     sb("black")
  255.     if direction == "up" then
  256.         cp(1,sy)
  257.         for i=1, sy do
  258.             for i=1, sx do
  259.                 write(" ")
  260.             end
  261.             cp(1,sy-i) sleep(.01)
  262.         end
  263.     elseif direction == "down" then
  264.         cp(1,1)
  265.         for i=1, sy do
  266.             for i=1, sx do
  267.                 write(" ")
  268.             end
  269.             cp(1,1+i) sleep(.01)
  270.         end
  271.     elseif direction == "left" then
  272.  
  273.     elseif direction == "right" then
  274.  
  275.     elseif direction == "blank" then
  276.         clr() sleep(.1)
  277.     end
  278. end
  279.  
  280. --[[ Functions ]]--
  281.  
  282.  
  283. --[[ Main ]]--
  284.  
  285. function main()
  286.     loadMap("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy, pallet_loaded)
  287.     loadCol("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy)
  288.     drawPlayer()
  289.  
  290.     local running = true
  291.     while running do
  292.         sleep(.00001) a,i = os.pullEvent("key")
  293.         if i == keys.w then
  294.             if not isCol(px,py-1) then
  295.                 cp(px,py)
  296.                 if #mp_mem > 0 then sb(mp_mem[(51*(py-1))+px]) else sb("black") end write(" ")
  297.                 py = py - 1
  298.                 cp(px,py) sb(player_color) write(" ")
  299.             end
  300.         elseif i == keys.a then
  301.             if not isCol(px-1,py) then
  302.                 cp(px,py)
  303.                 if #mp_mem > 0 then sb(mp_mem[(51*(py-1))+px]) else sb("black") end write(" ")
  304.                 px = px - 1
  305.                 cp(px,py) sb(player_color) write(" ")
  306.             end
  307.         elseif i == keys.s then
  308.             if not isCol(px,py+1) then
  309.                 cp(px,py)
  310.                 if #mp_mem > 0 then sb(mp_mem[(51*(py-1))+px]) else sb("black") end write(" ")
  311.                 py = py + 1
  312.                 cp(px,py) sb(player_color) write(" ")
  313.             end
  314.         elseif i == keys.d then
  315.             if not isCol(px+1,py) then
  316.                 cp(px,py)
  317.                 if #mp_mem > 0 then sb(mp_mem[(51*(py-1))+px]) else sb("black") end write(" ")
  318.                 px = px + 1
  319.                 cp(px,py) sb(player_color) write(" ")
  320.             end
  321.         elseif i == keys.q then
  322.             sb("black") clr() cp(1,1) sleep(.1) running = false
  323.         end
  324.         if px < 1 then
  325.             currentMapx = currentMapx - 1
  326.             px = sx animateScreen("blank")
  327.             loadMap("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy, pallet_loaded)
  328.             loadCol("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy)
  329.             drawPlayer()
  330.         elseif px > sx then
  331.             currentMapx = currentMapx + 1
  332.             px = 1 animateScreen("blank")
  333.             loadMap("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy, pallet_loaded)
  334.             loadCol("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy)
  335.             drawPlayer()
  336.         elseif py < 1 then
  337.             currentMapy = currentMapy - 1
  338.             py = sy animateScreen("up")
  339.             loadMap("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy, pallet_loaded)
  340.             loadCol("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy)
  341.             drawPlayer()
  342.         elseif py > sy then
  343.             currentMapy = currentMapy + 1
  344.             py = 1 animateScreen("down")
  345.             loadMap("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy, pallet_loaded)
  346.             loadCol("maps/mp_beta/mp_"..currentMapx.."-"..currentMapy)
  347.             drawPlayer()
  348.         end
  349.     end
  350.  
  351.  
  352. end
  353.  
  354. main()
  355.  
  356. --[[ Main ]]--
Advertisement
Add Comment
Please, Sign In to add comment