Actor.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. let library = require("../Library");
  2. let gameConfig = require("GameConfig");
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. gameStates: {
  7. default: null,
  8. type: cc.Node,
  9. serializable: true,
  10. },
  11. aiPlayerController: {
  12. default: null,
  13. type: cc.Node,
  14. serializable: true,
  15. },
  16. nameIndex:0
  17. },
  18. onLoad () {
  19. this.gStatesScp = this.gameStates.getComponent('GameStates');
  20. this.aiPConScp = this.aiPlayerController.getComponent('AiPlayerController');
  21. this.bBeat = false;
  22. this.comeOutY = -110;
  23. this.hiddenY = -340;
  24. this.armatureDisplay = this.getComponent(dragonBones.ArmatureDisplay);
  25. this.blueArmatureDisplay = this.node.getChildByName('quantao_blue_ske').getComponent(dragonBones.ArmatureDisplay);
  26. this.redArmatureDisplay = this.node.getChildByName('quantao_ske').getComponent(dragonBones.ArmatureDisplay);
  27. //获取 Armatrue
  28. this.armature = this.armatureDisplay.armature();
  29. //添加动画监听
  30. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
  31. this.idleAnimName = [
  32. 'idle',
  33. 'idle1',
  34. 'idle2',
  35. ];
  36. this.hookAnimName = [
  37. 'joy21',
  38. 'joy22',
  39. 'joy23',
  40. ];
  41. this.jayAnimName = [
  42. 'hook11',
  43. 'hook12',
  44. 'hook13',
  45. ];
  46. this.dizzAnimName = [
  47. 'dizzy',
  48. 'dizzy1',
  49. 'dizzy2',
  50. ];
  51. this.currentActorName = 0;
  52. },
  53. spawn(appearDur){
  54. let self = this;
  55. library.removeObj(this.gStatesScp.hiddenMouseArr,this.node);
  56. this.gStatesScp.appearMouseArr.push(this.node);
  57. this.currentActorName = library.randomInt(0,2);
  58. this.armatureDisplay.playAnimation(this.idleAnimName[this.currentActorName],1);
  59. //come out
  60. cc.tween(self.node)
  61. .to(0.1, { position: cc.v2(self.node.x,self.comeOutY)})
  62. .call(() =>
  63. {
  64. self.bBeat = true;
  65. self.aiPConScp.actorComeOut(self.nameIndex,appearDur);
  66. //delay to play
  67. self.scheduleOnce(function () {
  68. if(!self.bBeat) return;
  69. self.die();
  70. },appearDur);
  71. })
  72. .start()
  73. },
  74. comeOutFinished(self)
  75. {
  76. //come in
  77. cc.tween(self.node)
  78. .to(0.1, { position: cc.v2(self.node.x,self.hiddenY)})
  79. .start();
  80. },
  81. punch(bAi)
  82. {
  83. this.bBeat = false;
  84. if(0==this.nameIndex)
  85. {
  86. this.armatureDisplay.playAnimation(this.hookAnimName[this.currentActorName],1);
  87. if(bAi)
  88. {
  89. this.redArmatureDisplay.playAnimation("attack2",1);
  90. }
  91. else
  92. {
  93. this.blueArmatureDisplay.playAnimation("attack2",1);
  94. }
  95. return;
  96. }
  97. //left or right punch
  98. this.armatureDisplay.playAnimation(this.jayAnimName[this.currentActorName],1);
  99. if(bAi)
  100. {
  101. this.redArmatureDisplay.playAnimation("attack1",1);
  102. }
  103. else
  104. {
  105. this.blueArmatureDisplay.playAnimation("attack1",1);
  106. }
  107. },
  108. animationEventHandler(event)
  109. {
  110. if (event.type === dragonBones.EventObject.COMPLETE)
  111. {
  112. if (event.animationState.name === "hook11")
  113. {
  114. this.die();
  115. }
  116. else if (event.animationState.name === "hook12")
  117. {
  118. this.die();
  119. }
  120. else if (event.animationState.name === "hook13")
  121. {
  122. this.die();
  123. }
  124. else if (event.animationState.name === "joy21")
  125. {
  126. this.die();
  127. }
  128. else if (event.animationState.name === "joy22")
  129. {
  130. this.die();
  131. }
  132. else if (event.animationState.name === "joy23")
  133. {
  134. this.die();
  135. }
  136. }
  137. },
  138. die()
  139. {
  140. this.bBeat = false;
  141. library.removeObj(this.gStatesScp.appearMouseArr,this.node);
  142. this.gStatesScp.hiddenMouseArr.push(this.node);
  143. this.comeOutFinished(this);
  144. },
  145. });