FSpring.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { AudioMgr } from "../../../../main/ViewManage";
  2. import CUtilTime from "../../../../util/CUtilTime";
  3. import FF from "../../FF";
  4. import { GroupType } from "../../object/FObject";
  5. import FSprite, { SpriteActionType } from "../../object/FSprite";
  6. import BaseEvent from "../base/BaseEvent";
  7. /**
  8. * 泉水/吃苹果/吃蘑菇恢复气血
  9. */
  10. const {ccclass, property} = cc._decorator;
  11. @ccclass
  12. export default class FSpring extends BaseEvent {
  13. @property({
  14. type:cc.Prefab,
  15. displayName: '恢复的动画效果'
  16. })
  17. public effect:cc.Prefab = null;
  18. @property({
  19. type:cc.Font,
  20. displayName: '恢复的数字'
  21. })
  22. public effectNumber:cc.Font = null;
  23. @property({
  24. type:sp.Skeleton,
  25. displayName: '泉水动画'
  26. })
  27. public spine:sp.Skeleton = null;
  28. @property({
  29. displayName: '靠近的提示',
  30. type: cc.Node
  31. })
  32. icon: cc.Node = null;
  33. @property({
  34. displayName: '提示图标',
  35. type:cc.SpriteFrame
  36. })
  37. mTipsIcon: cc.SpriteFrame = null;
  38. @property({
  39. displayName: '采摘进度条',
  40. type:cc.ProgressBar
  41. })
  42. mProgressBar: cc.ProgressBar = null;
  43. @property(cc.Node)
  44. guides: Array<cc.Node> = [];//引导标识
  45. private isOpen = false
  46. onLoad(){
  47. super.onLoad()
  48. this.mProgressBar.node.active = false
  49. if (this.icon) {
  50. this.icon.active = false;
  51. }
  52. }
  53. onBegin(tag:number){
  54. if(this.isOpen){
  55. return
  56. }
  57. if(tag == 1){
  58. this.showButton();
  59. } else if (tag == 2) {
  60. if (this.icon) {
  61. this.icon.active = true;
  62. }
  63. }
  64. }
  65. onEnd(tag:number){
  66. if(tag == 1){
  67. this.closeOpt()
  68. } else if (tag == 2) {
  69. if (this.icon) {
  70. this.icon.active = false;
  71. }
  72. }
  73. }
  74. public showButton(){
  75. this.showOpt(this.mTipsIcon,()=>{
  76. this.isOpen = true
  77. this.huifu()
  78. })
  79. }
  80. private huifu(){
  81. if(this.spine){
  82. this.spine.setAnimation(0,'hit',true)
  83. }
  84. for (let i = 0; i < this.guides.length; i++) {
  85. const element = this.guides[i];
  86. element.destroy();
  87. }
  88. this.guides = [];
  89. this.closeOpt()
  90. // let cur = CUtilTime.getNowTime();
  91. // let sy = this.time - (cur - this.lastTime);
  92. // if(sy > 0){
  93. // this.ff.main.showTips('泉水恢复中('+sy+'秒)');
  94. // return;
  95. // }
  96. // this.lastTime = cur;
  97. this.ff.pauseSprite(true);
  98. this.ff.mainSprite.playAction(SpriteActionType.shiqu, true)
  99. this.playProgressBar()
  100. }
  101. private playProgressBar(){
  102. this.mProgressBar.progress = 0
  103. this.mProgressBar.node.active = true
  104. this.schedule(this.progressBarUpdate,0.1,11)
  105. }
  106. private progressBarUpdate(){
  107. this.mProgressBar.progress += 0.1
  108. if(this.mProgressBar.progress >= 1){
  109. this.ff.main.playerEffectByPath(AudioMgr.blood);
  110. this.unschedule(this.progressBarUpdate)
  111. this.mProgressBar.node.active = false
  112. this.ff.mainSprite.playAction(SpriteActionType.stand, true)
  113. this.addHP()
  114. }
  115. }
  116. private addHP(){
  117. this.ff.pauseSprite(false);
  118. if(this.spine){
  119. this.spine.setAnimation(0,'dead',false)
  120. this.spine.setCompleteListener(() => {
  121. this.spine.setCompleteListener(null);
  122. });
  123. }
  124. cc.tween(this.node).sequence(
  125. cc.callFunc(()=>{
  126. this.playEffect();
  127. }),
  128. cc.delayTime(0.5,),
  129. cc.callFunc(()=>{
  130. this.playEffect();
  131. }),
  132. cc.delayTime(0.5,),
  133. cc.callFunc(()=>{
  134. this.playEffect();
  135. }),
  136. ).start();
  137. }
  138. /**
  139. * 播放特效动画
  140. * @param sprite
  141. */
  142. private playEffect(){
  143. let nodes = this.ff.getGroupBy(GroupType.A);
  144. for (let i = 0; i < nodes.length; i++) {
  145. const element = nodes[i];
  146. if(element && element.hp > 0){
  147. let sprite = element.getComponent(FSprite);
  148. let addHP = Math.floor(sprite.attrData.hp/5);
  149. sprite.hp += addHP;
  150. if(sprite.hp > sprite.attrData.hp){
  151. sprite.hp = sprite.attrData.hp;
  152. }
  153. sprite.updatePanel();
  154. this.playNumber(sprite,addHP);
  155. }
  156. }
  157. }
  158. private playNumber(sprite:FSprite,addHP){
  159. let nodeEffect = cc.instantiate(this.effect);
  160. nodeEffect.parent = sprite.node;
  161. nodeEffect.group = sprite.node.group;
  162. let node: cc.Node = new cc.Node('hp');
  163. node.group = 'map';
  164. let lable: cc.Label = node.addComponent(cc.Label);
  165. lable.fontSize = 26;
  166. lable.font = this.effectNumber;
  167. lable.string = '.'+addHP;
  168. node.x = sprite.node.x;
  169. node.y = sprite.node.y + 40;
  170. this.ff.mMap.node.addChild(node);
  171. cc.tween(node).sequence(
  172. cc.spawn(
  173. cc.moveBy(1, cc.v2(0, 60)).easing(cc.easeSineOut()),
  174. cc.fadeOut(1)
  175. ),
  176. cc.callFunc(()=>{
  177. node.destroy();
  178. nodeEffect.destroy();
  179. })
  180. ).start();
  181. }
  182. }