//rocket - Update Every Frame
//set up all keypress variables
var leftPressed = isKeyPressed(Keys.leftArrow);
var rightPressed = isKeyPressed(Keys.rightArrow);
var upPressed = isKeyPressed(Keys.upArrow);
var spacePressed = isKeyPressed(Keys.space);
var bullet =  $this.findName("bullet");

//keypress conditionals\
//The following control the shooting and up arrow 
//controls which are pre-loaded.
//The only code required is the code in the meteor
if(spacePressed){
   //bullet.moving = true;
   if(!$this.scene.projectile)
   {
       var b = bullet.clone(true, true, $this.scene);

       b.x(bullet.getStagePos().x);
       b.y(bullet.getStagePos().y);
       b.rotation($this.rotation());
       b.moving = true;
       b.z(1000);
       
       $this.scene.projectile = b;
   }
   
}

if(upPressed){
    $this.moveForwardByRotation();
}
if(leftPressed){
    $this.spin(-40);
}
if(rightPressed){
    $this.spin(40);
}

//
if($this.y()>600){
    $this.y(0);
}

if($this.y()<0){
    $this.y(600);
}

if($this.x()>800){
    $this.x(0);
}

if($this.x()<0){
    $this.x(800);
}
//meteor - Initialize When Scene Starts
//Part 1 explores random() and this is a good
//place to talk to the ninja about the random()
//function as well as review how variables are used.
var rot = random(359);
$this.rotation(rot);