Advertisement
ravneravn

Turtle controller

Nov 14th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. mon = peripheral.wrap("right")
  2. term.redirect(mon)
  3. width, height = term.getSize()
  4. rednet.open("left")
  5. dl = {}
  6.  
  7.  
  8. --------------------------------------------
  9.  
  10. function setColor(text, background)
  11. term.setTextColor(text)
  12. term.setBackgroundColor(background)
  13. end
  14.  
  15. function drawImage(image, x, y)
  16. myImage = paintutils.loadImage(image)
  17. paintutils.drawImage(myImage, x, y)
  18. end
  19.  
  20. function writeFile()
  21. handle = fs.open("dayOrNight", "w")
  22. handle.write(time)
  23. handle.close()
  24. end
  25.  
  26. function loadFile()
  27. handle = fs.open("dayOrNight", "r")
  28. time = handle.readLine()
  29. handle.close()
  30. end
  31.  
  32. function mWrite(message, cX, cY, background, text)
  33. mon.setBackgroundColor(background)
  34. if text == nil then mon.setTextColor(colors.black)
  35. else mon.setTextColor(text)
  36. end
  37. mon.setCursorPos(cX, cY)
  38. mon.write(message)
  39. end
  40.  
  41. function backgroundColor(color)
  42. mon.setBackgroundColor(color)
  43. mon.clear()
  44. end
  45.  
  46. function drawScreen()
  47. backgroundColor(colors.lightBlue)
  48. drawImage("buttonOn", 3,2)
  49. drawImage("buttonOn", 16,2)
  50. drawImage("buttonOn", 3,6)
  51. drawImage("buttonOn", 16,6)
  52. drawImage("messageScreen", 2, 10)
  53. end
  54.  
  55. function drawButtons()
  56. drawImage("buttonOn", 3,2)
  57. drawImage("buttonOn", 16,2)
  58. drawImage("buttonOn", 3,6)
  59. drawImage("buttonOn", 16,6)
  60. end
  61.  
  62. function text()
  63. mWrite("New mine", 5, 3, colors.lime, colors.black)
  64. mWrite("Download", 5, 7, colors.lime, colors.black)
  65. mWrite("Pastebin", 18, 3, colors.lime, colors.black)
  66. mWrite("Go to", 19, 7, colors.lime, colors.black)
  67. end
  68.  
  69. function wait()
  70. event, sid, mes, dis = os.pullEvent()
  71. if event == "rednet_message" then
  72. if tY == 20 then
  73. mon.clear()
  74. drawScreen()
  75. text()
  76. tY = 10
  77. end
  78. mWrite(mes, 3, tY, colors.black, colors.white)
  79. tY = tY + 1
  80. elseif event == "monitor_touch" and mes > 1 and mes < 14 and dis > 1 and dis < 5 then newMine()
  81. elseif event == "monitor_touch" and mes > 14 and mes < 27 and dis > 1 and dis < 5 then pastebin()
  82. elseif event == "monitor_touch" and mes > 1 and mes < 14 and dis > 5 and dis < 9 then download()
  83. elseif event == "monitor_touch" and mes > 14 and mes < 27 and dis > 5 and dis < 9 then goTo()
  84. end
  85. end
  86.  
  87. function newMine()
  88. rednet.broadcast("new")
  89. drawButtons()
  90. mWrite("Sending", 5, 3, colors.lime, colors.black)
  91. mWrite("Download", 5, 7, colors.lime, colors.black)
  92. mWrite("Pastebin", 18, 3, colors.lime, colors.black)
  93. mWrite("Go to", 19, 7, colors.lime, colors.black)
  94. sleep(1)
  95. --mon.clear()
  96. drawButtons()
  97. text()
  98. --tY = 10
  99. end
  100.  
  101. function download()
  102. rednet.broadcast("download")
  103. drawButtons()
  104. mWrite("New mine", 5, 3, colors.lime, colors.black)
  105. mWrite("Sending", 6, 7, colors.lime, colors.black)
  106. mWrite("Pastebin", 18, 3, colors.lime, colors.black)
  107. mWrite("Go to", 19, 7, colors.lime, colors.black)
  108. sleep(1)
  109. --mon.clear()
  110. drawButtons()
  111. text()
  112. --tY = 10
  113. end
  114.  
  115. function pastebin()
  116. rednet.broadcast("pastebin")
  117. mon.clear()
  118. drawScreen()
  119. mWrite("New mine", 5, 3, colors.lime, colors.black)
  120. mWrite("Download", 5, 7, colors.lime, colors.black)
  121. mWrite("Sending", 18, 3, colors.lime, colors.black)
  122. mWrite("Go to", 19, 7, colors.lime, colors.black)
  123. mWrite("Enter pastebin code", (width/2)-8, 15, colors.black, colors.white)
  124. term.setCursorPos((width/2)-2, 16)
  125. code = io.read()
  126. mon.clear()
  127. drawScreen()
  128. mWrite("New mine", 5, 3, colors.lime, colors.black)
  129. mWrite("Download", 5, 7, colors.lime, colors.black)
  130. mWrite("Sending", 18, 3, colors.lime, colors.black)
  131. mWrite("Go to", 19, 7, colors.lime, colors.black)
  132. mWrite("Enter name for file", (width/2)-8, 15, colors.black, colors.white)
  133. term.setCursorPos((width/2)-2, 16)
  134. name = io.read()
  135. dl["placement"] = name
  136. dl["fileName"] = code
  137. pastebin = textutil.serialize(dl)
  138. rednet.broadcast(pastebin)
  139. sleep(1)
  140. --mon.clear()
  141. drawButtons()
  142. text()
  143. --tY = 10
  144. end
  145.  
  146. function goTo()
  147. rednet.broadcast("go up")
  148. mon.clear()
  149. drawScreen()
  150. mWrite("New mine", 5, 3, colors.lime, colors.black)
  151. mWrite("Download", 5, 7, colors.lime, colors.black)
  152. mWrite("Pastebin", 18, 3, colors.lime, colors.black)
  153. mWrite("Sending", 18, 7, colors.lime, colors.black)
  154. mWrite("Enter Y level to go to", (width/2)-11, 15, colors.black, colors.white)
  155. term.setCursorPos((width/2)-11, 16)
  156. level = io.read()
  157. rednet.broadcast(level)
  158. sleep(1)
  159. --mon.clear()
  160. drawButtons()
  161. text()
  162. --tY = 10
  163. end
  164.  
  165.  
  166. --------------------------------------------------
  167.  
  168. tY = 10
  169. drawScreen()
  170. text()
  171. while true do
  172. wait()
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement