AIBot.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const PlayerStateStatic = require('PlayerState');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. BotPerfectPercentage:40,
  6. },
  7. start : function () {
  8. this.NodeTouch = cc.find("TouchLayout").getComponent("NodeTouch");
  9. var randomNum = Math.floor(Math.random()*100);
  10. // cc.log(randomNum+'*************');
  11. if(randomNum<30){//低难度几率30%
  12. this.BotPerfectPercentage = 40;
  13. }else if(randomNum>=30 && randomNum<80){//中等难度几率50%
  14. this.BotPerfectPercentage = 70;
  15. }else if(randomNum>=80 && randomNum<=100){//高难度几率20%
  16. this.BotPerfectPercentage = 90;
  17. }
  18. },
  19. myRandom : function(num){
  20. if (num>Math.floor(Math.random()*100)) {
  21. return true;
  22. }else{
  23. return false;
  24. }
  25. },
  26. Enters :function (other,node) {
  27. var name = node.node.parent.parent.name;
  28. var PlayerStateScript = node.node.parent.parent.getComponent("PlayerState");
  29. var HeroControlScript = node.node.parent.parent.getComponent("HeroControl");
  30. //完美加速
  31. if (PlayerStateScript.CurrentInZoneType==PlayerStateStatic.ZoneType.AccelerationBandCenter) {
  32. // cc.log("调用了 ai 完美加速");
  33. if (this.myRandom(this.BotPerfectPercentage)) {
  34. this.NodeTouch.TOUCH_START(true);
  35. }
  36. }
  37. //右面加速
  38. else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.BehindAccelerationBand)
  39. {
  40. if (!PlayerStateScript.BTouchedScreenInTheZone) {
  41. if (this.myRandom(100)) {
  42. this.NodeTouch.TOUCH_START(true);
  43. }
  44. }
  45. }
  46. //长加速带
  47. else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.FrontLongAccelerationBand)
  48. {
  49. this.NodeTouch.TOUCH_START(true);
  50. setTimeout(function () {
  51. this.NodeTouch.TOUCH_END(true);
  52. }.bind(this),200);
  53. }
  54. //跳远
  55. else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.FrontLongJumpBand)//Hurdle
  56. {
  57. // cc.log("现在动作","跳远");
  58. // CustomLog("现在跳远",bHero);
  59. if (!PlayerStateScript.BTouchedScreenInTheZone) {
  60. this.NodeTouch.TOUCH_START(true);
  61. }
  62. }
  63. else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.PreHurdleBand)//Hurdle
  64. {
  65. // cc.log("跨栏",name);
  66. if (!PlayerStateScript.BTouchedScreenInTheZone) {
  67. if (this.myRandom(100)) {
  68. this.NodeTouch.TOUCH_START(true);
  69. }
  70. }
  71. }
  72. else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.PerfectHurdleBand)//Hurdle
  73. {
  74. if (!PlayerStateScript.BTouchedScreenInTheZone) {
  75. if (this.myRandom(this.BotPerfectPercentage)) {
  76. this.NodeTouch.TOUCH_START(true);
  77. }
  78. }
  79. }
  80. }
  81. });