Advertisement
jesusthekiller

maze3d

Jun 14th, 2013
4,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.55 KB | None | 0 0
  1. --[[
  2.     Project info:
  3.    
  4.     Name: Maze 3D
  5.     Creator: Jesusthekiller
  6.     Language: Lua (CC)
  7.     Website: None
  8.     License: GNU GPL
  9.         License file can be fount at www.jesusthekiller.com/license-gpl.html
  10.  
  11.     Version: 2.1
  12. ]]--
  13.  
  14. --[[
  15.     Big thanks to Gopher for 3D engine!
  16.     http://www.computercraft.info/forums2/index.php?/topic/10786-wolf3d-style-3d-engine-proof-of-concept/page__hl__wolf3d
  17. ]]--
  18.  
  19. --[[
  20.     Changelog:
  21.       1.0:
  22.         Initial Release
  23.       2.0:
  24.         No-HTTP version for Treasure disk
  25.       2.1:
  26.         No more temp files!
  27. ]]--
  28.  
  29. --[[
  30.     LICENSE:
  31.    
  32.     Maze 3D
  33.     Copyright (c) 2013 Jesusthekiller
  34.  
  35.     This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  36.  
  37.     This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  38.  
  39.     See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
  40. ]]--
  41.  
  42. -- The color check
  43. if (not term.isColor()) or turtle then
  44.     print("This program has to be run on advanced computer.")
  45.     error()
  46. end
  47.  
  48. -- The cprint
  49. local function cwrite(msg)
  50.     msg = tostring(msg)
  51.     local x, y = term.getCursorPos()
  52.     term.setCursorPos((51-#msg)/2, y)
  53.     write(msg)
  54. end
  55.  
  56. local function cprint(msg)
  57.     cwrite(msg.."\n")
  58. end
  59.  
  60. --[[
  61. -- The logo
  62. local f = fs.open("maze_logo", "w") or error("Error while opening file maze_logo", 0)
  63. f.write("0   0  00   0000 0000\n00 00 0  0     0 0   \n0 0 0 0000   00  000 \n0   0 0  0  0    0   \n0   0 0  0  0000 0000\n        \n   eeee    9999      \n    777e   97779     \n   eeee 7  97  97    \n    777e   97  97    \n   eeee 7  999977    \n    7777    7777")
  64. f.close()
  65.  
  66. f = paintutils.loadImage("maze_logo")
  67.  
  68. --fs.delete("maze_logo")]]
  69.  
  70. -- The splash
  71. term.setBackgroundColor(colors.black)
  72. term.setTextColor(colors.white)
  73. term.clear()
  74.  
  75. paintutils.drawImage({[1]={[1]=1,[2]=0,[3]=0,[4]=0,[5]=1,[6]=0,[7]=0,[8]=1,[9]=1,[10]=0,[11]=0,[12]=0,[13]=1,[14]=1,[15]=1,[16]=1,[17]=0,[18]=1,[19]=1,[20]=1,[21]=1,},[2]={[1]=1,[2]=1,[3]=0,[4]=1,[5]=1,[6]=0,[7]=1,[8]=0,[9]=0,[10]=1,[11]=0,[12]=0,[13]=0,[14]=0,[15]=0,[16]=1,[17]=0,[18]=1,[19]=0,[20]=0,[21]=0,},[3]={[1]=1,[2]=0,[3]=1,[4]=0,[5]=1,[6]=0,[7]=1,[8]=1,[9]=1,[10]=1,[11]=0,[12]=0,[13]=0,[14]=1,[15]=1,[16]=0,[17]=0,[18]=1,[19]=1,[20]=1,[21]=0,},[4]={[1]=1,[2]=0,[3]=0,[4]=0,[5]=1,[6]=0,[7]=1,[8]=0,[9]=0,[10]=1,[11]=0,[12]=0,[13]=1,[14]=0,[15]=0,[16]=0,[17]=0,[18]=1,[19]=0,[20]=0,[21]=0,},[5]={[1]=1,[2]=0,[3]=0,[4]=0,[5]=1,[6]=0,[7]=1,[8]=0,[9]=0,[10]=1,[11]=0,[12]=0,[13]=1,[14]=1,[15]=1,[16]=1,[17]=0,[18]=1,[19]=1,[20]=1,[21]=1,},[6]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=0,[6]=0,[7]=0,[8]=0,},[7]={[1]=0,[2]=0,[3]=0,[4]=16384,[5]=16384,[6]=16384,[7]=16384,[8]=0,[9]=0,[10]=0,[11]=0,[12]=512,[13]=512,[14]=512,[15]=512,[16]=0,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,},[8]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=128,[6]=128,[7]=128,[8]=16384,[9]=0,[10]=0,[11]=0,[12]=512,[13]=128,[14]=128,[15]=128,[16]=512,[17]=0,[18]=0,[19]=0,[20]=0,[21]=0,},[9]={[1]=0,[2]=0,[3]=0,[4]=16384,[5]=16384,[6]=16384,[7]=16384,[8]=0,[9]=128,[10]=0,[11]=0,[12]=512,[13]=128,[14]=0,[15]=0,[16]=512,[17]=128,[18]=0,[19]=0,[20]=0,[21]=0,},[10]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=128,[6]=128,[7]=128,[8]=16384,[9]=0,[10]=0,[11]=0,[12]=512,[13]=128,[14]=0,[15]=0,[16]=512,[17]=128,[18]=0,[19]=0,[20]=0,[21]=0,},[11]={[1]=0,[2]=0,[3]=0,[4]=16384,[5]=16384,[6]=16384,[7]=16384,[8]=0,[9]=128,[10]=0,[11]=0,[12]=512,[13]=512,[14]=512,[15]=512,[16]=128,[17]=128,[18]=0,[19]=0,[20]=0,[21]=0,},[12]={[1]=0,[2]=0,[3]=0,[4]=0,[5]=128,[6]=128,[7]=128,[8]=128,[9]=0,[10]=0,[11]=0,[12]=0,[13]=128,[14]=128,[15]=128,[16]=128,},}, 15, 3)
  76.  
  77. parallel.waitForAny(
  78.     function() coroutine.yield(); os.pullEvent("key"); coroutine.yield() end,
  79.     function() term.setBackgroundColor(colors.black); term.setTextColor(colors.white) while true do term.setCursorPos(18, 16); term.write("Press any key.."); sleep(0.5); term.clearLine(); sleep(0.5) end end
  80. )
  81.  
  82. -- The size
  83. local size
  84.  
  85. repeat
  86.     term.setCursorPos(1, 16)
  87.     term.clearLine()
  88.  
  89.     cwrite("Enter maze size (5-99):")
  90.     size = read()
  91.    
  92.     size = tonumber(size)
  93.     if not size then
  94.         size = 0
  95.     end
  96. until size > 4 and size < 100
  97.  
  98. -- The generate
  99. local function mazeGen(mx, my)
  100.    
  101.     --[[
  102.         Format:
  103.        
  104.         maze.x.y.(1/2/3/4) = true/false
  105.        
  106.         1 - top
  107.         2 - bottom
  108.         3 - right
  109.         4 - left
  110.     ]]--
  111.    
  112.     local maze = {}
  113.     for i = 1, mx do
  114.         maze[i] = {}
  115.         for j = 1, my do
  116.             maze[i][j] = {}
  117.             for k = 1, 4 do
  118.                 maze[i][j][k] = true
  119.             end
  120.         end
  121.     end
  122.  
  123.     local vis = 1
  124.     local tot = mx * my
  125.     local curr = {}
  126.     curr.x = math.random(1, mx)
  127.     curr.y = math.random(1, my)
  128.     local stack = {}
  129.  
  130.     while vis < tot do
  131.         local intact = {}
  132.         local x = curr.x
  133.         local y = curr.y
  134.        
  135.         if x - 1 >= 1 and maze[x-1][y][1] and maze[x-1][y][2] and maze[x-1][y][3] and maze[x-1][y][4] then -- Check for full cells
  136.             intact[#intact+1] = {x-1, y, 1}
  137.         end
  138.        
  139.         if x + 1 <= mx and maze[x+1][y][1] and maze[x+1][y][2] and maze[x+1][y][3] and maze[x+1][y][4] then
  140.             intact[#intact+1] = {x+1, y, 2}
  141.         end
  142.        
  143.         if y + 1 <= my and maze[x][y+1][1] and maze[x][y+1][2] and maze[x][y+1][3] and maze[x][y+1][4] then
  144.             intact[#intact+1] = {x, y+1, 3}
  145.         end
  146.        
  147.         if y - 1 >= 1 and maze[x][y-1][1] and maze[x][y-1][2] and maze[x][y-1][3] and maze[x][y-1][4] then
  148.             intact[#intact+1] = {x, y-1, 4}
  149.         end
  150.        
  151.         if #intact > 0 then
  152.             local i = math.random(1, #intact) -- Choose random
  153.            
  154.             if intact[i][3] == 1 then -- Set intact's attached wall to false
  155.                 maze[intact[i][1]][intact[i][2]][2] = false
  156.             elseif intact[i][3] == 2 then
  157.                 maze[intact[i][1]][intact[i][2]][1] = false
  158.             elseif intact[i][3] == 3 then
  159.                 maze[intact[i][1]][intact[i][2]][4] = false
  160.             elseif intact[i][3] == 4 then
  161.                 maze[intact[i][1]][intact[i][2]][3] = false
  162.             end
  163.            
  164.             maze[x][y][intact[i][3]] = false -- Set attached wall to false
  165.            
  166.             vis = vis + 1 -- Increase vis
  167.            
  168.             stack[#stack+1] = intact[i] -- Add to stack
  169.         else
  170.             local tmp = table.remove(stack) -- Get last cell
  171.             curr.x = tmp[1]
  172.             curr.y = tmp[2]
  173.         end
  174.     end
  175.    
  176.     return maze
  177. end
  178.  
  179. local m = mazeGen(size, size)
  180.  
  181. -- The game init
  182. local posx = 2
  183. local posy = 2
  184.  
  185. local offsetx = 51/2-2
  186. local offsety = 19/2-2
  187.  
  188. -- The maze-to-table
  189. local tab = {}
  190.  
  191. for x = 1, size * 2 + 1 do
  192.     tab[x] = {}
  193.    
  194.     for y = 1, size * 2 + 1 do
  195.         if x % 2 == 0 and y % 2 == 0 then -- Fill cells (empty)
  196.             tab[x][y] = " "
  197.         elseif x % 2 == 1 and y % 2 == 1 then -- Fill corners (full)
  198.             tab[x][y] = "1"
  199.         end
  200.     end
  201. end
  202.  
  203. for x, tV in ipairs(m) do
  204.     for y, v in ipairs(tV) do
  205.         if x == size and y == size then
  206.             v[1] = v[1] and "2" or " "
  207.             v[2] = v[2] and "2" or " "
  208.             v[3] = v[3] and "2" or " "
  209.             v[4] = v[4] and "2" or " "
  210.             tab[x*2-1][y*2] = v[1] -- Up
  211.             tab[x*2+1][y*2] = v[2] -- Down
  212.             tab[x*2][y*2+1] = v[3] -- Right
  213.             tab[x*2][y*2-1] = v[4] -- Left
  214.         else
  215.             v[1] = v[1] and "1" or " "
  216.             v[2] = v[2] and "1" or " "
  217.             v[3] = v[3] and "1" or " "
  218.             v[4] = v[4] and "1" or " "
  219.             tab[x*2-1][y*2] = v[1] -- Up
  220.             tab[x*2+1][y*2] = v[2] -- Down
  221.             tab[x*2][y*2+1] = v[3] -- Right
  222.             tab[x*2][y*2-1] = v[4] -- Left
  223.         end
  224.     end
  225. end
  226.  
  227. local gtab = {}
  228.  
  229. for k, v in ipairs(tab) do
  230.     gtab[#gtab+1] = table.concat(v)
  231. end
  232.  
  233. size = size * 2 + 1
  234.  
  235. --[[
  236. local template = fs.open("maze3d_template", "r")
  237. local game = fs.open("maze3d_game", "w")
  238.  
  239. game.writeLine("local mapH, mapW = "..size..","..size)
  240. game.writeLine("local dir = "..(gtab[2]:sub(3,3) == " " and '0' or '88'))
  241. game.writeLine("local map = {")
  242.  
  243. for k, v in ipairs(gtab) do
  244.     game.writeLine('"'..v..'",')
  245. end
  246.  
  247. game.writeLine("}")
  248.  
  249. game.writeLine(template.readAll())
  250. game.close()
  251. template.close()
  252.  
  253. shell.run("maze3d_game")
  254.  
  255. fs.delete("maze3d_game")
  256. fs.delete("maze3d_template")]]
  257.  
  258. local mapH, mapW = size, size
  259. local dir = gtab[2]:sub(3,3) == " " and '0' or '88'
  260. local map = gtab
  261. local startdir = dir
  262.  
  263. ------------------------------------------------------------------------------------------------------
  264. --GOPHER'S CODE HERE
  265.  
  266. local buffer=term
  267. local loadedAPI=false
  268.  
  269. local stime = os.clock()
  270.  
  271. if redirect then
  272.   buffer=redirect.createRedirectBuffer()
  273.   print("redirect API found, using buffer")
  274. else
  275.   local pe=printError
  276.   rawset(_G,"printError",error)  
  277.   local ok, err=pcall(os.loadAPI,"redirect")
  278.   if not ok then
  279.     print("trying "..shell.dir().."/redirect")
  280.     ok,err=pcall(os.loadAPI,shell.dir().."/redirect")
  281.   end
  282.   if ok then    
  283.     print("Loaded redirect API, using buffer")
  284.     buffer=redirect.createRedirectBuffer()
  285.     loadedAPI=true
  286.   else
  287.     print("redirect API not found or could not be loaded, drawing directly; this may cause flickering.")
  288.   end
  289.   rawset(_G,"printError",pe)
  290. end
  291.  
  292. local colorSchemes = {
  293.   {0,8}, --white+gray
  294.   {3,11}, --blue
  295.   {6,14}, --red
  296.   {5,13}, --green
  297.   {4,1}, --yellow/orange
  298. }
  299.  
  300.  
  301. local function cast(cx,cy,angle)
  302.   --direction vector
  303.   local vx,vy=math.cos(angle), math.sin(angle)
  304.   local slope=vy/vx
  305.   --next distance, x and y axis points
  306.   local ndx, ndy
  307.   --steps, distance and block
  308.   local dsx, dsy, bsx, bsy
  309.   if vx<0 then
  310.     local x=(cx%1)
  311.     bsx=-1
  312.     ndx=math.sqrt(x*x*(1+slope*slope))
  313.     dsx=math.sqrt((1+slope*slope))
  314.   else
  315.     local x=1-(cx%1)
  316.     bsx=1
  317.     ndx=math.sqrt(x*x*(1+slope*slope))
  318.     dsx=math.sqrt((1+slope*slope))
  319.   end
  320.  
  321.   if vy<0 then
  322.     local y=(cy%1)
  323.     bsy=-1
  324.     ndy=math.sqrt(y*y*(1+1/(slope*slope)))
  325.     dsy=math.sqrt((1+1/(slope*slope)))
  326.   else
  327.     local y=1-(cy%1)
  328.     bsy=1
  329.     ndy=math.sqrt(y*y*(1+1/(slope*slope)))
  330.     dsy=math.sqrt((1+1/(slope*slope)))
  331.   end
  332.  
  333.   local x,y=math.floor(cx),math.floor(cy)
  334.   while x>0 and x<=mapW and y>0 and y<=mapH do
  335.     local hitD
  336.     local isX
  337.     if ndx<ndy then
  338.       --x crossing is next
  339.       x=x+bsx
  340.       isX=true
  341.       hitD=ndx
  342.       ndx=ndx+dsx
  343.     else
  344.       y=y+bsy
  345.       isX=false
  346.       hitD=ndy
  347.       ndy=ndy+dsy
  348.     end
  349.     local wall=map[y]:sub(x,x)
  350.     if wall~=" " then
  351.      
  352.       return colorSchemes[tonumber(wall)][isX and 1 or 2], hitD
  353.     end
  354.   end  
  355. end
  356.  
  357. local w,h=term.getSize()
  358. local centerX, centerY=math.floor((w+1)/2), math.floor((h+1)/2)
  359.  
  360. local px, py=2.5,2.5
  361. --local dir=0
  362. local fx,fy
  363. local speed=.1
  364. local turnSpeed=4
  365.  
  366. local function turn(amt)
  367.   dir=dir+amt
  368.   fx,fy=math.cos(math.rad(dir)), math.sin(math.rad(dir))
  369. end
  370.  
  371. turn(0)
  372.  
  373. --build table of angles and base distances per scanline
  374. local screenDist=.55*w
  375. local scan={}
  376.  
  377. for x=1,w do
  378.   local t={}
  379.   scan[x]=t
  380.   t.angle=math.atan2(x-centerX,screenDist)
  381.   t.dist=((x-centerX)^2+screenDist^2)^.5/screenDist
  382. end
  383.  
  384. local function redraw()
  385.   if buffer.isBuffer then
  386.     term.redirect(buffer)
  387.   end
  388.   for x=1,w do
  389.     local wall,dist=cast(px,py,math.rad(dir)+scan[x].angle)
  390.     if wall then
  391.       --calc wall height based on distance
  392.       local height=scan[x].dist/dist
  393.       height=math.floor(math.min(height*centerY,(h+1)/2))
  394.       term.setBackgroundColor(colors.gray)
  395.       for y=1,(h+1)/2-height-1 do
  396.         term.setCursorPos(x,y)
  397.         term.write(" ")
  398.       end
  399.       for y=centerY+height+1,h do
  400.         term.setCursorPos(x,y)
  401.         term.write(" ")
  402.       end
  403.       term.setBackgroundColor(2^wall)
  404.       for y=centerY-height,centerY+height do
  405.         term.setCursorPos(x,y)
  406.         term.write(" ")
  407.       end
  408.     end
  409.   end
  410.   if buffer.isBuffer then
  411.     term.restore()
  412.     buffer.blit()
  413.   end
  414. end
  415.  
  416. local function clampCollision(x,y,radius)
  417.   --am I *in* a block?
  418.   local gx,gy=math.floor(x),math.floor(y)
  419.   if map[gy]:sub(gx,gx)~=" " then
  420.     --I am. Complete fail, do nothing.
  421.     return x,y
  422.   end
  423.  
  424.   --ok, check the neighbors.
  425.   local right=math.floor(x+radius)>gx
  426.   local left=math.floor(x-radius)<gx
  427.   local front=math.floor(y-radius)<gy
  428.   local back=math.floor(y+radius)>gy
  429.  
  430.   local pushed=false
  431.  
  432.   if right and map[gy]:sub(gx+1,gx+1)~=" " then
  433.     --push left
  434.     pushed=true
  435.     x=gx+1-radius
  436.   elseif left  and map[gy]:sub(gx-1,gx-1)~=" " then
  437.     --push right
  438.     pushed=true
  439.     x=gx+radius
  440.   end
  441.  
  442.   if front and map[gy-1]:sub(gx,gx)~=" " then
  443.     --push back
  444.     pushed=true
  445.     y=gy+radius
  446.   elseif back and map[gy+1]:sub(gx,gx)~=" " then
  447.     --push forward
  448.     pushed=true
  449.  
  450.  
  451.  
  452.     y=gy+1-radius
  453.   end
  454.  
  455.   --if I wasn't pushed out on any side, I might be hitting a corner
  456.   if not pushed then
  457.     --square rad
  458.     local r2=radius^2
  459.     local pushx,pushy=0,0
  460.     if left then
  461.       if front and map[gy-1]:sub(gx-1,gx-1)~=" " then
  462.         --check front-left
  463.         local dist2=(gx-x)^2+(gy-y)^2
  464.         if dist2<r2 then
  465.           local pushd=(r2-dist2)/2^.5
  466.           pushx,pushy=pushd,pushd
  467.         end
  468.       elseif back and map[gy+1]:sub(gx-1,gx-1)~=" " then
  469.         local dist2=(gx-x)^2+(gy+1-y)^2
  470.         if dist2<r2 then
  471.           local pushd=(r2-dist2)/2^.5
  472.           pushx,pushy=pushd,-pushd
  473.         end
  474.       end
  475.     elseif right then
  476.       if front and map[gy-1]:sub(gx+1,gx+1)~=" " then
  477.         --check front-left
  478.         local dist2=(gx+1-x)^2+(gy-y)^2
  479.         if dist2<r2 then
  480.           local pushd=(r2-dist2)/2^.5
  481.           pushx,pushy=-pushd,pushd
  482.         end
  483.       elseif back and map[gy+1]:sub(gx+1,gx+1)~=" " then
  484.         local dist2=(gx+1-x)^2+(gy+1-y)^2
  485.         if dist2<r2 then
  486.           local pushd=(r2-dist2)/2^.5
  487.           pushx,pushy=-pushd,-pushd
  488.         end
  489.       end
  490.     end
  491.     x=x+pushx
  492.     y=y+pushy
  493.   end
  494.  
  495.   return x,y
  496. end
  497.  
  498. term.setBackgroundColor(colors.black)
  499. --term.setTextColor(colors.white)
  500. term.clear()
  501. term.setCursorPos(1, 1)
  502.  
  503. term.setTextColor(colors.yellow)
  504. write("Move:                                          ")
  505. term.setTextColor(colors.lime)
  506. print("WASD")
  507.  
  508. term.setTextColor(colors.yellow)
  509. write("Turn:                              ")
  510. term.setTextColor(colors.lime)
  511. print("Left/Right arrow")
  512.  
  513. term.setTextColor(colors.yellow)
  514. write("Teleport to start:                                ")
  515. term.setTextColor(colors.lime)
  516. print("R")
  517.  
  518. term.setTextColor(colors.yellow)
  519. write("Quit:                                             ")
  520. term.setTextColor(colors.lime)
  521. print("Q\n")
  522.  
  523. term.setTextColor(colors.white)
  524. write("Goal: go to ")
  525. term.setTextColor(colors.lightBlue)
  526. write("blue")
  527. term.setTextColor(colors.white)
  528. print(" spot (opposite corner of the map)\n\n\n\n")
  529.  
  530. term.setTextColor(colors.white)
  531. cprint("Press any key to start!")
  532.  
  533. os.pullEvent("key")
  534.  
  535. local frameTimer=os.startTimer(0.5)
  536. local prevTick=0
  537. local dirty=true
  538. local win = false
  539. while true do
  540.   px,py=clampCollision(px,py,.25)
  541.   if dirty then
  542.     redraw()
  543.     dirty=false
  544.   end
  545.  
  546.   local e={os.pullEvent()}
  547.   if e[1]=="key" then
  548.     if e[2]==keys.left then
  549.       turn(-turnSpeed)
  550.       dirty=true
  551.     elseif e[2]==keys.right then
  552.       turn(turnSpeed)
  553.       dirty=true
  554.     elseif e[2]==keys.up or e[2]==keys.w then
  555.       px=px+fx*speed
  556.       py=py+fy*speed
  557.       dirty=true
  558.     elseif e[2]==keys.down or e[2]==keys.s then
  559.       px=px-fx*speed
  560.       py=py-fy*speed
  561.       dirty=true
  562.     elseif e[2]==keys.a then
  563.       px=px+fy*speed
  564.       py=py-fx*speed
  565.       dirty=true
  566.     elseif e[2]==keys.d then
  567.       px=px-fy*speed
  568.       py=py+fx*speed
  569.       dirty=true
  570.     elseif e[2]==keys.q then
  571.       break
  572.     elseif e[2]==keys.r then
  573.       px,py = 2.5,2.5
  574.       dir=startdir
  575.       dirty=true
  576.     end
  577.    
  578.     if px >= mapW-1 and py >= mapH-1 then
  579.       win = true
  580.       break
  581.     end
  582.   end
  583. end
  584.  
  585.  
  586. if loadedAPI then
  587.   os.unloadAPI("redirect")
  588. end
  589.  
  590. -- JESUS PART
  591.  
  592. -- The win/loose message
  593. term.setBackgroundColor(colors.white)
  594. term.setTextColor(colors.black)
  595. term.clear()
  596. term.setCursorPos(1, 1)
  597.  
  598. if win then
  599.   local ntime = os.clock()
  600.   write("\n")
  601.   cprint("Congratulations!")
  602.   cprint("You made it in")
  603.   cprint(tostring(math.floor((ntime-stime)/60)).." minutes and "..tostring(math.ceil((ntime-stime)%60)).." seconds")
  604.   cprint("Size of maze: "..(mapW-1)/2)
  605. sleep(1)
  606. else
  607.   write("\n")
  608.   cprint("Oh noes D:")
  609. end
  610.  
  611.  
  612.  
  613. parallel.waitForAny(
  614.   function() coroutine.yield(); os.pullEvent("key"); coroutine.yield() end,
  615.   function() term.setBackgroundColor(colors.white); term.setTextColor(colors.black) while true do term.setCursorPos(18, 14); term.write("Press any key.."); sleep(0.5); term.clearLine(); sleep(0.5) end end
  616. )
  617.  
  618. term.setBackgroundColor(colors.black)
  619. term.setTextColor(colors.white)
  620. term.clear()
  621. term.setCursorPos(1, 1)
  622. cprint("  Maze by Jesusthekiller. Thanks for playing!")
  623. cprint("3D engine by Gopher, He is A-W-E-S-O-M-E")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement