cc.Class({
extends: cc.Component,
properties: {
},
// LIFE-CYCLE CALLBACKS:
onLoad:function () {
this.zindex=1;
this.guan=1;
this.count=8;
this.score=0;
//干垃圾
this.node.getChildByName("New").getChildByName("lj0").type=0;
this.node.getChildByName("New").getChildByName("lj1").type=0;
this.node.getChildByName("New").getChildByName("lj6").type=0;
this.node.getChildByName("New").getChildByName("lj7").type=0;
this.node.getChildByName("New").getChildByName("lj8").type=0;
//湿垃圾
this.node.getChildByName("New").getChildByName("lj2").type=1;
this.node.getChildByName("New").getChildByName("lj9").type=1;
this.node.getChildByName("New").getChildByName("lj10").type=1;
this.node.getChildByName("New").getChildByName("lj11").type=1;
this.node.getChildByName("New").getChildByName("lj20").type=1;
//有毒垃圾
this.node.getChildByName("New").getChildByName("lj5").type=2;
this.node.getChildByName("New").getChildByName("lj3").type=2;
this.node.getChildByName("New").getChildByName("lj14").type=2;
this.node.getChildByName("New").getChildByName("lj12").type=2;
this.node.getChildByName("New").getChildByName("lj13").type=2;
//可回收垃圾
this.node.getChildByName("New").getChildByName("lj4").type=3;
this.node.getChildByName("New").getChildByName("lj15").type=3;
this.node.getChildByName("New").getChildByName("lj16").type=3;
this.node.getChildByName("New").getChildByName("lj17").type=3;
this.node.getChildByName("New").getChildByName("lj18").type=3;
this.node.getChildByName("New").getChildByName("lj19").type=3;
this.node.getChildByName("New").getChildByName("lj21").type=3;
this.myarray=new Array(this.node.getChildByName("New").getChildByName("lj0"),
this.node.getChildByName("New").getChildByName("lj1"),
this.node.getChildByName("New").getChildByName("lj2"),
this.node.getChildByName("New").getChildByName("lj3"),
this.node.getChildByName("New").getChildByName("lj4"),
this.node.getChildByName("New").getChildByName("lj5"),
this.node.getChildByName("New").getChildByName("lj6"),
this.node.getChildByName("New").getChildByName("lj7"),
this.node.getChildByName("New").getChildByName("lj8"),
this.node.getChildByName("New").getChildByName("lj9"),
this.node.getChildByName("New").getChildByName("lj10"),
this.node.getChildByName("New").getChildByName("lj11"),
this.node.getChildByName("New").getChildByName("lj12"),
this.node.getChildByName("New").getChildByName("lj13"),
this.node.getChildByName("New").getChildByName("lj14"),
this.node.getChildByName("New").getChildByName("lj15"),
this.node.getChildByName("New").getChildByName("lj16"),
this.node.getChildByName("New").getChildByName("lj17"),
this.node.getChildByName("New").getChildByName("lj18"),
this.node.getChildByName("New").getChildByName("lj19"),
this.node.getChildByName("New").getChildByName("lj20"),
this.node.getChildByName("New").getChildByName("lj21"),
);
this.myxy=new Array({x:-247,y:114},{x:-98,y:114},{x:65,y:114},{x:230,y:114},
{x:-247,y:-39},{x:-98,y:-39},{x:65,y:-39},{x:230,y:-39});
},
start:function () {
this.path();
},
path:function(){
console.log(this.myarray[0].active+"+++++++++++++++++++++++++++++++");
for(var j0=0;j0<this.myarray.length;j0++){
this.myarray[j0].active=true;
}
this.myarray.sort(this.myfunc);
for(var j=8;j<this.myarray.length;j++){
this.myarray[j].active=false;
}
for(var i=0;i<this.myxy.length;i++){
this.myarray[i].x=this.myxy[i].x;
this.myarray[i].y=this.myxy[i].y;
this.myarray[i].X=this.myarray[i].x;
this.myarray[i].Y=this.myarray[i].y;
if(this.myarray[i].hasEventListener(cc.Node.EventType.TOUCH_START)==false){
this.myarray[i].on(cc.Node.EventType.TOUCH_START,function(e){
e.currentTarget.zIndex=this.zindex;
this.zindex++;
e.currentTarget.x+= e.getDelta().x;
e.currentTarget.y+= e.getDelta().y;
}.bind(this),this)
;}
if(this.myarray[i].hasEventListener(cc.Node.EventType.TOUCH_MOVE)==false){
this.myarray[i].on(cc.Node.EventType.TOUCH_MOVE,function(e){
e.currentTarget.x+= e.getDelta().x;
e.currentTarget.y+= e.getDelta().y;
}.bind(this),this);}
if(this.myarray[i].hasEventListener(cc.Node.EventType.TOUCH_END)==false){
this.myarray[i].on(cc.Node.EventType.TOUCH_END,function(e){
for(var k=0;k<4;k++){
if(e.currentTarget.getBoundingBox().intersects(this.node.getChildByName("ljt"+k).getBoundingBox())){
if(e.currentTarget.type==Number(this.node.getChildByName("ljt"+k).name.charAt(3))){
e.currentTarget.active=false;
this.score+=3;
this.node.getChildByName("score").getComponent(cc.Label).string="计分:"+this.score;
this.count--;
if(this.count<=0){
this.guan++;
this.node.getChildByName("top").getChildByName("guan").getComponent(cc.Label).string="第"+this.guan+"关";
this.count=8;
this.path();
}
return;
}else{
if(this.score>0){
this.score-=1;
this.node.getChildByName("score").getComponent(cc.Label).string="计分:"+this.score;
e.currentTarget.x= e.currentTarget.X;
e.currentTarget.y= e.currentTarget.Y
return;
}
}
}
}
e.currentTarget.x= e.currentTarget.X;
e.currentTarget.y= e.currentTarget.Y;
}.bind(this),this);
}
}
},
myfunc:function(){
return Math.random()>0.5?1:-1;
},
// update (dt) {},
});