DustinRosebery

RCturtle

Oct 13th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------------------------------
  2. -- Name: RCturtle
  3. -- version: 1.1
  4. -- Author: Dustin Rosebery
  5. -- Description: Program that provides touchscreen turtle
  6. --              operation including movement, inventory,
  7. --              placing, and mining.
  8. -- setup: 4x4 advanced monitors with an advanced computer
  9. --          on the bottom of the monitors with a wireless
  10. --          modem on the right side. Also requires an
  11. --          advanced turtle with RCreceive installed
  12. --          and a wireless modem on the left side.
  13. ------------------------------------------------------------
  14.  
  15. m = peripheral.wrap("top")
  16. modem = peripheral.wrap("right")
  17. m.clear()
  18. buttons = {}
  19.  
  20. --------------------------------------------------
  21. -- button creation
  22. --------------------------------------------------
  23.  
  24. -- Directional button background color
  25. dirColor = colors.red
  26. -- Inventory button background color
  27. invColor = colors.white
  28. -- Inventory button text color
  29. invTextColor = colors.black
  30. ---------------------------------
  31. --Directional buttons
  32. ---------------------------------
  33.  
  34. -- fbut (forward)
  35. fxMin = 23
  36. fxSize = 7
  37. fxMax = fxMin + fxSize - 1
  38.  
  39. fyMin = 6
  40. fySize = 4
  41. fyMax = fyMin + fySize - 1
  42.  
  43. fbut = window.create(m,fxMin,fyMin,fxSize,fySize)
  44. fbut.setBackgroundColor(dirColor)
  45. fbut.restoreCursor()
  46. fbut.redraw()
  47. fbut.setCursorPos(1,2)
  48. fbut.write("forward")
  49.  
  50. -- bbut (backwards)
  51. bxMin = 23
  52. bxSize = 7
  53. bxMax = bxMin + bxSize - 1
  54.  
  55. byMin = 12
  56. bySize = 4
  57. byMax = byMin + bySize - 1
  58.  
  59. bbut = window.create(m,bxMin,byMin,bxSize,bySize)
  60. bbut.setBackgroundColor(dirColor)
  61. bbut.redraw()
  62. bbut.restoreCursor()
  63. bbut.setCursorPos(1,2)
  64. bbut.write(" back  ")
  65. bbut.redraw()
  66.  
  67. -- lbut (left)
  68. lxMin = 19
  69. lxSize = 7
  70. lxMax = lxMin + lxSize - 1
  71.  
  72. lyMin = 9
  73. lySize = 4
  74. lyMax = lyMin + lySize - 1
  75.  
  76. lbut = window.create(m,lxMin,lyMin,lxSize,lySize)
  77. lbut.setBackgroundColor(dirColor)
  78. lbut.redraw()
  79. lbut.setCursorPos(1,2)
  80. lbut.write(" left  ")
  81.  
  82. -- rbut (right)
  83. rxMin = 27
  84. rxSize = 7
  85. rxMax = rxMin + rxSize - 1
  86.  
  87. ryMin = 9
  88. rySize = 4
  89. ryMax = ryMin + rySize - 1
  90.  
  91. rbut = window.create(m,rxMin,ryMin,rxSize,rySize)
  92. rbut.setBackgroundColor(dirColor)
  93. rbut.redraw()
  94. rbut.setCursorPos(1,2)
  95. rbut.write(" right ")
  96.  
  97. -- ubut (up)
  98. uxMin = 36
  99. uxSize = 2
  100. uxMax = uxMin + uxSize - 1
  101.  
  102. uyMin = 7
  103. uySize = 3
  104. uyMax = uyMin + uySize - 1
  105.  
  106. ubut = window.create(m,uxMin,uyMin,uxSize,uySize)
  107. ubut.setBackgroundColor(dirColor)
  108. ubut.restoreCursor()
  109. for i = 1, uySize do
  110.   ubut.setCursorPos(1,i)
  111.   ubut.write("  ")
  112. end
  113. m.setCursorPos(36,6)
  114. m.write("up")
  115.  
  116. -- dbut (down)
  117. dxMin = 36
  118. dxSize = 2
  119. dxMax = dxMin + dxSize - 1
  120.  
  121. dyMin = 11
  122. dySize = 3
  123. dyMax = dyMin + dySize - 1
  124.  
  125. dbut = window.create(m,dxMin,dyMin,dxSize,dySize)
  126. dbut.setBackgroundColor(dirColor)
  127. dbut.restoreCursor()
  128. for i = 1, dySize do
  129.   dbut.setCursorPos(1,i)
  130.   dbut.write("  ")
  131. end
  132. m.setCursorPos(35,14)
  133. m.write("down")
  134.  
  135. ----------------------------
  136. --Inventory Buttons
  137. ----------------------------
  138. ixMin = 1
  139. ixSize = 14
  140. ixMax = ixMin + ixSize - 1
  141. iySize = 1
  142.  
  143. -- i0
  144. i0yMin = 1
  145. i0 = window.create(m,ixMin,i0yMin,ixSize,iySize)
  146. i0.setTextColor(colors.black)
  147. i0.restoreCursor()
  148. i0.write("Inventory:")
  149.  
  150. -- i1
  151. i1yMin = 2
  152. i1 = window.create(m,ixMin,i1yMin,ixSize,iySize)
  153. i1.setBackgroundColor(invColor)
  154. i1.setTextColor(invTextColor)
  155. i1.restoreCursor()
  156. i1.write("              ")
  157.  
  158. -- i2
  159. i2yMin = 3
  160. i2 = window.create(m,ixMin,i2yMin,ixSize,iySize)
  161. i2.setBackgroundColor(invColor)
  162. i2.setTextColor(invTextColor)
  163. i2.restoreCursor()
  164. i2.write("              ")
  165.  
  166. -- i3
  167. i3yMin = 4
  168. i3 = window.create(m,ixMin,i3yMin,ixSize,iySize)
  169. i3.setBackgroundColor(invColor)
  170. i3.setTextColor(invTextColor)
  171. i3.restoreCursor()
  172. i3.write("              ")
  173.  
  174. -- i4
  175. i4yMin = 5
  176. i4 = window.create(m,ixMin,i4yMin,ixSize,iySize)
  177. i4.setBackgroundColor(invColor)
  178. i4.setTextColor(invTextColor)
  179. i4.restoreCursor()
  180. i4.write("              ")
  181.  
  182. -- i5
  183. i5yMin = 6
  184. i5 = window.create(m,ixMin,i5yMin,ixSize,iySize)
  185. i5.setBackgroundColor(invColor)
  186. i5.setTextColor(invTextColor)
  187. i5.restoreCursor()
  188. i5.write("              ")
  189.  
  190. -- i6
  191. i6yMin = 7
  192. i6 = window.create(m,ixMin,i6yMin,ixSize,iySize)
  193. i6.setBackgroundColor(invColor)
  194. i6.setTextColor(invTextColor)
  195. i6.restoreCursor()
  196. i6.write("              ")
  197.  
  198. -- i7
  199. i7yMin = 8
  200. i7 = window.create(m,ixMin,i7yMin,ixSize,iySize)
  201. i7.setBackgroundColor(invColor)
  202. i7.setTextColor(invTextColor)
  203. i7.restoreCursor()
  204. i7.write("              ")
  205.  
  206. -- i8
  207. i8yMin = 9
  208. i8 = window.create(m,ixMin,i8yMin,ixSize,iySize)
  209. i8.setBackgroundColor(invColor)
  210. i8.setTextColor(invTextColor)
  211. i8.restoreCursor()
  212. i8.write("              ")
  213.  
  214. -- i9
  215. i9yMin = 10
  216. i9 = window.create(m,ixMin,i9yMin,ixSize,iySize)
  217. i9.setBackgroundColor(invColor)
  218. i9.setTextColor(invTextColor)
  219. i9.restoreCursor()
  220. i9.write("              ")
  221.  
  222. -- i10
  223. i10yMin = 11
  224. i10 = window.create(m,ixMin,i10yMin,ixSize,iySize)
  225. i10.setBackgroundColor(invColor)
  226. i10.setTextColor(invTextColor)
  227. i10.restoreCursor()
  228. i10.write("              ")
  229.  
  230. -- i11
  231. i11yMin = 12
  232. i11 = window.create(m,ixMin,i11yMin,ixSize,iySize)
  233. i11.setBackgroundColor(invColor)
  234. i11.setTextColor(invTextColor)
  235. i11.restoreCursor()
  236. i11.write("              ")
  237.  
  238. -- i12
  239. i12yMin = 13
  240. i12 = window.create(m,ixMin,i12yMin,ixSize,iySize)
  241. i12.setBackgroundColor(invColor)
  242. i12.setTextColor(invTextColor)
  243. i12.restoreCursor()
  244. i12.write("              ")
  245.  
  246. -- i13
  247. i13yMin = 14
  248. i13 = window.create(m,ixMin,i13yMin,ixSize,iySize)
  249. i13.setBackgroundColor(invColor)
  250. i13.setTextColor(invTextColor)
  251. i13.restoreCursor()
  252. i13.write("              ")
  253.  
  254. -- i14
  255. i14yMin = 15
  256. i14 = window.create(m,ixMin,i14yMin,ixSize,iySize)
  257. i14.setBackgroundColor(invColor)
  258. i14.setTextColor(invTextColor)
  259. i14.restoreCursor()
  260. i14.write("              ")
  261.  
  262. -- i15
  263. i15yMin = 16
  264. i15 = window.create(m,ixMin,i15yMin,ixSize,iySize)
  265. i15.setBackgroundColor(invColor)
  266. i15.setTextColor(invTextColor)
  267. i15.restoreCursor()
  268. i15.write("              ")
  269.  
  270. -- i16
  271. i16yMin = 17
  272. i16 = window.create(m,ixMin,i16yMin,ixSize,iySize)
  273. i16.setBackgroundColor(invColor)
  274. i16.setTextColor(invTextColor)
  275. i16.restoreCursor()
  276. i16.write("              ")
  277.  
  278.  
  279. -- inventory check
  280. function updateInv()
  281.   --TODO update inventory information
  282. end
  283.  
  284.  
  285. -- cleans item names by removing modID:
  286. funtion cleanName()
  287. table result = []
  288.   for i in string.gmatch(name, ":") do
  289.     result = i
  290.   ends
  291.   return result[2]
  292. end
  293.  
  294.  
  295. -- input listener
  296. while(true) do
  297.  
  298.   rednet.open("right")
  299.  
  300.   event, side, xpos, ypos = os.pullEvent("monitor_touch")
  301.   write(xpos .. ", " .. ypos.."\n") -- show touch location
  302.  
  303. -- directional control
  304.   if (     xpos >= fxMin and xpos <= fxMax and
  305.            ypos >= fyMin and ypos <= fyMax )then
  306.     rednet.broadcast("forward")
  307.   elseif ( xpos >= bxMin and xpos <= bxMax and
  308.            ypos >= byMin and ypos <= byMax )then
  309.     rednet.broadcast("back")
  310.   elseif ( xpos >= lxMin and xpos <= lxMax and
  311.            ypos >= lyMin and ypos <= lyMax )then
  312.     rednet.broadcast("left")
  313.   elseif ( xpos >= rxMin and xpos <= rxMax and
  314.            ypos >= ryMin and ypos <= ryMax )then
  315.     rednet.broadcast("right")
  316.   elseif ( xpos >= uxMin and xpos <= uxMax and
  317.            ypos >= uyMin and ypos <= uyMax )then
  318.     rednet.broadcast("up")
  319.   elseif ( xpos >= dxMin and xpos <= dxMax and
  320.            ypos >= dyMin and ypos <= dyMax )then
  321.     rednet.broadcast("down")
  322.  
  323. -- inventory control
  324.   elseif ( xpos >= ixMin and xpos <= ixMax )then
  325.     if (   ypos == i1yMin ) then
  326.       rednet.broadcast(1)
  327.       senderID, message, protocol = rednet.receive()
  328.       i1.setCursorPos(1,1)
  329.       i1.write(message)
  330.     elseif( ypos == i2yMin ) then
  331.       rednet.broadcast(2)
  332.     elseif( ypos == i3yMin ) then
  333.       rednet.broadcast(3)
  334.     elseif( ypos == i4yMin ) then
  335.       rednet.broadcast(4)
  336.     elseif( ypos == i5yMin ) then
  337.       rednet.broadcast(5)
  338.     elseif( ypos == i6yMin ) then
  339.       rednet.broadcast(6)
  340.     elseif( ypos == i7yMin ) then
  341.       rednet.broadcast(7)
  342.     elseif( ypos == i8yMin ) then
  343.       rednet.broadcast(8)
  344.     elseif( ypos == i9yMin ) then
  345.       rednet.broadcast(9)
  346.     elseif( ypos == i10yMin ) then
  347.       rednet.broadcast(10)
  348.     elseif( ypos == i11yMin ) then
  349.       rednet.broadcast(11)
  350.     elseif( ypos == i12yMin ) then
  351.       rednet.broadcast(12)
  352.     elseif( ypos == i13yMin ) then
  353.       rednet.broadcast(13)
  354.     elseif( ypos == i14yMin ) then
  355.       rednet.broadcast(14)
  356.     elseif( ypos == i15yMin ) then
  357.       rednet.broadcast(15)
  358.     elseif( ypos == i16yMin ) then
  359.       rednet.broadcast(16)
  360.     end
  361.   end
  362. end
Add Comment
Please, Sign In to add comment