Advertisement
Guest User

motion

a guest
May 22nd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. local x,y,z,dir=0,0,0,0
  2. local fuelSlot=1
  3. function refuel()
  4. turtle.select(fuelSlot)
  5. turtle.refuel(1)
  6. end
  7. function forward()
  8. reussit=turtle.forward()
  9. if not reussit then
  10. if turtle.getFuelLevel()==0 then
  11. refuel()
  12. else
  13. turtle.dig()
  14. end
  15. reussit=turtle.forward()
  16. end
  17. if reussit then
  18. if dir==0 then
  19. x=x+1
  20. elseif dir==1 then
  21. y=y+1
  22. elseif dir==2 then
  23. x=x-1
  24. elseif dir==3 then
  25. y=y-1
  26. end
  27. end
  28. return reussit
  29. end
  30. function back()
  31. reussit=turtle.back()
  32. if not reussit then
  33. if turtle.getFuelLevel()==0 then
  34. refuel()
  35. end
  36. reussit=turtle.back()
  37. end
  38. if reussit then
  39. if dir==0 then
  40. x=x-1
  41. elseif dir==1 then
  42. y=y-1
  43. elseif dir==2 then
  44. x=x+1
  45. elseif dir==3 then
  46. y=y+1
  47. end
  48. end
  49. return reussit
  50. end
  51. function up()
  52. reussit=turtle.up()
  53. if not reussit then
  54. if turtle.getFuelLevel()==0 then
  55. refuel()
  56. else
  57. turtle.digUp()
  58. end
  59. reussit=turtle.up()
  60. end
  61. if reussit then
  62. z=z+1
  63. end
  64. return reussit
  65. end
  66. function down()
  67. reussit=turtle.down()
  68. if not reussit then
  69. if turtle.getFuelLevel()==0 then
  70. refuel()
  71. else
  72. turtle.digDown()
  73. end
  74. reussit=turtle.down()
  75. end
  76. if reussit then
  77. z=z-1
  78. end
  79. return reussit
  80. end
  81. function turnRight()
  82. turtle.turnRight()
  83. dir=(dir+1)%4
  84. end
  85. function turnLeft()
  86. turtle.turnLeft()
  87. dir=dir-1
  88. if dir==-1 then
  89. dir=0
  90. end
  91. end
  92. function setDir(d)
  93. dif=dir-d
  94. if math.abs(dif)>2 then
  95. if dif>0 then
  96. dif=dif-4
  97. else
  98. dif=dif+4
  99. end
  100. end
  101. print(dif)
  102. while dir~=d do
  103. print(dir)
  104. if dif>0 then
  105. turnLeft()
  106. else
  107. turnRight()
  108. end
  109. end
  110. end
  111. function reset()
  112. x,y,z,dir=0,0,0,0
  113. end
  114. function setFuelSlot(s)
  115. fuelSlot=s
  116. end
  117. function getPosition()
  118. return x,y,z,dir
  119. end
  120. function setPosition(px,py,pz,pdir)
  121. x,y,z,dir=px,py,pz,pdir
  122. end
  123. function getDir()
  124. return dir
  125. end
  126. function setDir(d)
  127. dir=d
  128. end
  129. function getX()
  130. return x
  131. end
  132. function getY()
  133. return y
  134. end
  135. function getZ()
  136. return z
  137. end
  138. function setX(p)
  139. x=p
  140. end
  141. function setY(p)
  142. y=p
  143. end
  144. function setZ(p)
  145. z=p
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement