Advertisement
Guest User

Untitled

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