EffectLayer.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {CELL_WIDTH} from '../Model/ConstValue';
  2. import AudioUtils from "../Utils/AudioUtils";
  3. import Toast from '../Utils/Toast';
  4. cc.Class({
  5. extends: cc.Component,
  6. properties: {
  7. // foo: {
  8. // default: null, // The default value will be used only when the component attaching
  9. // to a node for the first time
  10. // url: cc.Texture2D, // optional, default is typeof default
  11. // serializable: true, // optional, default is true
  12. // visible: true, // optional, default is true
  13. // displayName: 'Foo', // optional
  14. // readonly: false, // optional, default is false
  15. // },
  16. // ...
  17. bombWhite:{
  18. default: null,
  19. type: cc.Prefab
  20. },
  21. crushEffect:{
  22. default: null,
  23. type: cc.Prefab
  24. },
  25. crushNumsEffect: {
  26. default: null,
  27. type: cc.Prefab
  28. },
  29. audioUtils:{
  30. type: AudioUtils,
  31. default: null
  32. },
  33. currentNums: {
  34. default: null,
  35. type: cc.Label
  36. },
  37. targetNum: {
  38. default: null,
  39. type: cc.Label
  40. },
  41. stepNums: {
  42. default: null,
  43. type: cc.Label
  44. }
  45. },
  46. // use this for initialization
  47. onLoad: function () {
  48. },
  49. playEffects: function(effectQueue, gameController = null){
  50. if(!effectQueue || effectQueue.length <= 0){
  51. return ;
  52. }
  53. let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放
  54. effectQueue.forEach(function(cmd){
  55. let delayTime = cc.delayTime(cmd.playTime);
  56. let callFunc = cc.callFunc(function(){
  57. let instantEffect = null;
  58. let animation = null;
  59. if(cmd.action == "crush"){
  60. instantEffect = cc.instantiate(this.crushEffect);
  61. animation = instantEffect.getComponent(cc.Animation);
  62. animation.play("effect");
  63. !soundMap["crush" + cmd.playTime] && this.audioUtils.playEliminate(cmd.step);
  64. soundMap["crush" + cmd.playTime] = true;
  65. }
  66. else if(cmd.action == "rowBomb"){
  67. instantEffect = cc.instantiate(this.bombWhite);
  68. animation = instantEffect.getComponent(cc.Animation);
  69. animation.play("effect_line");
  70. }
  71. else if(cmd.action == "colBomb"){
  72. instantEffect = cc.instantiate(this.bombWhite);
  73. animation = instantEffect.getComponent(cc.Animation);
  74. animation.play("effect_col");
  75. }else if(cmd.action == "crushNums"){
  76. instantEffect = cc.instantiate(this.crushNumsEffect);
  77. instantEffect.getComponent(cc.Label).string = `${cmd.nums * 10}`
  78. animation = instantEffect.getComponent(cc.Animation);
  79. animation.play("crushNums");
  80. // 分数统计
  81. let cnum = this.currentNums.string * 1
  82. let tnum = this.targetNum.string * 1
  83. let snum = this.stepNums.string * 1
  84. if(gameController.isStepPause){
  85. gameController.isStepPause = false
  86. gameController.showSkillTip(false)
  87. }else{
  88. snum -= 1
  89. }
  90. cnum += cmd.nums * 10
  91. this.currentNums.string = `${cnum}`
  92. this.stepNums.string = `${snum}`
  93. if(cnum > tnum){
  94. Toast('难度疯狂递增...', {duration: 3})
  95. this.targetNum.string = `${cnum * 1.5}`
  96. this.stepNums.string = '20'
  97. }else{
  98. if(snum <= 0){
  99. Toast(`挑战失败, 最高分${cnum}`, {duration: 3})
  100. this.currentNums.string = '0'
  101. this.stepNums.string = '20'
  102. this.targetNum.string = '1000'
  103. }
  104. }
  105. }
  106. instantEffect.x = CELL_WIDTH * (cmd.pos.x - 0.5);
  107. instantEffect.y = CELL_WIDTH * (cmd.pos.y - 0.5);
  108. instantEffect.parent = this.node;
  109. animation.on("finished",function(){
  110. instantEffect.destroy();
  111. },this);
  112. },this);
  113. this.node.runAction(cc.sequence(delayTime, callFunc));
  114. },this);
  115. },
  116. // called every frame, uncomment this function to activate update callback
  117. // update: function (dt) {
  118. // },
  119. });