Charactor.js 8.0 KB

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