Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTick()
- -- Read the touchscreen data from the script's composite input
- inputX = input.getNumber(3)
- inputY = input.getNumber(4)
- isPressed = input.getBool(1)
- Speed = input.getNumber(8)
- Depth = input.getNumber(9)
- Zoom = input.getNumber(10)
- -- Check if the player is pressing the rectangle at (10, 10) with width and height of 20px
- isPressingRectangleSwitch = isPressed and isPointInRectangle(inputX, inputY, 5, 5, 5, 5)
- isPressingIRSwitch = isPressed and isPointInRectangle(inputX, inputY, 15, 5, 5, 5)
- isPressingTriangleUp = isPressed and isPointInRectangle(inputX, inputY, 3, 15, 10, 10)
- isPressingTriangleDown = isPressed and isPointInRectangle(inputX, inputY, 3, 25, 10, 10)
- isPressingZoomPlus = isPressed and isPointInRectangle(inputX, inputY, 18, 15, 6, 6)
- isPressingZoomMinus = isPressed and isPointInRectangle(inputX, inputY, 18, 25, 6, 6)
- --output checks
- output.setBool(1, isPressingRectangleSwitch)
- output.setBool(3, isPressingIRSwitch)
- output.setBool(4, isPressingZoomPlus)
- output.setBool(5, isPressingZoomMinus)
- if not isPressingTriangleUp and not isPressingTriangleDown then output.setNumber(2, 0)
- end
- if isPressingTriangleUp then
- output.setNumber(2, 1)
- end
- if isPressingTriangleDown then
- output.setNumber(2, -1)
- end
- end
- -- Returns true if the point (x, y) is inside the rectangle at (rectX, rectY) with width rectW and height rectH
- function isPointInRectangle(x, y, rectX, rectY, rectW, rectH)
- return x > rectX and y > rectY and x < rectX+rectW and y < rectY+rectH
- end
- function onDraw()
- -- Draw a rectangle that fills in when the player is pressing it
- screen.setColor(255, 255, 255)
- if isPressingRectangleSwitch then
- screen.drawRectF(5, 5, 5, 5)
- else
- screen.drawRect(5, 5, 5, 5)
- end
- if isPressingTriangleUp then
- screen.drawTriangleF(7, 13, 3, 21, 12, 21)
- else
- screen.drawTriangle(7, 13, 3, 21, 12, 21)
- end
- if isPressingTriangleDown then
- screen.drawTriangleF(7, 33, 3, 25, 12, 25)
- else
- screen.drawTriangle(7, 33, 3, 25, 12, 25)
- end
- if isPressingIRSwitch then
- screen.drawRectF(15, 5, 5, 5)
- else
- screen.drawRect(15, 5, 5, 5)
- end
- if isPressingZoomMinus then
- screen.setColor(255, 0, 0)
- screen.drawRectF(18, 25, 6, 6)
- else
- screen.setColor(255, 0, 0)
- screen.drawRect(18, 25, 6, 6)
- end
- if isPressingZoomPlus then
- screen.setColor(0, 255, 0)
- screen.drawRectF(18, 15, 6, 6)
- else
- screen.setColor(0, 255, 0)
- screen.drawRect(18, 15, 6, 6)
- end
- screen.drawText(0, 0, "CAM")
- screen.drawText(17, 0, "IR")
- screen.setColor(255, 0, 0)
- screen.drawText(70, 0, "Speed")
- screen.drawText(70, 6, round(Speed))
- screen.setColor(0, 0, 255)
- screen.drawText(70, 11, "Depth")
- screen.drawText(70, 15, round(Depth))
- screen.setColor(0, 255, 255)
- screen.drawText(30, 5, round2(Zoom, 2))
- screen.setColor(0, 255, 255)
- screen.drawText(30, 0, "Zoom")
- --RETICULE
- screen.setColor(255, 255, 255)
- width = screen.getWidth()
- height = screen.getHeight()
- screen.drawCircle(width / 2, height / 2, 5)
- end
- function round(n)
- return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
- end
- function round2(num, numDecimalPlaces)
- local mult = 10^(numDecimalPlaces or 0)
- return math.floor(num * mult + 0.5) / mult
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement