Advertisement
Guest User

mine

a guest
Jul 30th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. function displayCord()
  2.   print(x)
  3.   print(y)
  4.   print(getOrientation())
  5.  
  6. end
  7. currentOrientation = 0
  8. io.write("What is your current x pos? ")
  9. x = io.read()
  10. io.write("What is your current y pos? ")
  11. y = io.read()
  12. io.write("What is your current depth? ")
  13. z = io.read()
  14. io.write("How far down do you wish to tunnel? ")
  15. tunnel = io.read()
  16. function initialiseOrientation()
  17. arrOrientation = {}
  18. arrOrientation[1] = "north"
  19. arrOrientation[2] = "east"
  20. arrOrientation[3] = "south"
  21. arrOrientation[4] = "west"
  22.  
  23. currentOrientation = startingOrientation()
  24. end
  25.  
  26. function getOrientation()
  27.   return arrOrientation[currentOrientation]
  28. end
  29.  
  30. function turn(direction)
  31.   tmpTurn = string.lower(direction)
  32.   if tmpTurn == "right" then
  33.     if  turtle.turnRight() then
  34.       if currentOrientation == 4 then
  35.         currentOrientation = 1
  36.       else
  37.         currentOrientation = currentOrientation + 1
  38.       end
  39.     end
  40.   elseif tmpTurn == "left" then
  41.     if  turtle.turnLeft() then
  42.       if currentOrientation == 1 then
  43.         currentOrientation = 4
  44.       else
  45.         currentOrientation = currentOrientation - 1
  46.       end
  47.     end
  48.   else
  49.     return false
  50.   end  
  51. end
  52.  
  53. function startingOrientation()
  54.   io.write("Which way is the turtle currently facing?")
  55.   facing =string.lower( io.read())
  56.     if facing == "north" then
  57.       return 1
  58.     elseif facing == "east" then
  59.       return 2
  60.     elseif facing == "south" then
  61.       return 3
  62.     elseif facing == "west" then
  63.       return 4
  64.     else
  65.       return 0
  66.     end
  67. end
  68. function refuel()
  69.   if  turtle.getFuelLevel( ) < 10 then
  70.     turtle.select(16)
  71.     turtle.refuel(1)
  72.   end
  73. end
  74.  
  75. function move(direction)
  76.   refuel()
  77.   tmpDir = string.lower(direction)
  78.  
  79.   if tmpDir == "forward" then
  80.     if turtle.forward() then
  81.       updateXY("forward")      
  82.     end  
  83.   elseif tmpDir == "back" then
  84.     if turtle.back() then
  85.       updateXY("back")
  86.     end
  87.   elseif tmpDir == "up" then
  88.     if turtle.up() then
  89.       y = (y) + (1)
  90.     end
  91.   elseif tmpDir == "down" then
  92.     if turtle.down() then
  93.       y = (y) - (1)  
  94.     end
  95.   else
  96.     return false
  97.   end
  98.      
  99. end
  100.  
  101. function updateXY(direction)
  102.   if getOrientation() == "north" then
  103.     if direction == "forward" then
  104.       y = y - 1  
  105.     elseif direction == "back" then
  106.       y = y + 1
  107.     end
  108.   elseif getOrientation() == "east" then
  109.     if direction == "forward" then
  110.       x = x + 1
  111.     elseif direction == "back" then
  112.       x = x - 1
  113.     end
  114.   elseif getOrientation() == "south" then
  115.     if direction == "forward" then
  116.       y = y + 1
  117.     elseif direction == "back" then
  118.       y = y - 1
  119.     end
  120.   elseif getOrientation() == "west" then
  121.     if direction == "forward" then  
  122.       x = x - 1
  123.     elseif direction == "back" then
  124.       x = x + 1
  125.     end
  126.   end
  127. end
  128. initialiseOrientation()
  129.  
  130.  
  131. print(getOrientation())
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. displayCord()
  139. for i = 1,30 do
  140.   move("forward")
  141.   displayCord()
  142.   move("forward")
  143.   displayCord()
  144.   turn("right")
  145.   displayCord()
  146.   turn("right")
  147.   displayCord()
  148.   move("back")
  149.   displayCord()
  150.   turn("left")
  151.   displayCord()
  152.  
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement