var game2,__extends=this&&this.__extends||function(){var t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(e,o)};return function(e,o){function i(){this.constructor=e}if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");t(e,o),e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}();!function(t){var e=function(e){function o(){var t=e.call(this)||this;return t._speed=0,t._radius=.25,t._accelerating=!1,t._hitObstacle=!1,t._life=1,t._gameWorld=null,t._effectParams={angle:new Laya.Vector4(0,0,0,0),distance:0},t._autoDrive=!1,t._lastAutoDriveDir=0,t}return __extends(o,e),o.createBall=function(t,e,i){var a=new Laya.Sprite3D("ball").addComponent(o);return a.init(t,e,i),a},o.prepare=function(){var e=new touch.CustomMaterial;e.setDiffuseTexture(t.AssetLoader.instance.get(t.GameConfig2.Assets.WHITE_CUBE_TEX)),e.setHasLight(!1),e.setFogDensity(.04),e.setTransparent(),e.setFogColor(touch.SkinManager.fogColors[0]),e.setColor(new Laya.Vector4(0,0,0,.3)),o._shadowMaterial=e,t.DeadEffect.parepare()},o.prototype.init=function(e,i,a){var r=this.owner,n=new Laya.SphereMesh(this._radius,16,16),s=new Laya.MeshSprite3D(n),l=new touch.CustomMaterial;l.setTransparent(),l.setFogDensity(.04),l.setDiffuseTexture(e),l.setColor(i),l.setFogColor(a),s.meshRender.material=l,this.owner.addChild(s),this._ballBody=s;var c=r.addComponent(Laya.SphereCollider);r.addComponent(Laya.Rigidbody),c.center=s.meshFilter.sharedMesh.boundingSphere.center.clone(),c.radius=s.meshFilter.sharedMesh.boundingSphere.radius;var h=new Laya.CylinderMesh(.2,.01,64),p=new Laya.MeshSprite3D(h);p.meshRender.material=o._shadowMaterial,r.addChild(p),p.transform.localPosition=new Laya.Vector3(0,.004-this._radius,0),this._shadow=p;var u=new Laya.Glitter,f=u.glitterRender.sharedMaterial;f.diffuseTexture=t.AssetLoader.instance.loadAsync(Laya.Texture2D,"res/tail/0.png","tail0"),f.albedo=new Laya.Vector4(1,1,1,1),this.owner.addChild(u),u.active=!0,this._trail=u;var d=u.templet;d.lifeTime=.12,d.minSegmentDistance=.1,d.minInterpDistance=.6,d.maxSlerpCount=128,d.maxSegments=600},o.prototype.setAvatarTexture=function(t){if(!this._avatarNode){var e=this.createBox({long:2,width:.001,height:.2},t);e.transform.localPosition=new Laya.Vector3(0,this._radius+.2,0),this._avatarNode=e}this._avatarNode.meshRender.material.setDiffuseTexture(t)},o.prototype.setAvatar=function(e){var o=t.AssetLoader.instance.get(e);this.setAvatarTexture(o)},o.prototype.setAvatarId=function(t){},o.prototype.setNameLabel=function(t){this._nameLabel||(this._nameLabel=this.createBox({long:2,width:.001,height:.2},t),this._nameLabel.transform.localPosition=new Laya.Vector3(0,this._radius+.25,0)),this._nameLabel.meshRender.material.setDiffuseTexture(t)},o.prototype.setNameId=function(e){var o=t.GameConfig2.Assets.AI_NAMES[e],i=t.AssetLoader.instance.get(o);this.setNameLabel(i)},o.prototype.createBox=function(t,e){var o=new Laya.BoxMesh(t.long,t.width,t.height),i=new Laya.MeshSprite3D(o),a=new touch.CustomMaterial;return a.setDiffuseTexture(e),a.setColor(new Laya.Vector4(1,1,1,1)),a.setHasLight(!1),a.setHasFog(!1),a.setHasAlphaTest(!0),a.setAlphaTestValue(.5),a.setTransparent(),i.meshRender.material=a,this.owner.addChild(i),i},o.prototype.addTo=function(t){t.addChild(this.owner)},o.prototype.setGameWorld=function(t){this._gameWorld=t},o.prototype.setPosition=function(t,e,o){this.transform.position=new Laya.Vector3(t,e,o)},Object.defineProperty(o.prototype,"position",{get:function(){return this.transform.position},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"ballBody",{get:function(){return this._ballBody},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"bodyTransform",{get:function(){return this._ballBody.transform},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"transform",{get:function(){return this.owner.transform},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"speed",{get:function(){return this._speed},set:function(t){this._speed=t},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"life",{get:function(){return this._life},set:function(t){this._life=t,console.info("Ball Life => ",t)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isAlive",{get:function(){return this._life>0},enumerable:!1,configurable:!0}),o.prototype.updateForwardRotation=function(t){this.bodyTransform.rotate(new Laya.Vector3(60*-this.speed*t,0,0),!0,!1)},o.prototype.updateSideRotation=function(t){var e=this.bodyTransform;e.rotation=new Laya.Quaternion(e.rotation.elements[0],0,t,e.rotation.elements[3])},o.prototype.moveForward=function(t){var e=this.transform;e.position=new Laya.Vector3(e.position.x,e.position.y,e.position.z-this.speed*t)},o.prototype.moveOnXAxis=function(t){this.transform.position.x=t},o.prototype.update=function(t){this.isAlive&&(this.updateForwardRotation(t),this.moveForward(t),this._updateTrail(),this._adjustBallSpeed(t),this.autoDrive&&this._autoAvoidObstacle(t),this._updateAliveState(t),this._resetState())},o.prototype.updateBendEffectAndDistance=function(e,o){this._effectParams.angle=e,this._effectParams.distance=o,t.GameRenderer.setBendAngleAndDistanceRecursive(this.owner,e,o,-1)},o.prototype._updateTrail=function(){if(this._trail.active){var t=this._trail;t.transform.position=new Laya.Vector3(0,0,0);var e=touch.Pool.getVector();e.x=this.position.x-.12,e.y=.01,e.z=this.position.z-.6;var o=touch.Pool.getVector();o.x=this.position.x+.12,o.y=.01,o.z=this.position.z-.6,t.addGlitterByPositions(e,o),touch.Pool.putVector(e),touch.Pool.putVector(o)}},o.prototype.getInitSpeed=function(){return 15*GameBaseData.gameSpeed},o.prototype._adjustBallSpeed=function(t){this._accelerating?this._accelerating=!1:this.speed>this.getInitSpeed()&&(this.speed-=.054*t*60,this.speed ",o.name),o.name==t.AccelerateBlock.NODE_NAME?this._onHitAccelerate():o.name==t.ObstacleBlock.NODE_NAME&&this._onHitObstacle()}},o.prototype._onHitAccelerate=function(){this._accelerating||(this.speed+=10.8*GameBaseData.gameSpeed,this.speed>42*GameBaseData.gameSpeed&&(this.speed=42*GameBaseData.gameSpeed),this._accelerating=!0)},o.prototype._onHitObstacle=function(){this._hitObstacle||(this._hitObstacle=!0,this.decreaseLife(1))},o.prototype.decreaseLife=function(t){this.life>0&&(this.life-=t,this.life<=0&&(this.life=0,this._onDead()))},o.prototype._onDead=function(){console.info("Ball ==> Dead"),this._showDeadEffect()},o.prototype._showDeadEffect=function(){if(!this._deadEffect){var e=t.DeadEffect.create();this.owner.addChild(e),e.transform.localPosition=new Laya.Vector3(0,.01-this._radius,0),this._deadEffect=e}this._deadEffect.show(),this.ballBody.active=!1,this._shadow.active=!1,this._trail.active=!1,this.updateBendEffectAndDistance(this._effectParams.angle,this._effectParams.distance)},o.prototype._resetState=function(){this._accelerating&&(this._accelerating=!0),this._hitObstacle&&(this._hitObstacle=!1)},o.prototype._updateAliveState=function(t){},Object.defineProperty(o.prototype,"autoDrive",{get:function(){return this._autoDrive},enumerable:!1,configurable:!0}),o.prototype.enableAutoDrive=function(t){this._gameWorld=t,this._autoDrive=!0},o.prototype.disableAutoDrive=function(){this._autoDrive=!1},o.prototype._autoAvoidObstacle=function(t){if(null!=this._gameWorld){for(var e=this._gameWorld.getAllObstacles(),o=[],i=0;i1&&r<=5&&a.transform.position.y<1&&o.push(a.transform.position.x)}if(o.length<=0)this._lastAutoDriveDir=0;else{var n=this._calculateSafeX(o),s=this.position.x,l=0;0!=(l=.05>Math.abs(n-s)?0:n>s?.2:-.2)&&this.moveOnXAxis(this.position.x+l)}}},o.prototype._calculateSafeX=function(t){for(var e=this.position.x,o=[],i=0;i<5;i++)o.push(!0);for(i=0;i=5&&(s=0)}return a},o}(Laya.Script);t.BallControl=e}(game2||(game2={}));