| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- var gameConfig = require("../GameConfig.js");
- var BasePlayerConfig = require("./BasePlayerConfig");
- var playerConfig = new BasePlayerConfig();
- cc.Class({
- extends: cc.Component,
- properties: {
- gameMode: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- charactor: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- playerStates: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- lastTime:0,
- deltaTime:0
- },
- onLoad() {
- this.init();
- },
- init() {
- //gameModeScript
- this.gmSt = this.gameMode.getComponent('GameMode');
- //gStatesSt
- this.gStatesSt = this.gmSt.gStatesSt;
- //ctorSt
- this.ctorSt = this.charactor.getComponent('BaseCharactor');
- //pStatesSt
- this.pStatesSt = this.playerStates.getComponent('BasePlayerStates');
- this.runDuration = 1000;
- this.playerConfig = playerConfig;
- },
- start() { },//override
- resetZindex() {
- this.node.zIndex = this.ctorSt.zOrder;
- },
- update(dt) {
- //计算deltatime cocos 的dt坏了
- let ms = new Date().getMilliseconds();
-
- if(ms>this.lastTime)
- {
- this.deltaTime = ms-this.lastTime;
- }
- else{
- this.deltaTime = 1000-this.lastTime+ms;
- }
- this.lastTime = ms;
-
- if (this.pStatesSt.currentProState == this.pStatesSt.pProStates.end) return;
- //跑 run
- if (this.pStatesSt.currentState == this.pStatesSt.playerAnimState.run) {
-
- if(this.pStatesSt.restMovePos!=0)
- {
- if(this.pStatesSt.targetMovePos-this.node.x<0)
- {
- this.node.x = this.pStatesSt.targetMovePos;
- this.pStatesSt.restMovePos=0;
-
- this.pStatesSt.actionArr.shift();
- if(this.pStatesSt.actionArr.length==0)
- {
- this.resetRunState();
- }
- else{
- this.run();
- }
- }
-
- if(this.pStatesSt.restMovePos>0)
- {
- // console.log('x =',this.pStatesSt.restMovePos * this.deltaTime / this.runDuration)
- this.node.x += this.pStatesSt.restMovePos * this.deltaTime / this.runDuration;
- this.runDuration -= this.deltaTime;
-
- //不同速度下不同跑步動畫切換
- if (this.pStatesSt.currentSpeed - this.playerConfig.speedReducing > this.playerConfig.playerSpeedGrade.idle) {
-
- if (this.pStatesSt.currentSpeed < this.playerConfig.playerSpeedGrade.medium) {
- if (this.pStatesSt.currentSpeedGrade != this.playerConfig.playerSpeedGrade.slow) {
- this.ctorSt.run('Run1');
- this.pStatesSt.currentSpeedGrade = this.playerConfig.playerSpeedGrade.slow;
- }
- }
- else if (this.pStatesSt.currentSpeed > this.playerConfig.playerSpeedGrade.medium &&
- this.pStatesSt.currentSpeed < this.playerConfig.playerSpeedGrade.fast) {
- if (this.pStatesSt.currentSpeedGrade != this.playerConfig.playerSpeedGrade.medium) {
- this.ctorSt.run('Run2');
- this.pStatesSt.currentSpeedGrade = this.playerConfig.playerSpeedGrade.medium;
- }
- }
- this.pStatesSt.currentSpeed -= this.playerConfig.speedReducing;
-
- } else {
- this.pStatesSt.currentSpeed = this.playerConfig.playerSpeedGrade.idle;
- }
-
- if (this.pStatesSt.passedHurdrailNum <= this.pStatesSt.handrailArr.length - 1) {
- if (this.node.x >= this.pStatesSt.handrailArr[this.pStatesSt.passedHurdrailNum].startPX + gameConfig.handrailLength + 20) {
- this.passedHandrail();
- this.pStatesSt.handrailArr[this.pStatesSt.passedHurdrailNum].bFallDown = 1;
- this.pStatesSt.passedHurdrailNum++;
- }
- }
- }
- }
- }
-
- //Enter end area
- if (this.node.x > this.gmSt.terminal.x - 320 &&
- this.pStatesSt.currentProState < this.pStatesSt.pProStates.intoEnd) {
- this.pStatesSt.currentProState = this.pStatesSt.pProStates.intoEnd;
- this.setEndSpeed();
- }
- //Prepare to endLine
- if (this.pStatesSt.currentProState == this.pStatesSt.pProStates.intoEnd) {
- if (this.pStatesSt.currentSpeed <= 0) return;
- this.pStatesSt.currentSpeed -= this.pStatesSt.intoTheEndSpeed;
- }
- //Enter endline
- if (this.node.x > this.gmSt.terminal.x - this.pStatesSt.endLineStopPoint && this.gmSt.terminal.active) {
- this.enterEndline();
- }
- },
- setEndSpeed() {},//overwrite
- passedHandrail() {},//overwrite
- enterEndline() {
- this.pStatesSt.currentSpeed = 0;
- this.ctorSt.setAnim('idle', false);
- this.pStatesSt.currentState = this.pStatesSt.playerAnimState.default;
- this.pStatesSt.currentProState = this.pStatesSt.pProStates.end;
- this.gStatesSt.arrEndPArr.push(this.pStatesSt);
- },
- speedUp() {
-
- if(this.pStatesSt.currentState != this.pStatesSt.playerAnimState.run) return;
- if(this.pStatesSt.currentSpeed > this.playerConfig.playerSpeedGrade.fast) return;
- if(this.pStatesSt.restMovePos != 0) return;
- this.pStatesSt.runTimes++;
- this.pStatesSt.currentSpeed += this.playerConfig.acceleration;
- this.runDuration = 1000-this.pStatesSt.currentSpeed;
- this.pStatesSt.targetMovePos = this.node.x+this.playerConfig.perRunDistance;
- // console.log('targetMovePos=',this.pStatesSt.targetMovePos)
- this.pStatesSt.restMovePos = this.playerConfig.perRunDistance;
- this.ctorSt.run('Run1');
-
- },
- // speedUp() {
-
- // this.pStatesSt.runTimes++;
- // if(this.pStatesSt.currentState != this.pStatesSt.playerAnimState.run) return;
- // this.pStatesSt.futureSpeed += playerConfig.acceleration;
- // if(this.pStatesSt.futureSpeed > playerConfig.playerSpeedGrade.fast)
- // {
- // this.pStatesSt.futureSpeed = playerConfig.playerSpeedGrade.fast;
- // }
- // if(this.pStatesSt.actionArr.length == 0)
- // {
- // this.pStatesSt.actionArr.push(this.pStatesSt.currentSpeed);
- // this.run();
- // }
- // else if(this.pStatesSt.actionArr.length == 1)
- // {
- // this.pStatesSt.actionArr.push(this.pStatesSt.currentSpeed);
- // }
- // },
- // run() {
- // if (this.pStatesSt.currentSpeed <= playerConfig.playerSpeedGrade.fast &&
- // this.pStatesSt.currentState == this.pStatesSt.playerAnimState.run &&
- // this.pStatesSt.restMovePos == 0)
- // {
- // // console.log('lastSpeed =',this.pStatesSt.lastSpeed)
- // // console.log('futureSpeed =',this.pStatesSt.futureSpeed)
- // if(this.pStatesSt.lastSpeed <this.pStatesSt.futureSpeed)
- // {
- // this.pStatesSt.currentSpeed = this.pStatesSt.lastSpeed + playerConfig.acceleration;
- // this.pStatesSt.lastSpeed = this.pStatesSt.currentSpeed;
- // }
- // // console.log('currentSpeed =',this.pStatesSt.currentSpeed)
- // this.runDuration = 1000-this.pStatesSt.currentSpeed;
- // this.pStatesSt.targetMovePos = this.node.x+playerConfig.perRunDistance;
- // this.pStatesSt.restMovePos = playerConfig.perRunDistance;
- // this.ctorSt.run('Run1');
- // }
- // },
- stop(){
- this.node.x = this.pStatesSt.targetMovePos;
- this.pStatesSt.restMovePos=0;
- this.resetRunState();
- },
- resetRunState(){
- this.pStatesSt.actionArr.length = 0;
- this.ctorSt.run('idle');
- this.pStatesSt.currentSpeedGrade = this.playerConfig.playerSpeedGrade.idle;
- // this.pStatesSt.lastSpeed = playerConfig.playerSpeedGrade.idle;
- this.pStatesSt.currentSpeed = this.playerConfig.playerSpeedGrade.idle;
- // this.pStatesSt.futureSpeed = playerConfig.playerSpeedGrade.idle;
- this.runDuration = 1000;
- },
- speedUp_client(){},
- jump() {}//overwrite
- });
|