PlayerController.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.AiControScp._Statepassivity = false;
  83. if (this.AiControScp._RightJayShow) {
  84. //被右拳打中
  85. if (this.AiControScp._CriticalStrike) {
  86. //被右拳打中 暴击
  87. this.ctorScp.hurt(1, 1);
  88. return;
  89. }
  90. if (this.AiControScp._DoubleHit) {
  91. //被右拳打中 连击
  92. this.ctorScp.hurt(1, 2);
  93. return;
  94. }
  95. this.ctorScp.hurt(1, 0);
  96. return;
  97. }
  98. this._RightDodge = true;
  99. this.ctorScp.dodge(0);
  100. } else if (name == 'left_down') {
  101. this.AiControScp._Statepassivity = false;
  102. if (this.AiControScp._LeftJayShow) {
  103. //被左拳打中
  104. if (this.AiControScp._CriticalStrike) {
  105. //被左拳打中 暴击
  106. this.ctorScp.hurt(0, 1);
  107. return;
  108. }
  109. if (this.AiControScp._DoubleHit) {
  110. //被左拳打中 连击
  111. this.ctorScp.hurt(0, 2);
  112. return;
  113. }
  114. this.ctorScp.hurt(0, 0);
  115. return;
  116. }
  117. this._LeftDodg = true;
  118. this.ctorScp.dodge(1);
  119. } else if (name == 'down') {
  120. this._Defence = true;
  121. this.AiControScp._Statepassivity = false;
  122. this.ctorScp.block();
  123. }
  124. },
  125. update(dt) {
  126. },
  127. });