// Basketball program
// Score if press mouse inside hoop
//
// @author Kim Bruce

dialect "rtobjectdraw"

def basketball: GraphicApplication = object {
    inherit graphicApplicationSize (400 @ 400)

    // start and size of text field showing score
    def textStart: Point = 150 @ 200
    def textSize: Number = 16
    
    // Location and dimensions of hoop
    def hoopSize: Point = 100 @ 60
    def hoopStart: Point = 160 @ 50
    // create the basketball hoop
    def hoop: Graphic2D =
          framedOvalAt (hoopStart) size (hoopSize) on (canvas)

    // create text item to display score
    def display: Text =
          textAt (textStart) with ("Your score is 0") on (canvas)
    display.fontSize := textSize

    // score of game so far
    var score: Number := 0

    // Update score if press mouse in hoop
    method onMousePress (point: Point) -> Done {
        if (hoop.contains (point)) then {
            score := score + 2
            display.contents := "Your score is {score}"
        }
    }

    // required to pop up window and start graphics
    startGraphics
}
