/** 
This activity teaches the ninjas a new application of the pointToObject() function.
**/

//****************pcninja Object - Update Every Frame***************//
var downArrowPressed = isKeyPressed(Keys.downArrow);

if(downArrowPressed && $this.y() < 460){
    moveY($this);
}

var upArrowPressed = isKeyPressed(Keys.upArrow);

if(upArrowPressed && $this.y() > 0){
    moveY($this, -$this.speedY());
}

//******************star Object - Update Every Frame***************//
if($this.thrown){
    $this.moveForward(10);
}

// Bonus
if ($this.isTouching(pcninja) || $this.x() > 800 || $this.y() < 0 || $this.y() > 600) { 
    $this.remove(); 
} else if ($this.x() < 0) { 
    $this.remove(); 
    $this.scene.score++; 
}

//****************pcninja - Initialize When Scene Starts***********//
if($this.scene.state() == "PLAY"){
    createTimer(5000, function(){
        var nstar = star.clone();
        nstar.x(682);
        nstar.y(304);
        nstar.thrown=true;
        nstar.pointToObject(pcninja);
        nstar.rotatoion(nstar.rotation()-90);
    });
}

//**********Scene Object - Initialize When Scene Starts**************//
// BONUS
if ($this.scene.state() == "PLAY") { 
    $this.scene.score = 0; 
}

//***************Scene Object - Update Every Frame******************//
// BONUS 
score.text($this.scene.score);