Guest User

rcturtle

a guest
Oct 12th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.36 KB | None | 0 0
  1. m = peripheral.wrap("top")
  2. modem = peripheral.wrap("right")
  3. m.clear()
  4. buttons = {}
  5.  
  6. --------------------------------------------------
  7. -- button creation
  8. --------------------------------------------------
  9.  
  10. -- Directional button color
  11. dirColor = colors.red
  12. -- Inventory button color
  13. invColor = colors.white
  14.  
  15. ---------------------------------
  16. --Directional buttons
  17. ---------------------------------
  18.  
  19. -- fbut (forward)
  20. fxMin = 23
  21. fxSize = 7
  22. fxMax = fxMin + fxSize - 1
  23.  
  24. fyMin = 6
  25. fySize = 4
  26. fyMax = fyMin + fySize - 1
  27.  
  28. fbut = window.create(m,fxMin,fyMin,fxSize,fySize)
  29. fbut.setBackgroundColor(dirColor)
  30. fbut.restoreCursor()
  31. fbut.redraw()
  32. fbut.setCursorPos(1,2)
  33. fbut.write("forward")
  34.  
  35. -- bbut (backwards)
  36. bxMin = 23
  37. bxSize = 7
  38. bxMax = bxMin + bxSize - 1
  39.  
  40. byMin = 12
  41. bySize = 4
  42. byMax = byMin + bySize - 1
  43.  
  44. bbut = window.create(m,bxMin,byMin,bxSize,bySize)
  45. bbut.setBackgroundColor(dirColor)
  46. bbut.redraw()
  47. bbut.restoreCursor()
  48. bbut.setCursorPos(1,2)
  49. bbut.write(" back  ")
  50. bbut.redraw()
  51.  
  52. -- lbut (left)
  53. lxMin = 19
  54. lxSize = 7
  55. lxMax = lxMin + lxSize - 1
  56.  
  57. lyMin = 9
  58. lySize = 4
  59. lyMax = lyMin + lySize - 1
  60.  
  61. lbut = window.create(m,lxMin,lyMin,lxSize,lySize)
  62. lbut.setBackgroundColor(dirColor)
  63. lbut.redraw()
  64. lbut.setCursorPos(1,2)
  65. lbut.write(" left  ")
  66.  
  67. -- rbut (right)
  68. rxMin = 27
  69. rxSize = 7
  70. rxMax = rxMin + rxSize - 1
  71.  
  72. ryMin = 9
  73. rySize = 4
  74. ryMax = ryMin + rySize - 1
  75.  
  76. rbut = window.create(m,rxMin,ryMin,rxSize,rySize)
  77. rbut.setBackgroundColor(dirColor)
  78. rbut.redraw()
  79. rbut.setCursorPos(1,2)
  80. rbut.write(" right ")
  81.  
  82. -- ubut (up)
  83. uxMin = 36
  84. uxSize = 2
  85. uxMax = uxMin + uxSize - 1
  86.  
  87. uyMin = 7
  88. uySize = 3
  89. uyMax = uyMin + uySize - 1
  90.  
  91. ubut = window.create(m,uxMin,uyMin,uxSize,uySize)
  92. ubut.setBackgroundColor(dirColor)
  93. ubut.restoreCursor()
  94. for i = 1, uySize do
  95.   ubut.setCursorPos(1,i)
  96.   ubut.write("  ")
  97. end
  98. m.setCursorPos(36,6)
  99. m.write("up")
  100.  
  101. -- dbut (down)
  102. dxMin = 36
  103. dxSize = 2
  104. dxMax = dxMin + dxSize - 1
  105.  
  106. dyMin = 11
  107. dySize = 3
  108. dyMax = dyMin + dySize - 1
  109.  
  110. dbut = window.create(m,dxMin,dyMin,dxSize,dySize)
  111. dbut.setBackgroundColor(dirColor)
  112. dbut.restoreCursor()
  113. for i = 1, dySize do
  114.   dbut.setCursorPos(1,i)
  115.   dbut.write("  ")
  116. end
  117. m.setCursorPos(35,14)
  118. m.write("down")
  119.  
  120. ----------------------------
  121. --Inventory Buttons
  122. ----------------------------
  123. ixMin = 1
  124. ixSize = 14
  125. ixMax = ixMin + ixSize - 1
  126. iySize = 1
  127.  
  128. -- i1
  129. iyMin = 2
  130. i1 = window.create(m,ixMin,iyMin,ixSize,iySize)
  131.  
  132.  
  133.  
  134.  
  135. -- input listener
  136. while(true) do
  137.   event, side, xpos, ypos = os.pullEvent("monitor_touch")
  138.   write(xpos .. ", " .. ypos.."\n")
  139.   rednet.open("right")
  140.  
  141.   if (     xpos >= fxMin and xpos <= fxMax and
  142.            ypos >= fyMin and ypos <= fyMax )then
  143.     rednet.broadcast("forward")
  144.   elseif ( xpos >= bxMin and xpos <= bxMax and
  145.            ypos >= byMin and ypos <= byMax )then
  146.     rednet.broadcast("back")
  147.   elseif ( xpos >= lxMin and xpos <= lxMax and
  148.            ypos >= lyMin and ypos <= lyMax )then
  149.     rednet.broadcast("left")
  150.   elseif ( xpos >= rxMin and xpos <= rxMax and
  151.            ypos >= ryMin and ypos <= ryMax )then
  152.     rednet.broadcast("right")
  153.   elseif ( xpos >= uxMin and xpos <= uxMax and
  154.            ypos >= uyMin and ypos <= uyMax )then
  155.     rednet.broadcast("up")
  156.   elseif ( xpos >= dxMin and xpos <= dxMax and
  157.            ypos >= dyMin and ypos <= dyMax )then
  158.     rednet.broadcast("down")
  159.   end
  160.  
  161. end
Advertisement
Add Comment
Please, Sign In to add comment