AiCharactor.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. cc.Class({
  2. extends: require("BaseCharactor"),
  3. properties: {
  4. PlayerController: cc.Node,
  5. AiPlayerController: cc.Node,
  6. },
  7. onLoad() {
  8. this._super();
  9. this.armatureDisplay = this.node.getComponent(dragonBones.ArmatureDisplay);
  10. this.armature = this.armatureDisplay.armature();
  11. //添加动画事件监听
  12. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
  13. this.armatureDisplay.addEventListener(dragonBones.EventObject.FRAME_EVENT, this.animationEventHandler_Enter, this);
  14. },
  15. start() {
  16. this.init();
  17. },
  18. // update (dt) {},
  19. attack(bLeft) {
  20. //发射攻击事件 // 普攻
  21. if (bLeft == 0) {
  22. //右拳
  23. this.armatureDisplay.node.scaleX = 1;
  24. this.armature.animation.play("attack", 1);
  25. this.node.emit("attack");
  26. } else if (bLeft == 1) {
  27. //左拳
  28. this.armatureDisplay.node.scaleX = -1;
  29. this.armature.animation.play("attack", 1);
  30. this.node.emit("attack");
  31. }
  32. //暴击右
  33. else if (bLeft == 2) {
  34. this.armatureDisplay.node.scaleX = -1;
  35. this.armature.animation.play("critical_strike", 1);
  36. this.node.emit("attack_critical_strike");
  37. }
  38. //暴击左
  39. else if (bLeft == 3) {
  40. this.armatureDisplay.node.scaleX = 1;
  41. this.armature.animation.play("critical_strike", 1);
  42. this.node.emit("attack_critical_strike");
  43. }
  44. //连击
  45. else if (bLeft == 4) {
  46. this.armatureDisplay.node.scaleX = -1;
  47. this.armature.animation.play("double-hit", 1);
  48. this.node.emit("attack_double-hit");
  49. }
  50. //连击
  51. else if (bLeft == 5) {
  52. this.armatureDisplay.node.scaleX = 1;
  53. this.armature.animation.play("double-hit", 1);
  54. this.node.emit("attack_double-hit");
  55. }
  56. },
  57. dodge(bLeft) { //躲闪
  58. console.log("Ai躲闪");
  59. //发射躲闪事件
  60. if (bLeft == 0) {
  61. //左躲闪
  62. this.armatureDisplay.node.scaleX = 1;
  63. this.armature.animation.play("dodge", 1);
  64. } else if (bLeft == 1) {
  65. //右躲闪
  66. this.armatureDisplay.node.scaleX = -1;
  67. this.armature.animation.play("dodge", 1);
  68. }
  69. this.node.emit("dodge");
  70. },
  71. hurt(bLeft, type) { //挨打 左右拳,击打类型
  72. //发射挨打事件
  73. if (type == 0) {
  74. //普通挨打
  75. if (bLeft == 0) {
  76. //左挨打
  77. console.log("Ai挨右打");
  78. this.armatureDisplay.node.scaleX = -1;
  79. this.armature.animation.play("be_beaten", 1);
  80. } else if (bLeft == 1) {
  81. //右挨打
  82. console.log("Ai挨左打");
  83. this.armatureDisplay.node.scaleX = 1;
  84. this.armature.animation.play("be_beaten", 1);
  85. }
  86. }
  87. if (type == 1) {
  88. console.log("Ai挨暴打");
  89. if (bLeft == 0) {
  90. //左挨打
  91. //被暴打
  92. this.armatureDisplay.node.scaleX = -1;
  93. this.armature.animation.play("be_critical_strike", 1);
  94. } else if (bLeft == 1) {
  95. //被暴打
  96. //右挨打
  97. this.armatureDisplay.node.scaleX = 1;
  98. this.armature.animation.play("be_critical_strike", 1);
  99. }
  100. }
  101. if (type == 2) {
  102. console.log("Ai挨连打");
  103. if (bLeft == 0) {
  104. //被连击打
  105. //左挨打
  106. this.armatureDisplay.node.scaleX = -1;
  107. this.armature.animation.play("be_double_hit", 1);
  108. } else if (bLeft == 1) {
  109. //被连击打
  110. //右挨打
  111. this.armatureDisplay.node.scaleX = 1;
  112. this.armature.animation.play("be_double_hit", 1);
  113. }
  114. }
  115. this.node.emit("be_beaten");
  116. },
  117. block() { //防御
  118. this.armature.animation.play("block", 1);
  119. this.node.emit("block");
  120. },
  121. animationEventHandler(event) {
  122. if (event.type === dragonBones.EventObject.COMPLETE) {
  123. //主角
  124. if (event.animationState.name === "attack") {
  125. console.log("attack 动作播放完毕!!!");
  126. //TODO:
  127. //this.armatureDisplay.node.scaleX = 0.39;
  128. this.armature.animation.play("idle", 0);
  129. this.aicontroScp._RightJayShow = false;
  130. this.aicontroScp._LeftJayShow = false;
  131. this.aicontroScp._Statepassivity = false;
  132. }
  133. if (event.animationState.name === "be_beaten") {
  134. console.log("critical_strike 动作播放完毕!!!");
  135. //TODO:
  136. this.armatureDisplay.node.scaleX = 1;
  137. this.armature.animation.play("idle", 0);
  138. this.aicontroScp._Hurt = false;
  139. this.aicontroScp._Statepassivity = false;
  140. }
  141. if (event.animationState.name === "critical_strike") {
  142. console.log("critical_strike 动作播放完毕!!!");
  143. //TODO:
  144. //this.armatureDisplay.node.scaleX = 0.39;
  145. this.armature.animation.play("idle", 0);
  146. this.aicontroScp._CriticalStrike = false;
  147. this.aicontroScp._Statepassivity = false;
  148. }
  149. if (event.animationState.name === "double-hit") {
  150. console.log("double-hit 动作播放完毕!!!");
  151. //TODO:
  152. //this.armatureDisplay.node.scaleX = 0.39;
  153. this.armature.animation.play("idle", 0);
  154. this.aicontroScp._DoubleHit = false;
  155. this.aicontroScp._Statepassivity = false;
  156. }
  157. if (event.animationState.name === "dodge") {
  158. console.log("dodge 动作播放完毕!!!");
  159. //TODO:
  160. //this.armatureDisplay.node.scaleX = 0.39;
  161. this.armature.animation.play("idle", 0);
  162. this.aicontroScp._RightDodge = false;
  163. this.aicontroScp._LeftDodg = false;
  164. this.aicontroScp._Statepassivity = false;
  165. }
  166. if (event.animationState.name === "block") {
  167. console.log("block 动作播放完毕!!!");
  168. //TODO:
  169. // this.armatureDisplay.node.scaleX = 0.39;
  170. this.armature.animation.play("idle", 0);
  171. this.aicontroScp._Defence = false;
  172. this.aicontroScp._Statepassivity = false;
  173. }
  174. }
  175. },
  176. animationEventHandler_Enter(event) {
  177. },
  178. init() {
  179. //角色脚本
  180. this.controScp = this.PlayerController.getComponent('PlayerController');
  181. //Ai脚本
  182. this.aicontroScp = this.AiPlayerController.getComponent('AiPlayerController');
  183. },
  184. });