PlayerController.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. cc.Class({
  2. extends: require("BasePlayerController"),
  3. properties: {
  4. TouchNode: cc.Node,
  5. charactor: cc.Node,
  6. AiController: cc.Node,
  7. },
  8. onLoad() {
  9. this._super();
  10. this._Statepassivity = this.Statepassivity;
  11. this._RightJayShow = this.RightJayShow; //出右拳
  12. this._LeftJayShow = this.LeftJayShow; //出左拳
  13. this._RightDodge = this.RightDodge; //右躲闪
  14. this._LeftDodg = this.LeftDodg; //左躲闪
  15. this._Defence = this.Defence; //防御
  16. this._Hurt = this.Hurt;
  17. this._CriticalStrike = this.CriticalStrike; //暴击
  18. this._DoubleHit = this.DoubleHit; //连击
  19. this._BeCriticalStrike = this.BeCriticalStrike; //被暴击
  20. this._BeDoubleHit = this.BeDoubleHit; //被连击
  21. //注册回调事件
  22. let Self = this;
  23. this.TouchNode.on('gesture', function(event) {
  24. console.log(event.name);
  25. Self.Gesture(event.name);
  26. });
  27. },
  28. start() {
  29. this.init();
  30. },
  31. init() {
  32. //角色脚本
  33. this.ctorScp = this.charactor.getComponent('Charactor');
  34. this.AiControScp = this.AiController.getComponent('AiPlayerController');
  35. //this.statesScp = this.charactor.getComponent('PlayerStates');
  36. },
  37. Gesture(name) {
  38. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  39. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  40. console.log(randomnum_1, randomnum_2);
  41. if (name == 'right_top') {
  42. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  43. //出现暴击或者连击
  44. if (randomnum_2 == 1) {
  45. //暴击
  46. this._CriticalStrike = true;
  47. this.ctorScp.attack(2);
  48. this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  49. }
  50. if (randomnum_2 == 2) {
  51. //连击
  52. this._DoubleHit = true;
  53. this.ctorScp.attack(4);
  54. this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  55. }
  56. } else { //普攻状态 普攻动作
  57. this._RightJayShow = true;
  58. this.ctorScp.attack(0);
  59. this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  60. }
  61. } else if (name == 'left_top') {
  62. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  63. //出现暴击或者连击
  64. if (randomnum_2 == 1) {
  65. //暴击
  66. this._CriticalStrike = true;
  67. this.ctorScp.attack(3);
  68. this.AiControScp.ondefense_Ai(-1, 1); //左右拳,击打类型
  69. }
  70. if (randomnum_2 == 2) {
  71. //连击
  72. this._DoubleHit = true;
  73. this.ctorScp.attack(5);
  74. this.AiControScp.ondefense_Ai(-1, 2); //左右拳,击打类型
  75. }
  76. } else { //普攻状态 普攻动作
  77. this._LeftJayShow = true;
  78. this.ctorScp.attack(1);
  79. this.AiControScp.ondefense_Ai(-1, 0); //左右拳,击打类型
  80. }
  81. } else if (name == 'right_down') {
  82. this._RightDodge = true;
  83. this.AiControScp._Statepassivity = false;
  84. this.ctorScp.dodge(0);
  85. } else if (name == 'left_down') {
  86. this._LeftDodg = true;
  87. this.AiControScp._Statepassivity = false;
  88. this.ctorScp.dodge(1);
  89. } else if (name == 'down') {
  90. this._Defence = true;
  91. this.AiControScp._Statepassivity = false;
  92. this.ctorScp.block();
  93. }
  94. },
  95. // update (dt) {},
  96. });