package Racing.Assembly{import Racing.DataTools;import Racing.DynamicRegistration;import Racing.GoldPigAssembly;import Racing.Message;import Racing.MyCar;import Racing.Scene;import Racing.Shake;import Racing.UI_List;import core.responder.NResponder;import game.resource.ResourcePath;import laya.display.Animation;import laya.display.Sprite;import laya.events.Event;import laya.maths.Point;import laya.media.SoundManager;import laya.ui.Image;import laya.utils.Handler;import laya.utils.Timer;import laya.utils.Tween;public class Parking extends Sprite{private var carSign:Image;public var carArray:Array;public var movingCar:MyCar=null;private static var _instance:Parking;public var myCar:MyCar;public var newCar:MyCar;private var newCarUnlock:Image;private var shine:Image;private var close:Image;public var arr:Array;public var carMax:int;public var composeTip:ComposeTip;private var goldPig:GoldPigAssembly=new GoldPigAssembly();private var balckhold:Imagepublic function Parking(){this.addChild(goldPig);//this.mo//this.mouseThrough=true;//var x1:int=DataTools.x1;//var y1:int=DataTools.y1;//var x2:int=DataTools.x2;//var y2:int=DataTools.y2;//this.graphics.drawLine(x1,y1,x1,y2,"#000000");//this.graphics.drawLine(x1,y1,x2,y1,"#000000");//this.graphics.drawLine(x2,y2,x1,y2,"#000000");//this.graphics.drawLine(x2,y2,x2,y1,"#000000");//this.graphics.drawPie(x1,(y1 y2)/2,(y2-y1)/2,90,270,null,"#000000");//this.graphics.drawPie(x2,(y1 y2)/2,(y2-y1)/2,-90,90,null,"#000000");composeTip=new ComposeTip();addChild(composeTip);carArray=new Array(this.parkingMax);for(var j=0;j=0)car.position=position;//没有指定positionif(car.position<0){car.position=this.getUsefulPosition();}//如果当前位置上已经有马了if(carArray[car.position]!=null){var c:MyCar=carArray[car.position];c.removeSelf();carArray[car.position]=null;}else{carArray[car.position]=car;this.addChild(car);car.setXYByPosition();}return true;}//获取相同等级的车public function getLikeGrade(a:int = 1):Array{arr = new Array();for(var i:int = 0; i max){max = (carArray[g] as MyCar).grade}}}return max;}public function getByPosition(position:int):MyCar{return carArray[position];}//获取下一个可以放车的位置,如果已满则返回空public function getUsefulPosition():int{for(var j=0;j800){////Dustbin.instance.//Parking.instance.dropByMovingCar();//Asset.save();//endMove();//return;//}console.log("parking.mouseUp");console.log(mouseX "," mouseY);if(movingCar==null)return;var movedCar:MyCar=carArray[movingCar.position];var p=DataTools.getPositionByXY(mouseX,mouseY);switch(p){case -1 :{ //-1:落在跑道上Runway.instance.push(movedCar);//console.log("把车放到了跑道上");endMove();Asset.save();break;}case -2 ://-2:落在无效位置 returnif(FirstPage.instance.sound){SoundManager.playSound(PlaySounds.cant, 1,new Handler(this, function():void{trace("播放完成")}));}Message.addMessage("Please put the horse in the right place");var tweCar:MyCar=movingCar.copy1();tweCar.x=movingCar.x;tweCar.y=movingCar.y;endMove();addChild(tweCar);getByPosition(tweCar.position).alpha=0.5;var xx=DataTools.getXByPosition(tweCar.position);var yy=DataTools.getYByPosition(tweCar.position);Tween.to(tweCar,{x: xx,y:yy},300,null,Handler.create(this,function end(){getByPosition(tweCar.position).alpha=1;tweCar.removeSelf();}));break;default :{//落在停车位//情况3.落在没有车的地方,移动至该处//nowCar:鼠标拖拽结束后停在nowCar上var nowCar:MyCar=carArray[p] as MyCar;if(nowCar==null){var carAni:MyCar=movingCar.copy1();carAni.x=DataTools.getXByPosition(p);carAni.y=DataTools.getYByPosition(p);;carAni.alpha=0.5;addChild(carAni);Tween.from(carAni,{x: DataTools.getXByPosition(carAni.position),y:DataTools.getYByPosition(carAni.position)},400,null,Handler.create(this,function move(){carAni.removeSelf();init();}));carArray[p]=movedCar;carArray[movedCar.position]=null;movedCar.position=p;Asset.save();endMove();movedCar.alpha=0.5;break;}//有车////在跑道上的车if(nowCar.onRunway==true)break;console.log(movedCar.grade);console.log(nowCar.grade);if(nowCar.grade<0||movedCar.grade<0){endMove();return;}//情况4:等级不同,互换位置if(movedCar.grade!=nowCar.grade){changeAni(p,movedCar.position);Asset.save();endMove();break;}//情况5:等级相同,合成if(movedCar.grade==nowCar.grade&&movedCar!=nowCar&&movedCar.grade<=29){//合成动画this.init();compose(nowCar,movedCar);endMove();}}}endMove();}public function get parkingMax():int{return DataTools.parkingMax;}//在位置position1上合成一辆grade级车public function compose(nowCar:MyCar,movedCar:MyCar){FirstPage.instance.vibrateShort();if(Guide.instance.hand1 != null){Guide.instance.hand1.visible = false;Scene.con.removeChild(Guide.instance.hand1);}if(Guide.instance.text1 != null){Guide.instance.text1.visible = false;Scene.con.removeChild(Guide.instance.text1);}if(Guide.instance.hand5 != null){Guide.instance.hand5.visible = false;Scene.con.removeChild(Guide.instance.hand5);}//if(Asset.playnum == 1){//Guide.instance.delMerge();//}//Asset.playnum ;if(movingCar){movingCar.removeSelf();movingCar=null;}this.remove(movedCar.position);this.remove(nowCar.position);newCar=new MyCar(movedCar.grade 1);if(newCar.grade > getHighCarGrade()){var timer:Timer=new Timer();timer.once(1600,this,function unlockkk(){if(movingCar!=null){composeTip.stop();this.endMove();}Scene.instance.addChild(new UnLock(newCar.grade));});}//下面是缓动var characterA:MyCar=nowCar.copy1();var characterB:MyCar=nowCar.copy1();var x0=nowCar.x;var y0=nowCar.y;//characterA.pivot(46.5, 50);characterA.x = x0;characterA.y= y0;characterB.x = x0;characterB.y = y0;var shake1:ComposeShake=new ComposeShake();var shake2:ComposeShake=new ComposeShake();this.addChild(characterA);this.addChild(characterB);var terminalX = 200;push(newCar,nowCar.position);newCar.alpha=0;//Tween.to(characterA, { x : terminalX }, 5000,push(newCar));//怼在一起//to :到当前的状态//from:从当前状态出发shake1.init_(characterA,7,3,0);shake2.init_(characterB,7,-3,0);Tween.to(characterA, { x : x0-120 }, 300,null);Tween.to(characterB, { x : x0 120 }, 300,null,Handler.create(this,function back(){//shake1.begin();//shake2.begin();//在最远位置抖动150new Timer().once(150,this,function(){shake1.end();shake2.end();Tween.to(characterA, { x : x0 }, 100,null);//开始合在一起Tween.to(characterB, { x : x0 }, 100,null,Handler.create(this,function (){//两只马怼在了一起//console.log("两只马怼在了一起");//爆破效果Laya.timer.once(1000,this,function(e:Event):void{})characterA.removeSelf();characterB.removeSelf();if(FirstPage.instance.sound){SoundManager.playSound(PlaySounds.merge, 1,new Handler(this, function():void{trace("播放完成")}));}// 5层:光,新旧马,新旧阴影,星星newCar.alpha=0;//0光var sun:Sprite=new Sprite();sun.loadImage(ResourcePath.getImage("sun"));sun.x=DataTools.getXByPosition(newCar.position)-250;sun.y=DataTools.getYByPosition(newCar.position)-250;//1旧马var oldCar:MyCar=characterB;oldCar.alpha=0;oldCar.mouseEnabled=false;//this.addChild(oldCar);//新马newCar.removeSelf();//newCar.mouseEnabled=false;//旧阴影var oldShadow:MyCar=oldCar.shadow;oldShadow.setXYByPosition();oldShadow.alpha=0;//新阴影var newShadow:MyCar=newCar.shadow;newShadow.setXYByPosition();newShadow.alpha=0;this.addChildren(sun,oldCar,newCar,oldShadow,newShadow); var star:Animation=new Animation();star.loadAtlas(ResourcePath.getJson("star"));star.interval=50;star.x=sun.x;star.y=sun.y;this.addChild(star);star.play(0,false);star.on(Event.COMPLETE,this,function(){star.removeSelf()});oldCar.alpha=1;var mynewcar:MyCar=newCar;//阴影开始出现Tween.to(oldShadow,{alpha:1},250,null,Handler.create(this,function(){//阴影完全出现oldShadow.removeSelf();oldCar.removeSelf();mynewcar.alpha=1;newShadow.alpha=1;//阴影逐渐消失Tween.to(newShadow,{alpha:0},250,null,Handler.create(this,function(){newShadow.removeSelf();}));//阳光逐渐消失Tween.to(sun,{alpha:0.3},400,null,Handler.create(this,function(){newShadow.removeSelf();sun.removeSelf();}));}));}));})}));// characterB使用Tween.from缓动//if(getMaxGradeExpect(newCar)acar.grade?maxGrade:acar.grade;}}for(var j=0;jacar.grade?maxGrade:acar.grade;}console.log(maxGrade);return maxGrade;}public function com30(){}}}import Racing.Shake;import laya.display.Sprite;import laya.utils.Handler;import laya.utils.Tween;class ComposeShake extends Shake{private var px0;private var py0;private var pivD:int;private var rotD:int;private var rot:int;public function init_(obj:Sprite,halfT:int,pivD:int,rotD:int){this.pivD=pivD;this.rotD=rotD;px0=obj.pivotX;py0=obj.pivotY;rot=obj.rotation;super.init(obj, 0, 0, 0, 0, halfT);}public override function to1(){if(num<=0){end();return;}if(switchOn==false){end();return;}Tween.to(obj,{pivotX:px0-pivD,pivotX:py0-pivD,rotation:rot-rotD},delay,null,Handler.create(this,function (){to2();}));}public override function to2(){if(num>0)num--;if(switchOn==false){end();return;}Tween.to(obj,{pivotX:px0 pivD,pivotX:py0 pivD,rotation:rot rotD},delay,null,Handler.create(this,function (){to1();}));}public override function end(){super.end();obj.pivotX=px0;obj.pivotY=py0;obj.rotation=0;}}