Advertisement
bddap

bmov0.0

Mar 31st, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. x = 0
  2. y = 0
  3. z = 0
  4. o = 0
  5.  
  6. doAttack = false
  7. doDig = false
  8.  
  9. function f()
  10.   while not turtle.forward() do
  11.     moveFail()
  12.   end
  13.   if o == 0 then z=z-1 end
  14.   if o == 1 then x=x+1 end
  15.   if o == 2 then z=z+1 end
  16.   if o == 3 then x=x-1 end
  17.   p()
  18. end
  19.  
  20. --queue this many functions to do
  21. function q(func,reps)
  22.   for i=1,reps do
  23.     func()
  24.   end
  25. end
  26.  
  27. function b()
  28.   if turtle.back() then
  29.     if o == 0 then z=z+1 end
  30.     if o == 1 then x=x-1 end
  31.     if o == 2 then z=z+1 end
  32.     if o == 3 then x=x+1 end
  33.     p()
  34.     return true
  35.   end
  36.   return false
  37. end
  38.  
  39. function d()
  40.   if turtle.down() then
  41.     y = y - 1
  42.     p()
  43.     return true
  44.   end
  45.   return false
  46. end
  47.  
  48. function u()
  49.   if turtle.up() then
  50.     y = y + 1
  51.     p()
  52.     return true
  53.   end
  54.   return false
  55. end
  56.  
  57. function r()
  58.   turtle.turnRight()
  59.   o=(o+1)%4
  60.   p()
  61. end
  62.  
  63. function l()
  64.   turtle.turnLeft()
  65.   o=(o-1)%4
  66.   p()
  67. end
  68.  
  69. function moveFail(direction)
  70. end
  71.  
  72. function p()
  73.   term.clear()
  74.   term.setCursorPos(1,1)
  75.   io.write("x == ") print(x)
  76.   io.write("y == ") print(y)
  77.   io.write("z == ") print(z)
  78.   io.write("o == ") print(o)
  79. end
  80.  
  81. function turnto(odest)
  82.   odest = odest % 4
  83.   while not (o == odest) do
  84.     l()
  85.   end
  86. end
  87.  
  88. function gx(xdest)
  89.   if xdest > x then turnto(1)
  90.     q(f,xdest-x)
  91.   end
  92.   if xdest < x then turnto(3)
  93.     q(f,x-xdest)
  94.   end
  95.   --does nothing if x == xdest
  96. end
  97.  
  98. function gy(ydest)
  99.   if ydest > y then q(u,ydest-y) end
  100.   if ydest < y then q(d,y-ydest) end
  101. end
  102.  
  103. function gz(zdest)
  104.   if zdest > z then turnto(2)
  105.     q(f,zdest-z)
  106.   end
  107.   if zdest < z then turnto(0)
  108.     q(f,z-zdest)
  109.   end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement