var touch,__extends=this&&this.__extends||function(){var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(e,i)};return function(e,i){function n(){this.constructor=e}if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();!function(t){var e=function(e){function i(){var t=e.call(this)||this;return t.skinIndex=0,t.ballSpeed=0,t.accelerate=0,t.isExceed=!0,t.isDead=!1,t.gameOver=!1,t.isAI=!1,t._safeDir=1,t._trail=null,t._shadow=null,t._nameNode=null,t._life=1,t._lifeProduceCounter=0,t._maxLife=1,t._sprintState=!1,t._sprintTimer=0,t._sprintShow=!1,t._sprintNode=null,t._skin=null,t._main=null,t._isAutoRelive=!1,t._autoReliveTimes=0,t._safeDir=Math.random()>.5?-1:1,t}return __extends(i,e),i.prototype.onTriggerEnter=function(e){var i=e.owner;t.GameFactory.POOL.ACCELERATE_BLOCK==i.name?this._onHitAccelerateBlock(i):t.GameFactory.POOL.OBSTACLE_BOX==i.name?this._onHitObstacle(i):i.name==t.GameFactory.POOL.DIAMOND?this._onHitDiamond(i):i.name==t.GameFactory.POOL.POWER_UP&&this._onHitPowerup(i)},i.prototype._onHitObstacle=function(e){if(this.isSprintState){this.isAI||(this.playSound("break"),t.GameData.instance.isVibrateOn&&SdkHelper.SdkUtils.shortVibrate());var i=e.transform.position.clone(),n=(this.owner.transform,e._$color);n||(n=new Laya.Vector4(1,1,1,1));var o=this.transform.position.clone();o.y=.5,i.z-=.01;for(var r=t.GameFactory.instance.createStoneParticles(!1,i,this.owner.parent),a=0,s=function(e){var i=r.getChildAt(e);i.active=!0,i.meshRender.material.albedoColor=n;var s=i.transform.position.clone(),p=new Laya.Vector3;Laya.Vector3.subtract(s,o,p),Laya.Vector3.normalize(p,p),Laya.Vector3.scale(p,t.MathUtil.randomInt(10,15),p),p.z-=10,Laya.Vector3.add(s,p,p),Laya.Tween.to(s,{x:p.x,y:p.y,z:p.z,update:new Laya.Handler(i,function(){i.transform.position=s})},300,Laya.Ease.linearIn,new Laya.Handler(i,function(){++a==r.numChildren&&r.timer.frameOnce(1,r,function(){t.GameFactory.instance.recycleStoneParticles(r)})}))},p=0;p0?(this.extraLife--,this._beginAutoRelive(t.GameDefine.AUTORELIVE_TIME),this._main&&this._main.event(t.GameEvent.LIFE_CHANGE,[this._lifeProduceCounter,2])):this.gameOver=!0))},i.prototype.getSprintSpeed=function(){return t.GameData.instance.config.speed.sprint_max},i.prototype.getMaxNormalSpeed=function(){return t.GameData.instance.config.speed.normal_max},i.prototype._onHitAccelerateBlock=function(e){this.isAI||(this.playSound(t.GameFactory.POOL.ACCELERATE_BLOCK),this.accelerate=1),this.isSprintState||(this.ballSpeed+=t.GameData.instance.config.speed.increase,this.ballSpeed>this.getMaxNormalSpeed()&&(this.ballSpeed=this.getMaxNormalSpeed()))},i.prototype.addSprintProgress=function(e){this.lifeProduceCounter+=e,this.lifeProduceCounter>=100?(this.lifeProduceCounter=100,this._beginSprint(),this._life300&&(o=300),o<50&&(o=50);var r=this.isAI?i.x:2.5,a=this.isAI?2:1;o=this.isAI?300:o,Laya.Tween.to(i,{x:r,y:a,update:new Laya.Handler(e,function(){i.z=n.position.z-2,this.transform.position=i})},o,Laya.Ease.linearIn,new Laya.Handler(e,function(){e.active=!1}))}},i.prototype.getSpeed=function(){return this.ballSpeed},i.prototype.getInitSpeed=function(){return this.isAI?t.GameData.instance.config.speed.ai_init:t.GameData.instance.config.speed.init},i.prototype.getAiInitSpeed=function(){return t.MathUtil.randomInt(t.GameData.instance.config.speed.ai_init_min,t.GameData.instance.config.speed.ai_init_max)},Object.defineProperty(i.prototype,"trail",{get:function(){return this._trail},enumerable:!1,configurable:!0}),i.prototype.setIsAI=function(t){this.isAI=t},i.prototype.playerExceedAI=function(t){this.isExceed=t},Object.defineProperty(i.prototype,"transform",{get:function(){return this.owner.transform},enumerable:!1,configurable:!0}),i.prototype.setTrail=function(t){this._trail=t},i.prototype.setTrailTexture=function(t){if(this._trail){this._trail.glitterRender.sharedMaterial.diffuseTexture=t}},i.prototype.setSprint=function(t){this._sprintNode=t,this._sprintShow=t.active},i.prototype.setShadow=function(t){this._shadow=t},i.prototype.setNameNode=function(t){this._nameNode=t},i.prototype.setNameTexture=function(t){this._nameNode.meshRender.material.setDiffuseTexture(t)},i.prototype.setSkin=function(t,e){var i=this.owner.meshRender.material;i.setDiffuseTexture(t),e?i.setColor(e):i.setColor(new Laya.Vector4(1,1,1,1)),this._skin=t},i.prototype._setSprintSkin=function(){var e=t.GameFactory.instance.getSprintSkin();this.owner.meshRender.material.setDiffuseTexture(e)},i.prototype.setFogColor=function(t){this.owner.meshRender.material.setFogColor(t),this._nameNode&&this._nameNode.meshRender.material.setFogColor(t),this._shadow&&this._shadow.meshRender.material.setFogColor(t)},i.prototype.show=function(t){this.owner.active=t,this._shadow&&(this._shadow.active=t),this._nameNode&&(this._nameNode.active=t)},i.prototype.showShadow=function(t){this._shadow&&(this._shadow.active=t)},i.prototype.showTrail=function(t){this._trail&&(this._trail.active=t)},i.prototype.showName=function(t){this._nameNode&&(this._nameNode.active=t)},i.prototype.showSprint=function(e){this._sprintShow=e,this._sprintNode&&(e||t.GameUtils.refreshBallPartPosition(this.transform,this._sprintNode.transform,0,this._sprintShow?0:200))},i.prototype.renew=function(t,e,i,n,o){this.transform.position=t,this.isExceed=e,this.isDead=!1,this._safeDir=Math.random()>.5?-1:1;var r=this._trail;r.active=!1,r.timerOnce(50,this,function(t){t.active=!0},[r]),this.isSprintState&&this._endSprint(),this.setSkin(i),this.setTrailTexture(n),this.setNameTexture(o),this.refreshPartsPosition()},i.prototype.playSound=function(e){e==t.GameFactory.POOL.OBSTACLE_BOX?t.SoundManager.playSound("res/sounds/gameover.mp3"):e==t.GameFactory.POOL.ACCELERATE_BLOCK?t.SoundManager.playSound("res/sounds/speedup.mp3"):e==t.GameFactory.POOL.DIAMOND?t.SoundManager.playSound("res/sounds/speedup.mp3"):"break"==e&&t.SoundManager.playSound("res/sounds/break.mp3")},i.prototype.updateForwardRotation=function(t){this.owner.transform.rotate(new Laya.Vector3(60*-this.ballSpeed*t,0,0),!0,!1)},i.prototype.updateSideRotation=function(t){var e=this.owner.transform;e.rotation=new Laya.Quaternion(e.rotation.elements[0],0,t,e.rotation.elements[3])},i.prototype.moveForward=function(t){var e=this.owner.transform;e.position=new Laya.Vector3(e.position.x,e.position.y,e.position.z-this.ballSpeed*t)},i.prototype.moveToX=function(t){var e=this.owner.transform;e.position=new Laya.Vector3(t,e.position.y,e.position.z)},i.prototype.moveByX=function(t){var e=this.owner.transform;e.position=new Laya.Vector3(e.position.x+t,e.position.y,e.position.z)},i.prototype.setPosition=function(t){this.transform.position=t},i.prototype.refreshPartsPosition=function(){t.GameUtils.refreshBallParts(this.transform,null,this._shadow,this._nameNode),this._sprintNode&&t.GameUtils.refreshBallPartPosition(this.transform,this._sprintNode.transform,0,this._sprintShow?0:200)},i.prototype.refreshTrail=function(){t.GameUtils.refreshTrail(this._trail,this.transform)},i.prototype.adjustSpeed=function(e){this._sprintState?this.ballSpeedthis.getSprintSpeed()&&(this.ballSpeed=this.getSprintSpeed())):this.ballSpeed>this.getInitSpeed()&&(this.ballSpeed-=e*t.GameData.instance.config.speed.auto_decrease,this.ballSpeede.position.z-o.transform.position.z&&1>o.transform.position.y&&i.push(o.transform.position.x)}var r=this.processBeHitAIBall(e.position.x,i);return.05>Math.abs(r-e.position.x)?0:r>e.position.x?.2:-.2},i.prototype.processBeHitAIBall=function(t,e){for(var i=[],n=0;n<5;++n)i.push(!0);for(n=0;n0){for(n=i.length-1;n>-0;n--)if(i[n])return n-2}else for(n=0;nthis._maxLife&&(this._life=this._maxLife)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"extraLife",{get:function(){return this._life},set:function(t){this._life=t,this._life>this.maxLife&&(this._life=this.maxLife),this._life<0&&(this._life=0)},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"lifeProduceCounter",{get:function(){return this._lifeProduceCounter},set:function(t){this._lifeProduceCounter=t},enumerable:!1,configurable:!0}),i.prototype.setEventDispatcher=function(t){this._main=t},Object.defineProperty(i.prototype,"isAutoRelive",{get:function(){return this._isAutoRelive},set:function(t){this._isAutoRelive=t},enumerable:!1,configurable:!0}),i.prototype._udpateAutoRelive=function(){this._isAutoRelive&&(this._autoReliveTimes%10<5?this.owner.active=!1:this.owner.active=!0,this._autoReliveTimes--,this._autoReliveTimes<0&&this._endAutoRelive())},i.prototype._beginAutoRelive=function(t){this.isAutoRelive=!0,this._autoReliveTimes=t},i.prototype._endAutoRelive=function(){this.owner.active=!0,this._isAutoRelive=!1},i.prototype.update=function(t){this.adjustSpeed(t),this.updateForwardRotation(t),this.moveForward(t),this.refreshPartsPosition(),this.refreshTrail(),this.isDead||this.gameOver||(this._udpateAutoRelive(),this._updateSprintState(t))},Object.defineProperty(i.prototype,"isSprintState",{get:function(){return this._sprintState},enumerable:!1,configurable:!0}),i.prototype.enterSprintState=function(){this.addSprintProgress(100)},i.prototype._beginSprint=function(){console.info("Sprint ===> Start"),this._sprintState=!0,this._sprintTimer=t.GameData.instance.config.speed.sprint_time,this.showSprint(!0),this._main&&this._main.event(t.GameEvent.SPRINT_CHANGE,[!0])},i.prototype._endSprint=function(){console.info("Sprint ===> Stop"),this.showSprint(!1),this._sprintState=!1,this._sprintTimer=0,this.transform.scale=new Laya.Vector3(1,1,1),this._main&&this._main.event(t.GameEvent.SPRINT_CHANGE,[!1]),this._beginAutoRelive(90)},i.prototype._updateSprintState=function(e){if(this._sprintState){this._sprintTimer-=e;i=e/t.GameData.instance.config.speed.sprint_time*100;this.addSprintProgress(-i),this._sprintTimer<=0&&this._endSprint()}else if(this.lifeProduceCounter>0&&t.GameData.instance.config.speed.sprint_decrease>0){var i=t.GameData.instance.config.speed.sprint_decrease*e;this.addSprintProgress(-i)}},i.prototype.setBendAngle=function(t){if(this.owner.meshRender.material.setBendOffset(t),this._sprintNode&&this.isSprintState)for(var e=0;e