Advertisement
Guest User

Untitled

a guest
Oct 20th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. if posx == nil then posx = 1 end
  2. if posy == nil then posy = 0 end
  3.  
  4. if fieldx == nil then fieldx = 9 end
  5. if fieldy == nil then fieldy = 9 end
  6.  
  7. if wait == nil then wait = 5 end
  8. if waitafter == nil then waitafter = true end
  9.  
  10. function coord()
  11. print("Position: "..posx.." / "..posy)
  12. end
  13.  
  14. function iposx()
  15. posx = posx + 1
  16. end
  17.  
  18. function iposy()
  19. posy = posy + 1
  20. end
  21.  
  22. function dposx()
  23. posx = posx - 1
  24. end
  25.  
  26. function dposy()
  27. posy = posy - 1
  28. end
  29.  
  30. function mine()
  31.     print("doing stuff here")
  32. end
  33.  
  34. function move(dx, dy)
  35.     moveDirX(posx, dx)
  36.     moveDirY(posy, dy)
  37. end
  38.  
  39. function moveDirX(ax, dx)
  40.     if ax == 0 then step(dx, 1) else
  41.         delta = ax-dx
  42.         step(delta, 0)
  43.     end
  44. end
  45.  
  46. function moveDirY(ay, dy)
  47.     if ay == 0 then step(dy, 1) else
  48.         delta = ay-dy
  49.         step(delta, 1)
  50.     end
  51. end
  52.  
  53. function betrag(zahl1)
  54.     if zahl1 < 0 then return zahl1 * -1
  55.     else return zahl1
  56.     end
  57. end
  58.  
  59. function step(count, axis)
  60.     if axis == 0 then
  61.         if count > 0 then
  62.             moveLeft(betrag(count))
  63.             return true
  64.         elseif count < 0 then
  65.             moveRight(betrag(count))
  66.             return true
  67.         end
  68.     elseif axis == 1 then
  69.         if count > 0 then
  70.             moveBack(betrag(count))
  71.             return true
  72.         elseif count < 0 then
  73.             moveForward(betrag(count))
  74.             return true
  75.         end
  76.     end
  77.    
  78. end
  79.  
  80. function moveRight(ci)
  81.     turtle.turnRight(1)
  82.         for i=1, ci do
  83.             print("Moving right. New: "..(posx+1).." / "..posy)
  84.             if not turtle.detect() then
  85.                 turtle.forward()
  86.                 iposx()
  87.             else print("I crashed right!")
  88.             end
  89.         end
  90.     turtle.turnLeft(1)
  91. end
  92.  
  93. function moveLeft(ci)
  94.     turtle.turnLeft(1)
  95.         for i=1, ci do
  96.             print("Moving left. New: "..(posx-1).." / "..posy)
  97.             if not turtle.detect() then
  98.                 turtle.forward()
  99.                 dposx()
  100.             else print("I crashed left!")
  101.             end
  102.         end
  103.     turtle.turnRight(1)
  104. end
  105.  
  106. function moveForward(ci)
  107.     for i=1, ci do
  108.         print("Moving forward. New: "..posx.." / "..(posy+1))
  109.         if not turtle.detect() then
  110.             turtle.forward()
  111.             iposy()
  112.         else print("I crashed forward!")
  113.         end
  114.     end
  115. end
  116.  
  117. function moveBack(ci)
  118.     turn180()
  119.     for i=1, ci do
  120.         print("Moving back. New: "..posx.." / "..(posy-1))
  121.         if not turtle.detect() then
  122.             turtle.forward()
  123.             dposy()
  124.         else print("I crashed backward!")
  125.         end
  126.     end
  127.     turn180()
  128. end
  129.  
  130. function turn180()
  131. turtle.turnRight()
  132. turtle.turnRight()
  133. end
  134.  
  135.  
  136. if not waitafter then sleep(wait) end
  137. --.....
  138. move(1,1)
  139. move(1,1)
  140. if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement