Advertisement
Guest User

Untitled

a guest
May 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1.  
  2. function onTick()
  3. -- Read the touchscreen data from the script's composite input
  4. inputX = input.getNumber(3)
  5. inputY = input.getNumber(4)
  6. isPressed = input.getBool(1)
  7. Speed = input.getNumber(8)
  8. Depth = input.getNumber(9)
  9. Zoom = input.getNumber(10)
  10.  
  11.  
  12. -- Check if the player is pressing the rectangle at (10, 10) with width and height of 20px
  13.  
  14. isPressingRectangleSwitch = isPressed and isPointInRectangle(inputX, inputY, 5, 5, 5, 5)
  15. isPressingIRSwitch = isPressed and isPointInRectangle(inputX, inputY, 15, 5, 5, 5)
  16. isPressingTriangleUp = isPressed and isPointInRectangle(inputX, inputY, 3, 15, 10, 10)
  17. isPressingTriangleDown = isPressed and isPointInRectangle(inputX, inputY, 3, 25, 10, 10)
  18. isPressingZoomPlus = isPressed and isPointInRectangle(inputX, inputY, 18, 15, 6, 6)
  19. isPressingZoomMinus = isPressed and isPointInRectangle(inputX, inputY, 18, 25, 6, 6)
  20.  
  21. --output checks
  22. output.setBool(1, isPressingRectangleSwitch)
  23. output.setBool(3, isPressingIRSwitch)
  24. output.setBool(4, isPressingZoomPlus)
  25. output.setBool(5, isPressingZoomMinus)
  26.  
  27.  
  28.  
  29. if not isPressingTriangleUp and not isPressingTriangleDown then output.setNumber(2, 0)
  30. end
  31.  
  32. if isPressingTriangleUp then
  33. output.setNumber(2, 1)
  34. end
  35. if isPressingTriangleDown then
  36. output.setNumber(2, -1)
  37. end
  38. end
  39.  
  40. -- Returns true if the point (x, y) is inside the rectangle at (rectX, rectY) with width rectW and height rectH
  41. function isPointInRectangle(x, y, rectX, rectY, rectW, rectH)
  42. return x > rectX and y > rectY and x < rectX+rectW and y < rectY+rectH
  43. end
  44.  
  45. function onDraw()
  46. -- Draw a rectangle that fills in when the player is pressing it
  47. screen.setColor(255, 255, 255)
  48. if isPressingRectangleSwitch then
  49. screen.drawRectF(5, 5, 5, 5)
  50. else
  51. screen.drawRect(5, 5, 5, 5)
  52. end
  53.  
  54. if isPressingTriangleUp then
  55. screen.drawTriangleF(7, 13, 3, 21, 12, 21)
  56. else
  57. screen.drawTriangle(7, 13, 3, 21, 12, 21)
  58. end
  59.  
  60. if isPressingTriangleDown then
  61. screen.drawTriangleF(7, 33, 3, 25, 12, 25)
  62. else
  63. screen.drawTriangle(7, 33, 3, 25, 12, 25)
  64. end
  65. if isPressingIRSwitch then
  66. screen.drawRectF(15, 5, 5, 5)
  67. else
  68. screen.drawRect(15, 5, 5, 5)
  69. end
  70. if isPressingZoomMinus then
  71. screen.setColor(255, 0, 0)
  72. screen.drawRectF(18, 25, 6, 6)
  73. else
  74. screen.setColor(255, 0, 0)
  75. screen.drawRect(18, 25, 6, 6)
  76. end
  77. if isPressingZoomPlus then
  78. screen.setColor(0, 255, 0)
  79. screen.drawRectF(18, 15, 6, 6)
  80. else
  81. screen.setColor(0, 255, 0)
  82. screen.drawRect(18, 15, 6, 6)
  83. end
  84.  
  85.  
  86.  
  87. screen.drawText(0, 0, "CAM")
  88. screen.drawText(17, 0, "IR")
  89. screen.setColor(255, 0, 0)
  90. screen.drawText(70, 0, "Speed")
  91. screen.drawText(70, 6, round(Speed))
  92. screen.setColor(0, 0, 255)
  93. screen.drawText(70, 11, "Depth")
  94. screen.drawText(70, 15, round(Depth))
  95. screen.setColor(0, 255, 255)
  96. screen.drawText(30, 5, round2(Zoom, 2))
  97. screen.setColor(0, 255, 255)
  98. screen.drawText(30, 0, "Zoom")
  99.  
  100. --RETICULE
  101. screen.setColor(255, 255, 255)
  102. width = screen.getWidth()
  103. height = screen.getHeight()
  104. screen.drawCircle(width / 2, height / 2, 5)
  105.  
  106. end
  107.  
  108.  
  109. function round(n)
  110. return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
  111. end
  112.  
  113. function round2(num, numDecimalPlaces)
  114. local mult = 10^(numDecimalPlaces or 0)
  115. return math.floor(num * mult + 0.5) / mult
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement