Advertisement
LDDestroier

TurtleTron Game (beta)

Feb 6th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.16 KB | None | 0 0
  1. local youAreDead = function()
  2.     turtle.up()
  3. end
  4.  
  5. local placeBlock = function()
  6.     local count = turtle.getItemCount(turtle.getSelectedSlot())
  7.     if count == 0 then
  8.         repeat
  9.             if turtle.getSelectedSlot() == 16 then
  10.                 error("Ran out of blocks.")
  11.             else
  12.                 turtle.select(turtle.getSelectedSlot() + 1)
  13.             end
  14.         until (turtle.getItemCount(turtle.getSelectedSlot()) > 0)
  15.     else
  16.         turtle.place()
  17.     end
  18. end
  19.  
  20. local doTheMoving = function()
  21.     local sight = turtle.inspect()
  22.     if sight then
  23.         youAreDead()
  24.     else
  25.         turtle.back()
  26.         placeBlock()
  27.     end
  28. end
  29.  
  30. local getInput = function()
  31.     while true do
  32.         local evt = {os.pullEvent()}
  33.         if evt[1] == "key" then
  34.             local key = evt[2]
  35.             if key == keys.left then
  36.                 turtle.turnRight()
  37.             elseif key == keys.right then
  38.                 turtle.turnLeft()
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. term.setBackgroundColor(colors.black)
  45. term.setTextColor(colors.white)
  46. term.clear()
  47. term.setCursorPos(1,1)
  48. print("Wireless plethora keyboards are strongly recommended.")
  49. sleep(0)
  50. os.pullEvent("char")
  51. turtle.turnRight()
  52. turtle.turnRight()
  53. write("Ready, ")
  54. sleep(0.5)
  55. write("Set, ")
  56. sleep(0.5)
  57. write("GO!")
  58. parallel.waitForAny(doTheMoving, getInput)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement