| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- const MOVE_RIGHT = 2;
- cc.macro.ENABLE_TILEDMAP_CULLING = false;
- cc.Class({
- extends: cc.Component,
- properties: {
- InitialPositionY:0,
- CurrentSpeed: 300,
- jumps: 2,
- acceleration: 1500,
- jumpSpeed: 600,
- drag: 600,
- Level: {
- default: null,
- type: cc.Node
- },
- player: {
- default: null,
- type: cc.Node
- }
- },
- // use this for initialization
- onLoad: function () {
- this._up = false;
- this.body = this.getComponent(cc.RigidBody);
- this.speed = cc.p(0, 0);
- this.InitialPositionY = this.node.getPositionY();
- this.EnableHeroMoving(true);
- },
- HeroJump:function()
- {
- if(this.node.getPositionY()>this.InitialPositionY)return;
- this._up = true;
- // this.CurrentSpeed=500;
- // this.schedule(function()
- // {
- // this.CurrentSpeed=300;
- // }, 1,1);
- },
- EnableHeroMoving:function(bMoving)
- {
- if(bMoving)
- {
- this._moveFlags = MOVE_RIGHT;
- }
- else
- {
- this._moveFlags = -1;
- }
- },
- HeroUpSpeed:function(UpValue)
- {
- // cc.log('speed up');
- if(this.CurrentSpeed<1000 )
- {
- // cc.log('speed ='+this.CurrentSpeed);
- this.CurrentSpeed+=UpValue;
- }
- },
- // Stagger:function()
- // {
- // // cc.log('Stagger')
- // var PlayerStateScript = this.node.getComponent("PlayerState");
- // // cc.log("踉跄",PlayerStateScript.BStagger);
- // if(PlayerStateScript.BStagger) return;
- // PlayerStateScript.BStagger = !PlayerStateScript.BStagger;
- //
- // //踉跄+减速
- // this.player.getComponent("Charactor").setOnTripListener();
- //
- // this.player.getComponent("Charactor").setEndListener(function (animationName) {
- // if (animationName == "run-05") {
- // // PlayerStateScript.BStagger = !PlayerStateScript.BStagger;
- // }
- // }.bind(this));
- // this.CurrentSpeed = 50;
- // this.getComponent("easing").startDamp(this.CurrentSpeed,0.1,0,500,2);
- //
- // this.getComponent("easing").sethandleCallBack(function () {
- // // cc.log("轨迹 结束");
- // PlayerStateScript.BStagger = !PlayerStateScript.BStagger;
- // }.bind(this));
- // this.getComponent("easing").setreduceListnener(function (s) {
- // this.CurrentSpeed=s;
- // }.bind(this));
- // this.getComponent("easing").setincreaseListnener(function (s) {
- // this.CurrentSpeed=s;
- // }.bind(this));
- // },
- onBeginContact: function (contact, selfCollider, otherCollider) {
- // if (selfCollider.node.y > otherCollider.node.y) {
- // this.jumps = 2;
- // }
- // if (otherCollider.tag === 100) {
- // this.camera.shakeCamera();
- // }
- },
- // called every frame, uncomment this function to activate update callback
- update: function (dt) {
- this.speed = this.body.linearVelocity;
- // this.Level.getComponent('Level').SetDistance(this.node.getPosition().x);
- // this.Level.getComponent('LevelControl').SetDistance(this.node.getPosition().x);
- if (this._moveFlags === MOVE_RIGHT) {
- // this.anim.play('walk');
- if(this.node.scaleX < 0) {
- this.node.scaleX *= -1;
- }
- this.speed.x += this.acceleration * dt;
- if(this.speed.x > this.CurrentSpeed) {
- this.speed.x = this.CurrentSpeed;
- }
- }
- else {
- if(this.speed.x !== 0) {
- var d = this.drag * dt;
- if(Math.abs(this.speed.x) <= d) {
- this.speed.x = 0;
- // this.anim.play('idle');
- } else {
- this.speed.x -= this.speed.x > 0 ? d : -d;
- }
- }
- }
-
- if (this.jumps > 0 && this._up) {
- this.speed.y = this.jumpSpeed;
- this.jumps--;
- }
- this._up = false;
- this.body.linearVelocity = this.speed;
- },
- //todo 所有的都移动出去了
- // allMoveEndListnener : function (node) {
- // // cc.log('我所有的都出去了',this.player);
- // this.player.getComponent("Charactor").setOnTripListener();
- // }
- });
|