Guest User

godeeper

a guest
May 23rd, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. --GoDeeper by Konlab
  2. ver = "1.0"
  3. prev = 5
  4. cur = 5
  5. next = 5
  6. pos = 5
  7. function set(xtt)
  8.   term.setCursorPos(xtt,9)
  9.   term.setBackgroundColor(colors.black)
  10.   term.write("o")
  11.  
  12. end
  13. function go()
  14.   prev = cur
  15.   cur = next
  16.   next = math.random(2,25)
  17.   level(prev,1)
  18.   level(cur,2)
  19.   level(next,3)
  20. end
  21. function level(xto,n)--n==1 -> old n==2 -> current n==3 -> next
  22.   --if n == 1 then
  23. --  n=5
  24.     if n > 4 then
  25.       error("n>4")
  26.     end
  27.     yto = n * 5
  28.    
  29.    
  30.     term.setBackgroundColor(colors.brown)
  31.     term.setCursorPos(1,yto)
  32.     term.setBackgroundColor(colors.lightGray)
  33.     term.setCursorPos(xto,yto)
  34.     term.write(" ")    
  35.    
  36. end
  37. function keyy()
  38.   evvv = "char"
  39.   chh = "a"
  40.   evvv,chh = os.pullEvent("char")
  41. --  chh = read()
  42.   if chh == "a" then
  43.     pos = pos - 1
  44.   elseif chh == "d" then
  45.     pos = pos + 1
  46.   end
  47. end
  48. function game()
  49.   term.setBackgroundColor(colors.lightGray)
  50.   term.clear()
  51.   term.setCursorPos(1,1)
  52.   while true do
  53.     if cur == pos then
  54.     go()
  55.     end
  56.     keyy()
  57.     set()  
  58.    
  59.    
  60.   end  
  61. --  print("press any key")  
  62.   os.pullEvent("key")
  63.  
  64. end
  65. function drawMenu()
  66.   term.setBackgroundColor(colors.brown)
  67.   term.clear()
  68.   term.setCursorPos(1,1)
  69.   term.setBackgroundColor(colors.green)
  70.   term.write("Go Deeper game by Konlab  ")
  71.   term.setCursorPos(1,2)
  72.   print("                            ")  
  73.   print()
  74.   term.setBackgroundColor(colors.cyan)
  75.   print("Begin game                ")
  76.   print()
  77.   print("Contrlos&Credits          ")
  78.   print()
  79.   print("Exit game                 ")
  80.  
  81.  
  82. end
  83. function credits()
  84. term.clear()
  85. term.setCursorPos(1,1)
  86. print("GoDeeper - Controls")
  87. print("A;D - go left/right")
  88. print()
  89. print("GoDeeper - Credits")
  90. print("GoDeeper was created by Konlab")
  91. print("Current version: "..ver)
  92. print("Click to continue")
  93. os.pullEvent("mouse_click")
  94. end
  95. function main()
  96.   while true do
  97.     drawMenu()
  98.     event,button,x,y = os.pullEvent("mouse_click")
  99.     if y == 8 then
  100.       return
  101.     elseif y == 6 then
  102.       credits()
  103.     elseif y == 4 then
  104.       game()
  105.     end    
  106.   end
  107. end
  108.  
  109. ok,err = pcall(main)
  110. if err == "Terminated" then
  111.   print("Terminated")
  112.   return
  113. end
  114. if ok then
  115. term.setBackgroundColor(colors.black)
  116. term.setTextColor(colors.white)
  117. term.clear()
  118. term.setCursorPos(1,1)
  119. print("Thanks for using GoDeeper by Konlab")
  120. return
  121. else
  122.   term.setBackgroundColor(colors.black)
  123.  
  124.   term.clear()
  125.   term.setCursorPos(1,1)
  126.   print("Crashed:"..err)
  127.  
  128. end
Advertisement
Add Comment
Please, Sign In to add comment