123
function onTick()
-- Read the touchscreen data from the script's composite input
inputX = input.getNumber(3)
inputY = input.getNumber(4)
isPressed = input.getBool(1)
-- Check if the player is pressing the rectangle at (10, 10) with width and height of 20px
isPressingRectangle = isPressed and isPointInRectangle(inputX, inputY, 0, 0, 20, 20)
-- Set the composite output, on/off channel 1
output.setBool(1, isPressingRectangle)
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
if isPressingRectangle then
screen.drawRectF(0, 0, 20, 20)
else
screen.drawRect(0, 0, 20, 20)
end
end