henoireil

Untitled

Sep 1st, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. -- Script by http://www.youtube.com/user/HomicidalRiceCake
  2.  
  3. rednet.open("right")
  4. m = peripheral.wrap("top")
  5. m.setTextScale(0.5)
  6.  
  7. local ename, eside, touchY, touchY
  8. local bEvent
  9.  
  10. local function setColor(color)
  11. m.setBackgroundColor(color)
  12. end
  13.  
  14. local function drawPixel(x, y)
  15. m.setCursorPos(x, y)
  16. m.write(" ")
  17. end
  18.  
  19. local function drawRect(startX, startY, sizeX, sizeY)
  20. if startX < 1 then
  21. startX = 1
  22. end
  23. if startY < 1 then
  24. startY = 1
  25. end
  26.  
  27. if (sizeX <= 1) and (sizeY <= 1) then
  28. drawPixel(startX, startY)
  29. return
  30. else
  31. for iy = 0, sizeY - 1 do
  32. for ix = 0, sizeX - 1 do
  33. drawPixel(startX + ix, startY + iy)
  34. end
  35. end
  36. end
  37. end
  38.  
  39. local function renderButtons()
  40. setColor(colors.lightGray)
  41. drawRect(3, 4, 11, 3)
  42. drawRect(6, 2, 5, 7)
  43. drawRect(2, 8, 3, 2)
  44.  
  45. drawRect(2, 2, 3, 2)
  46.  
  47. drawRect(12, 8, 3, 2)
  48.  
  49. setColor(colors.white)
  50. drawPixel(6, 2)
  51. drawPixel(10, 2)
  52. drawPixel(6, 8)
  53. drawPixel(10, 8)
  54. drawPixel(3, 4)
  55. drawPixel(3, 6)
  56. drawPixel(13, 4)
  57. drawPixel(13, 6)
  58. drawPixel(2, 8)
  59. drawPixel(4, 8)
  60.  
  61. drawPixel(2, 2)
  62. drawPixel(4, 2)
  63.  
  64. drawPixel(12, 9)
  65. drawPixel(14, 9)
  66.  
  67. setColor(colors.red)
  68. drawRect(6, 4, 5, 3)
  69.  
  70. setColor(colors.yellow)
  71. drawRect(7, 5, 3, 1)
  72.  
  73. end
  74.  
  75. local function inBox(x, y, startX, startY, sizeX, sizeY)
  76. return ((x >= startX) and (x < (startX + sizeX))) and ((y >= startY) and (y < (startY + sizeY)))
  77. end
  78.  
  79. local function checkButtonPress(x, y)
  80. if inBox(x, y, 3, 4, 3, 3) then
  81. return "left"
  82. elseif inBox(x, y, 11, 4, 3, 3) then
  83. return "right"
  84. elseif inBox(x, y, 6, 2, 5, 2) then
  85. return "forward"
  86. elseif inBox(x, y, 6, 7, 5, 2) then
  87. return "back"
  88.  
  89. elseif inBox(x, y, 5, 8, 3, 2) then
  90. return "speed"
  91.  
  92. elseif inBox(x, y, 2, 8, 3, 2) then
  93. return "up"
  94. elseif inBox(x, y, 12, 8, 3, 2) then
  95. return "down"
  96. elseif inBox(x, y, 6, 4, 5, 3) then
  97. return "fire"
  98. else
  99. return nil
  100. end
  101. end
  102.  
  103. setColor(colors.black)
  104. drawRect(1, 1, 15, 10)
  105. renderButtons()
  106.  
  107. while true do
  108. ename, eside, touchX, touchY = os.pullEvent()
  109. if ename=="monitor_touch" then
  110. bEvent = checkButtonPress(touchX, touchY)
  111. if bEvent then
  112. rednet.broadcast("CM_"..bEvent)
  113. end
  114. end
  115.  
  116. end
Advertisement
Add Comment
Please, Sign In to add comment