//TIMER VARIABLES
var tm:Timer = new Timer(10);
var tm2:Timer = new Timer(10);
var tm3:Timer = new Timer(10);
var tm4:Timer = new Timer(10);

 

//PIECES FOUND

var piece1Found=false;
var piece2Found=false;
var piece3Found=false;
var piece4Found=false;
var piece5Found=false;

//PIECE VISABILITY

 

this.piece1.visible=false;
this.piece2.visible=false;
this.piece3.visible=false;
this.piece4.visible=false;
this.piece5.visible=false;

 

 

//LEFT EVENTLISTENER


this.stage.addEventListener(KeyboardEvent.KEY_DOWN,moveLeft)
this.stage.addEventListener(KeyboardEvent.KEY_UP,stopLeft)


function stopLeft(evt:KeyboardEvent):void{
tm.stop();
}

function moveLeft(evt:KeyboardEvent){
switch(evt.keyCode){
case 37:
tm.addEventListener(TimerEvent.TIMER,startTimer);
tm.start();
default:
break;
}
}

function startTimer(tevt:TimerEvent):void{
this.characterRock.x=characterRock.x-5;
}

/////////////////////////////////////////////////////////
//RIGHT EVENTLISTENER AND IF STATMENTS TO Reveal PIECES//
/////////////////////////////////////////////////////////

 

 

this.stage.addEventListener(KeyboardEvent.KEY_DOWN,moveRight)
this.stage.addEventListener(KeyboardEvent.KEY_UP,stopRight)

 

function stopRight(evt:KeyboardEvent):void{
tm2.stop();
}

function moveRight(evt:KeyboardEvent){
switch(evt.keyCode){
case 39:
tm2.addEventListener(TimerEvent.TIMER,startTimer2);
tm2.start();
default:
break;
}
}

function startTimer2(tevt:TimerEvent):void{


this.characterRock.x=characterRock.x+5;

 

//PIECE 1 ACTION(right)
if(characterRock.hitTestObject(this.paintBrush)==true && piece1Found==false){
this.testBox.text="Good Find!";


this.piece1.visible=true;

if(piece1.visible=true){
piece1Found=true;
piece1.play();
}
}

//PIECE 2 ACTION(right)

if(characterRock.hitTestObject(this.blackCat)==true && piece2Found==false){
this.testBox.text="The cat had a piece!";


this.piece2.visible=true;

if(piece2.visible=true){
piece2Found=true;
piece2.play();
}
}

//PIECE 3 ACTION(down)
if(characterRock.hitTestObject(this.easel)==true && piece3Found==false){
this.testBox.text="Behind the painting is a piece of a painting!";
//numberOfPieces++;
if(piece3.visible=true){
piece3Found=true;
piece3.play();
}

}
//PIECE 4 ACTION(right)

else if(characterRock.hitTestObject(this.pallett)==true && piece4Found==false){
this.testBox.text="That was a tough one!";
this.piece4.visible=true;

if(piece4.visible=true){
piece4Found=true;
piece4.play();

}
}

//PIECE 5 ACTION(right)
else if(characterRock.hitTestObject(this.flowerpot)==true &&piece5Found==false){
this.testBox.text="Good job!";
this.piece5.visible=true;

if(piece5.visible=true){
piece5Found=true;
piece5.play();
}
}
}

//UP EVENTLISTENER

this.stage.addEventListener(KeyboardEvent.KEY_DOWN,moveUp)
this.stage.addEventListener(KeyboardEvent.KEY_UP,stopUp)


function stopUp(evt:KeyboardEvent):void{
tm3.stop();
}

function moveUp(evt:KeyboardEvent){
switch(evt.keyCode){
case 38:
tm3.addEventListener(TimerEvent.TIMER,startTimer3);
tm3.start();
default:
break;
}

}

function startTimer3(tevt:TimerEvent):void{
this.characterRock.y=characterRock.y-5;

}

//DOWN EVENTLISTENER

this.stage.addEventListener(KeyboardEvent.KEY_DOWN,moveDown)
this.stage.addEventListener(KeyboardEvent.KEY_UP,stopDown)

 

function stopDown(evt:KeyboardEvent):void{
tm4.stop();
}

function moveDown(evt:KeyboardEvent){
switch(evt.keyCode){
case 40:
tm4.addEventListener(TimerEvent.TIMER,startTimer4);
tm4.start();
default:
break;
}
}

function startTimer4(tevt:TimerEvent):void{
this.characterRock.y=characterRock.y+5;

}

//THROW IN if(pieceFound==true&&......)

 

 

stage.addEventListener(Event.ENTER_FRAME,goIn)
function goIn(event:Event):void{
if (piece1Found==true&&piece2Found==true&&piece3Found==true&&piece4Found==true&&piece5Found==true){
//gotoAndPlay("finish");
this.testBox.text="Well Done! Game Over!";
}
else{
this.Boxy.text="All 5 Pieces are Needed";
}
}