Xgamer911

Control

May 27th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.16 KB | None | 0 0
  1. -- slots 1-8 Sand
  2. -- slots 9-12 cobblestone
  3. -- slot 13 empty
  4. -- slot 14 cobblestone
  5. -- slot 15 sand
  6. -- slot 16 coal
  7.  
  8. local w,h = term.getSize()
  9. local selection = 0
  10. local internalselection = 0
  11. local range = 0
  12. local currentrange = 0
  13. local ypos = 1
  14. local fuel
  15. local fuelava
  16. local counter = 1
  17. local sandcounter=0
  18. local cobblecounter=0
  19.  
  20. --Some draw functions to get us started
  21. local function printCentered(str, ypos)
  22. term.setCursorPos(w/2 - #str/2, ypos)
  23. term.write(str)
  24. end
  25.  
  26. local function printFarLeft(str, ypos)
  27. term.setCursorPos(1, ypos)
  28. term.write(str)
  29. end
  30.  
  31. local function printLeft(str, ypos)
  32. term.setCursorPos(5, ypos)
  33. term.write(str)
  34. end
  35.  
  36. local function printLeft2(str, ypos)
  37. term.setCursorPos(10, ypos)
  38. term.write(str)
  39. end
  40.  
  41. local function printRight(str, ypos)
  42. term.setCursorPos(w - 15, ypos)
  43. term.write(str)
  44. end
  45.  
  46. local function printRight2(str, ypos)
  47. term.setCursorPos(w - 25, ypos)
  48. term.write(str)
  49. end
  50.  
  51. local function printFarRight(str, ypos)
  52. term.setCursorPos(w - #str, ypos)
  53. term.write(str)
  54. end
  55.  
  56. function drawHeader()
  57. printCentered("Turtle Control", 1)
  58. printCentered(string.rep("-", w+1), 2)
  59.  
  60. -- print fuel level
  61. fuel = turtle.getFuelLevel()
  62. printFarLeft("Fuel " ,3)
  63. print(fuel)
  64.  
  65. -- print avilable fuel
  66. fuelava = turtle.getItemCount(16)
  67. printFarLeft("Fuel Available " ,5)
  68. print(fuelava)
  69.  
  70. -- Print Range
  71. printRight("Range Left "..tostring(range),5)
  72. end
  73.  
  74. function drawMainMenu()
  75. printLeft2("1. Forward", 7)
  76. printRight("5. Up", 7)
  77.  
  78. printLeft2("2. Backward", 8)
  79. printRight("6. Down", 8)
  80.  
  81. printLeft2("3. Left", 9)
  82.  
  83. printLeft2("4. Right", 10)
  84. printRight("8. Quit", 10)
  85.  
  86. printLeft2("Selection: ", 12)
  87. selection = tonumber(read())
  88. end
  89.  
  90. function forward()
  91. term.clear()
  92. term.setCursorPos(1,1)
  93. internalselection=0
  94. drawHeader()
  95.  
  96. printLeft("Forward", 7)
  97. printLeft("-------", 8)
  98. printLeft("1. Forward 1", 9)
  99. printRight("3. Main Menu", 9)
  100. printLeft("2. Forward range", 10)
  101.  
  102. printLeft("Selection: ", 12)
  103. internalselection = tonumber(read())
  104.  
  105. if internalselection==1 then
  106. turtle.forward()
  107. term.clear()
  108. term.setCursorPos(1,1)
  109. end
  110.  
  111. if internalselection==2 then
  112. term.clear()
  113. term.setCursorPos(1,1)
  114.  
  115. drawHeader()
  116.  
  117. printLeft("Forward Range", 7)
  118. printLeft("-------------", 8)
  119. printLeft("How far: ", 9)
  120. currentrange = 0
  121. range = tonumber(read())
  122.  
  123. repeat
  124. term.clear()
  125. term.setCursorPos(1,1)
  126. drawHeader()
  127.  
  128. turtle.forward()
  129. currentrange = currentrange + 1
  130. until currentrange == range
  131.  
  132. range=0
  133. end
  134. end
  135.  
  136. function backward()
  137. term.clear()
  138. term.setCursorPos(1,1)
  139. internalselection=0
  140. drawHeader()
  141.  
  142. printLeft("Backward", 7)
  143. printLeft("--------", 8)
  144. printLeft("1. Backward 1", 9)
  145. printRight("3. Main Menu", 9)
  146. printLeft("2. Backward range", 10)
  147.  
  148. printLeft("Selection: ", 12)
  149. internalselection = tonumber(read())
  150.  
  151. if internalselection==1 then
  152. turtle.back()
  153. term.clear()
  154. term.setCursorPos(1,1)
  155. end
  156.  
  157. if internalselection==2 then
  158. term.clear()
  159. term.setCursorPos(1,1)
  160.  
  161. drawHeader()
  162.  
  163. printLeft("Backward Range", 7)
  164. printLeft("-------------", 8)
  165. printLeft("How far: ", 9)
  166. currentrange = 0
  167. range = tonumber(read())
  168.  
  169. repeat
  170. term.clear()
  171. term.setCursorPos(1,1)
  172. drawHeader()
  173.  
  174. turtle.back()
  175. currentrange = currentrange + 1
  176. until currentrange == range
  177.  
  178. range=0
  179. end
  180.  
  181. if internalselection==3 then
  182. term.clear()
  183. term.setCursorPos(1,1)
  184. internalselection=0
  185. selection=0
  186. main()
  187. end
  188. end
  189.  
  190. function up()
  191. term.clear()
  192. term.setCursorPos(1,1)
  193. internalselection=0
  194. drawHeader()
  195.  
  196. printLeft("Up", 7)
  197. printLeft("--", 8)
  198. printLeft("1. Up 1", 9)
  199. printRight("3. Main Menu", 9)
  200. printLeft("2. Up range", 10)
  201.  
  202. printLeft("Selection: ", 12)
  203. internalselection = tonumber(read())
  204.  
  205. if internalselection==1 then
  206. turtle.up()
  207. term.clear()
  208. term.setCursorPos(1,1)
  209. end
  210.  
  211. if internalselection==2 then
  212. term.clear()
  213. term.setCursorPos(1,1)
  214.  
  215. drawHeader()
  216.  
  217. printLeft("Up Range", 7)
  218. printLeft("--------", 8)
  219. printLeft("How far: ", 9)
  220. currentrange = 0
  221. range = tonumber(read())
  222.  
  223. repeat
  224. term.clear()
  225. term.setCursorPos(1,1)
  226. drawHeader()
  227.  
  228. turtle.up()
  229. currentrange = currentrange + 1
  230. until currentrange == range
  231.  
  232. range=0
  233. end
  234.  
  235. if internalselection==3 then
  236. term.clear()
  237. term.setCursorPos(1,1)
  238. internalselection=0
  239. selection=0
  240. main()
  241. end
  242. end
  243.  
  244. function down()
  245. term.clear()
  246. term.setCursorPos(1,1)
  247. internalselection=0
  248. drawHeader()
  249.  
  250. printLeft("Down", 7)
  251. printLeft("----", 8)
  252. printLeft("1. Down 1", 9)
  253. printRight("3. Main Menu", 9)
  254. printLeft("2. Down range", 10)
  255.  
  256. printLeft("Selection: ", 12)
  257. internalselection = tonumber(read())
  258.  
  259. if internalselection==1 then
  260. turtle.down()
  261. term.clear()
  262. term.setCursorPos(1,1)
  263. end
  264.  
  265. if internalselection==2 then
  266. term.clear()
  267. term.setCursorPos(1,1)
  268.  
  269. drawHeader()
  270.  
  271. printLeft("Down Range", 7)
  272. printLeft("----------", 8)
  273. printLeft("How far: ", 9)
  274. currentrange = 0
  275. range = tonumber(read())
  276.  
  277. repeat
  278. term.clear()
  279. term.setCursorPos(1,1)
  280. drawHeader()
  281.  
  282. turtle.down()
  283. currentrange = currentrange + 1
  284. until currentrange == range
  285.  
  286. range=0
  287. end
  288.  
  289. if internalselection==3 then
  290. term.clear()
  291. term.setCursorPos(1,1)
  292. internalselection=0
  293. selection=0
  294. main()
  295. end
  296. end
  297.  
  298. function main()
  299. --PROGRAM START
  300. term.clear()
  301. term.setCursorPos(1,1)
  302.  
  303. while true do
  304. drawHeader()
  305. drawMainMenu()
  306.  
  307. if fuel < 5 then
  308. turtle.select(16)
  309. turtle.refuel(1)
  310. turtle.select(1)
  311. end
  312.  
  313. if selection==1 then
  314. forward()
  315. end
  316.  
  317. if selection==2 then
  318. backward()
  319. end
  320.  
  321. if selection==3 then
  322. turtle.turnLeft()
  323. term.clear()
  324. term.setCursorPos(1,1)
  325. end
  326.  
  327. if selection==4 then
  328. turtle.turnRight()
  329. term.clear()
  330. term.setCursorPos(1,1)
  331. end
  332.  
  333. if selection==5 then
  334. up()
  335. end
  336.  
  337. if selection==6 then
  338. down()
  339. end
  340.  
  341.  
  342. if selection==8 then
  343. term.clear()
  344. term.setCursorPos(1,1)
  345. break
  346. end
  347.  
  348. end
  349. end
  350.  
  351. main()
Advertisement
Add Comment
Please, Sign In to add comment