AiPlayerController.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. var gameConfig = require("../GameConfig.js");
  2. var playerConfig = require("./AiPlayerConfig");
  3. var webView = require("../../WebView");
  4. var globalConfig = require("../../Global");
  5. var lib = require("../../Library.js");
  6. var server = require("../../MiniGameServer");
  7. cc.Class({
  8. extends: require("BasePlayerController"),
  9. properties: {
  10. mainPlayer: {
  11. default: null,
  12. type: cc.Node,
  13. serializable: true,
  14. },
  15. },
  16. init()//override
  17. {
  18. this._super();
  19. this.areaState = -1;
  20. this.area1 = gameConfig.handrailArea1;
  21. this.area2 = gameConfig.handrailArea2;
  22. this.playerConfig = playerConfig;
  23. },
  24. start()//override
  25. {
  26. this._super();
  27. },
  28. update(dt) {//override
  29. this._super();
  30. if(!globalConfig.bAi) return;
  31. //super class return is not effect to sub class so we need to write if return every subclass
  32. if(this.pStatesSt.currentProState == this.pStatesSt.pProStates.end) return;
  33. //测试用给Ai随机速度
  34. // if (this.pStatesSt.currentSpeed < playerConfig.playerSpeedGrade.fast)
  35. // {
  36. // this.pStatesSt.currentSpeed += lib.randomFromIntRange(0, 1.2);
  37. // // this.pStatesSt.currentSpeed += lib.randomFromIntRange(0, 1);
  38. // }
  39. if(lib.randomFromIntRange(0, 100)>98){
  40. this.speedUp();
  41. }
  42. if(this.pStatesSt.handrailArr.length == this.pStatesSt.passedHurdrailNum)return;
  43. this.hurdrailStartPX = this.pStatesSt.handrailArr[this.pStatesSt.passedHurdrailNum].startPX;
  44. // Enter jump area 1 of handrail
  45. if (this.node.x > this.hurdrailStartPX+this.area1.end/2 &&
  46. this.node.x < this.hurdrailStartPX+this.area1.end)
  47. {
  48. if(this.areaState == -1)
  49. {
  50. this.areaState = 0;
  51. this.rate = lib.randomFromIntRange(0,100);
  52. if(this.rate<40)
  53. {
  54. this.jump();
  55. }
  56. }
  57. }
  58. // Enter jump area 2 of handrail
  59. if (this.node.x > this.hurdrailStartPX + this.area2.end/2 &&
  60. this.node.x < this.hurdrailStartPX + this.area2.end)//-(2487-2374))
  61. {
  62. if(this.areaState == 0)
  63. {
  64. this.areaState = 1;
  65. if (this.rate >= 40 && this.rate < 50) {
  66. this.jump();
  67. }
  68. this.schedule(function() {
  69. this.areaState = -1;
  70. }, 1, 0, 0);
  71. }
  72. }
  73. },
  74. setEndSpeed(){//overwrite
  75. this.pStatesSt.intoTheEndSpeed = this.pStatesSt.currentSpeed / (this.gmSt.terminal.x+35-this.pStatesSt.endLineStopPoint);
  76. },
  77. passedHandrail()//overwrite
  78. {
  79. // console.log('passedHandrail');
  80. let ContainIndex = -1;
  81. for(let i=0;i<this.gStatesSt.drawedhandrailArr.length;i++)
  82. {
  83. // console.log('index',this.gStatesSt.drawedhandrailArr[i].index);
  84. // console.log('Num',this.pStatesSt.passedHurdrailNum);
  85. if(this.gStatesSt.drawedhandrailArr[i].index == this.pStatesSt.passedHurdrailNum)
  86. {
  87. ContainIndex = i;
  88. break;
  89. }
  90. }
  91. if(ContainIndex!=-1)
  92. {
  93. // console.log('Kuolan2 fall');
  94. let handrail = this.gStatesSt.drawedhandrailArr[ContainIndex].handrail.getChildByName('Kuolan2');
  95. let spine = handrail.getComponent(sp.Skeleton);
  96. spine.setAnimation(0, 'Idl1_3', false);
  97. this.ctorSt.stagger();
  98. }
  99. },
  100. jump() {//overwrite
  101. this.pStatesSt.currentState = this.pStatesSt.playerAnimState.jump;
  102. this.ctorSt.jump('hurdling_1', function ()
  103. {
  104. this.pStatesSt.currentState = this.pStatesSt.playerAnimState.run;
  105. this.pStatesSt.passedHurdrailNum++;
  106. }.bind(this));
  107. }
  108. });