| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- var gameConfig = require("../GameConfig.js");
- var playerConfig = require("./AiPlayerConfig");
- var webView = require("../../WebView");
- var globalConfig = require("../../Global");
- var lib = require("../../Library.js");
- var server = require("../../MiniGameServer");
- cc.Class({
- extends: require("BasePlayerController"),
- properties: {
- mainPlayer: {
- default: null,
- type: cc.Node,
- serializable: true,
- },
- },
- init()//override
- {
- this._super();
- this.areaState = -1;
- this.area1 = gameConfig.handrailArea1;
- this.area2 = gameConfig.handrailArea2;
- this.playerConfig = playerConfig;
- },
- start()//override
- {
- this._super();
- },
- update(dt) {//override
- this._super();
- if(!globalConfig.bAi) return;
- //super class return is not effect to sub class so we need to write if return every subclass
- if(this.pStatesSt.currentProState == this.pStatesSt.pProStates.end) return;
- //测试用给Ai随机速度
- // if (this.pStatesSt.currentSpeed < playerConfig.playerSpeedGrade.fast)
- // {
- // this.pStatesSt.currentSpeed += lib.randomFromIntRange(0, 1.2);
- // // this.pStatesSt.currentSpeed += lib.randomFromIntRange(0, 1);
- // }
- if(lib.randomFromIntRange(0, 100)>98){
- this.speedUp();
- }
- if(this.pStatesSt.handrailArr.length == this.pStatesSt.passedHurdrailNum)return;
- this.hurdrailStartPX = this.pStatesSt.handrailArr[this.pStatesSt.passedHurdrailNum].startPX;
- // Enter jump area 1 of handrail
- if (this.node.x > this.hurdrailStartPX+this.area1.end/2 &&
- this.node.x < this.hurdrailStartPX+this.area1.end)
- {
- if(this.areaState == -1)
- {
- this.areaState = 0;
- this.rate = lib.randomFromIntRange(0,100);
- if(this.rate<40)
- {
- this.jump();
- }
- }
- }
- // Enter jump area 2 of handrail
- if (this.node.x > this.hurdrailStartPX + this.area2.end/2 &&
- this.node.x < this.hurdrailStartPX + this.area2.end)//-(2487-2374))
- {
- if(this.areaState == 0)
- {
- this.areaState = 1;
- if (this.rate >= 40 && this.rate < 50) {
- this.jump();
- }
- this.schedule(function() {
- this.areaState = -1;
- }, 1, 0, 0);
- }
- }
- },
- setEndSpeed(){//overwrite
- this.pStatesSt.intoTheEndSpeed = this.pStatesSt.currentSpeed / (this.gmSt.terminal.x+35-this.pStatesSt.endLineStopPoint);
- },
- passedHandrail()//overwrite
- {
- // console.log('passedHandrail');
- let ContainIndex = -1;
- for(let i=0;i<this.gStatesSt.drawedhandrailArr.length;i++)
- {
- // console.log('index',this.gStatesSt.drawedhandrailArr[i].index);
- // console.log('Num',this.pStatesSt.passedHurdrailNum);
- if(this.gStatesSt.drawedhandrailArr[i].index == this.pStatesSt.passedHurdrailNum)
- {
- ContainIndex = i;
- break;
- }
- }
- if(ContainIndex!=-1)
- {
- // console.log('Kuolan2 fall');
- let handrail = this.gStatesSt.drawedhandrailArr[ContainIndex].handrail.getChildByName('Kuolan2');
- let spine = handrail.getComponent(sp.Skeleton);
- spine.setAnimation(0, 'Idl1_3', false);
- this.ctorSt.stagger();
- }
- },
- jump() {//overwrite
- this.pStatesSt.currentState = this.pStatesSt.playerAnimState.jump;
- this.ctorSt.jump('hurdling_1', function ()
- {
- this.pStatesSt.currentState = this.pStatesSt.playerAnimState.run;
- this.pStatesSt.passedHurdrailNum++;
- }.bind(this));
- }
- });
|