AIBot.js 2.6 KB

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