/**
Like the Rain Catcher games, this game uses a timer to release the bubbles so they 
can float to the top. We’ll be using $this.scene.state() == “PLAY” so that the bubbles 
do not continue to rise after the game has stopped. The bubble used in this game may 
be hard to initially locate since it starts at the bottom of the screen. Use 
GAME OBJECTS to select it if you’re having trouble.

Decomposition: 
* variable to keep track of score
* bubbles are cloned at random x 
* bubbles move up 
* get a point when bubbles are clicked
* lose a point when bubble moves off screen
*/

//*****************Scene Object - Initialize When Scene Starts*********************//
// make variable for score
$this.totalScore = 0;
if($this.scene.state() == "PLAY") {
    createTimer(1000, function() {
        var nbubble = bubble.clone();
        nbubble.x(random(720,80));
        nbubble.y(600);
    });
}

//*******************bubble Object - Update Every Frame Event**********************//
if($this.y() > 0) { // move as long as it's on the screen
    $this.moveY(-100);
} else { // when it is off screen
    $this.remove()
    $this.scene.totalScore -= 1;
    score.text($this.scene.totalScore)
}

//*********************bubble Object - Mouse Click Event***************************//
$this.remove();
$this.scene.totalScore += 1;
score.text($this.scene.totalScore); // update score