henoireil

Ordi

Sep 1st, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 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. drawRect(12, 8, 3, 2)
  45.  
  46. setColor(colors.white)
  47. drawPixel(6, 2)
  48. drawPixel(10, 2)
  49. drawPixel(6, 8)
  50. drawPixel(10, 8)
  51. drawPixel(3, 4)
  52. drawPixel(3, 6)
  53. drawPixel(13, 4)
  54. drawPixel(13, 6)
  55. drawPixel(2, 8)
  56. drawPixel(4, 8)
  57.  
  58. drawPixel(2, 2)
  59. drawPixel(4, 2)
  60.  
  61. drawPixel(12, 9)
  62. drawPixel(14, 9)
  63.  
  64. setColor(colors.red)
  65. drawRect(6, 4, 5, 3)
  66. drawPixel(3, 2)
  67.  
  68. setColor(colors.yellow)
  69. drawRect(7, 5, 3, 1)
  70.  
  71. end
  72.  
  73. local function inBox(x, y, startX, startY, sizeX, sizeY)
  74. return ((x >= startX) and (x < (startX + sizeX))) and ((y >= startY) and (y < (startY + sizeY)))
  75. end
  76.  
  77. local function checkButtonPress(x, y)
  78. if inBox(x, y, 3, 4, 3, 3) then
  79. return "left"
  80. elseif inBox(x, y, 11, 4, 3, 3) then
  81. return "right"
  82. elseif inBox(x, y, 6, 2, 5, 2) then
  83. return "forward"
  84. elseif inBox(x, y, 6, 7, 5, 2) then
  85. return "back"
  86.  
  87. elseif inBox(x, y, 2, 2, 3, 1) then
  88. return "speed"
  89.  
  90. elseif inBox(x, y, 2, 8, 3, 2) then
  91. return "up"
  92. elseif inBox(x, y, 12, 8, 3, 2) then
  93. return "down"
  94. elseif inBox(x, y, 6, 4, 5, 3) then
  95. return "fire"
  96. else
  97. return nil
  98. end
  99. end
  100.  
  101. setColor(colors.black)
  102. drawRect(1, 1, 15, 10)
  103. renderButtons()
  104.  
  105. while true do
  106. ename, eside, touchX, touchY = os.pullEvent()
  107. if ename=="monitor_touch" then
  108. bEvent = checkButtonPress(touchX, touchY)
  109. if bEvent then
  110. rednet.broadcast("CM_"..bEvent)
  111. end
  112. end
  113.  
  114. end
Advertisement
Add Comment
Please, Sign In to add comment