EffectLayer.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. bombWhite:{
  8. default:null,
  9. type:cc.Prefab
  10. },
  11. crushEffect:{
  12. default: null,
  13. type: cc.Prefab
  14. },
  15. crushNumsEffect:{
  16. default:null,
  17. type:cc.Prefab
  18. },
  19. audioUtils:{
  20. default:null,
  21. type:AudioUtils
  22. },
  23. //当前分数
  24. currentNums:{
  25. default:null,
  26. type:cc.Label
  27. },
  28. //关卡目标分数
  29. // targetNum:{
  30. // default:null,
  31. // type:cc.Label
  32. // },
  33. //关卡目标1
  34. targetOneNum:{
  35. default:null,
  36. type:cc.Label
  37. },
  38. //关卡目标2
  39. targetTwoNum:{
  40. default:null,
  41. type:cc.Label
  42. },
  43. //关卡目标1
  44. targetThreeNum:{
  45. default:null,
  46. type:cc.Label
  47. },
  48. //步数
  49. surplusStepNums:{
  50. default:null,
  51. type:cc.Label
  52. },
  53. //关卡
  54. levelNum:{
  55. default:null,
  56. type:cc.Label
  57. },
  58. },
  59. // LIFE-CYCLE CALLBACKS:
  60. onLoad () {
  61. this.levelNum.string = 9; //关卡
  62. this.surplusStepNums.string = 20; //剩余步数
  63. // this.targetOneNum.string = 60;
  64. // this.targetTwoNum.string = 55;
  65. // this.targetThreeNum.string = 58;
  66. //当前的关卡数
  67. // let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
  68. this.curLevelNum = this.levelNum.string * 1 + 1;
  69. // curLevel.string = "第" + this.curLevelNum + "关";
  70. let sprite = cc.find("Canvas/TopResult/TargetArea")
  71. //关卡目标
  72. if (this.levelNum.string >= 8){
  73. let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  74. let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo");
  75. let targetThree = cc.find("Canvas/TopResult/TargetArea/Layout/TargetThree");
  76. targetOne.active = true;
  77. targetTwo.active = true;
  78. targetThree.active = true;
  79. targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  80. targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat;
  81. targetThree.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").fox;
  82. this.targetOneNum.string = 60;
  83. this.targetTwoNum.string = 55;
  84. this.targetThreeNum.string = 58;
  85. }else if (this.levelNum.string >= 5){
  86. let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  87. let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo");
  88. targetOne.active = true;
  89. targetTwo.active = true;
  90. targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  91. targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat;
  92. this.targetOneNum.string = 60;
  93. this.targetTwoNum.string = 55;
  94. }else {
  95. let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  96. targetOne.active = true;
  97. targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  98. this.targetOneNum.string = 60;
  99. }
  100. },
  101. playEffects(effectQueue,gameController = null){
  102. // console.log("特效的effectQueue:",effectQueue)
  103. if (!effectQueue || effectQueue.length <= 0){
  104. return;
  105. }
  106. let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放
  107. effectQueue.forEach(function (cmd) {
  108. // console.log("cmd:", cmd)
  109. let delayTime = cc.delayTime(cmd.playTime);
  110. let callFunc = cc.callFunc(function (){
  111. let instantEffect = null;
  112. let animation = null;
  113. // console.log("cmd的action:",cmd.action)
  114. if (cmd.action == "crush"){
  115. // console.log("常规消除")
  116. instantEffect = cc.instantiate(this.crushEffect);
  117. animation = instantEffect.getComponent(cc.Animation);
  118. animation.play("effect");
  119. !soundMap["crush" + cmd.playTime] && this.audioUtils.playEliminate(cmd.step);
  120. soundMap["crush" + cmd.playTime] = true;
  121. }else if (cmd.action == "rowBomb"){
  122. // console.log("正常消除了整行")
  123. instantEffect = cc.instantiate(this.bombWhite);
  124. animation = instantEffect.getComponent(cc.Animation);
  125. animation.play("effect_line");
  126. }else if (cmd.action == "colBomb"){
  127. // console.log("正常消除了整列")
  128. instantEffect = cc.instantiate(this.bombWhite);
  129. animation = instantEffect.getComponent(cc.Animation);
  130. animation.play("effect_col");
  131. }
  132. else if (cmd.action == "crushRow"){
  133. // console.log("道具消除整行")
  134. instantEffect = cc.instantiate(this.bombWhite);
  135. animation = instantEffect.getComponent(cc.Animation);
  136. animation.play("effect_line");
  137. // this.down()
  138. }else if (cmd.action == "crushCol"){
  139. // console.log("道具消除整列")
  140. instantEffect = cc.instantiate(this.bombWhite);
  141. animation = instantEffect.getComponent(cc.Animation);
  142. animation.play("effect_col");
  143. }
  144. else if (cmd.action == "typeBomb"){
  145. //道具消除一种类型
  146. instantEffect = cc.instantiate(this.crushEffect);
  147. animation = instantEffect.getComponent(cc.Animation);
  148. animation.play("effect");
  149. }
  150. else if (cmd.action == "crushNums"){
  151. instantEffect = cc.instantiate(this.crushNumsEffect);
  152. instantEffect.getComponent(cc.Label).string = `${cmd.nums * 10}`;
  153. animation = instantEffect.getComponent(cc.Animation);
  154. animation.play("crushNums");
  155. //分数统计
  156. let currentNum = this.currentNums.string * 1; //当前分数
  157. // let tnum = this.targetNum.string * 1;
  158. let stepNum = this.surplusStepNums.string * 1;
  159. let surplusStep = this.surplusStepNums.string * 1;
  160. if (gameController.isStepPause){
  161. //计步暂停
  162. gameController.isStepPause = false;
  163. gameController.showSkillTip(false);
  164. }else {
  165. //计步减1
  166. stepNum -= 1;
  167. }
  168. currentNum += cmd.nums * 10;
  169. this.currentNums.string = `${currentNum}`;
  170. this.surplusStepNums.string = `${stepNum}`;
  171. // if (cnum >= tnum){
  172. // // this.guan++;
  173. // this.levelNum.string++;
  174. // // Toast("难度疯狂递增...",{duration:3});
  175. // Toast(`第${this.levelNum.string-1}关已完成`,{duration:3});
  176. // this.targetNum.string = `${cnum + 2500}`;
  177. //
  178. // this.stepNums.string = "20";
  179. // }else {
  180. // if (snum <= 0){
  181. // Toast(`挑战失败,最高分${cnum}`,{duration:3})
  182. // this.currentNums.string = 0;
  183. // this.stepNums.string = 20;
  184. // this.targetNum.string = 1000;
  185. // }
  186. // }
  187. // console.log("cmd:",cmd)
  188. let targetOneNow = cmd.oneNums;
  189. let targetTwoNow = cmd.twoNums;
  190. let targetThreeNow = cmd.threeNums;
  191. // console.log("targetOneNow:",targetOneNow)
  192. this.targetOneNum.string -= targetOneNow;
  193. this.targetTwoNum.string -= targetTwoNow;
  194. this.targetThreeNum.string -= targetThreeNow;
  195. let targetOneNum = this.targetOneNum.string * 1;
  196. let targetTwoNum = this.targetTwoNum.string * 1;
  197. let targetThreeNum = this.targetThreeNum.string * 1;
  198. if (targetOneNum <= 0){
  199. this.targetOneNum.string = 0;
  200. }
  201. if (targetTwoNum <= 0){
  202. this.targetTwoNum.string = 0;
  203. }
  204. if (targetThreeNum <= 0){
  205. this.targetThreeNum.string = 0;
  206. }
  207. // console.log("剩余步数:",this.surplusStepNums.string)
  208. if (this.surplusStepNums.string * 1 >= 0 && targetOneNum <= 0 && targetTwoNum <= 0 && targetThreeNum <= 0){
  209. // Toast(`第${this.curLevelNum}关完成`, {duration:5})
  210. this.curLevelNum++;
  211. // this.targetOneNum.string = 0;
  212. // this.targetTwoNum.string = 0;
  213. // this.targetThreeNum.string = 0;
  214. // this.surplusStepNums.string = 20;
  215. let resultMask = cc.find("Canvas/Result")
  216. //展示关卡
  217. resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.curLevelNum}关完成`;
  218. //展示当前分数
  219. resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  220. //展示金币
  221. resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20;
  222. //展示星星
  223. resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20;
  224. // console.log("resultTitle",resultTitle)
  225. setTimeout(function (){
  226. resultMask.active = true;
  227. },500);
  228. this.targetOneNum.string = 60;
  229. this.targetTwoNum.string = 55;
  230. this.targetThreeNum.string = 58;
  231. this.surplusStepNums.string = 20;
  232. cc.find("Canvas/TopResult").active = false;
  233. }
  234. else if (this.surplusStepNums.string * 1 == 0 && (targetOneNum > 0 && targetTwoNum > 0 && targetThreeNum > 0)) {
  235. Toast("闯关失败!",{duration:6})
  236. let resultMask = cc.find("Canvas/Result")
  237. //展示关卡
  238. resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦";
  239. //展示当前分数
  240. resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  241. //展示金币
  242. resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0;
  243. //展示星星
  244. resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0;
  245. // console.log("resultTitle",resultTitle)
  246. setTimeout(function (){
  247. resultMask.active = true;
  248. let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom")
  249. zoom.active = false;
  250. },500);
  251. this.targetOneNum.string = 60;
  252. this.targetTwoNum.string = 55;
  253. this.targetThreeNum.string = 58;
  254. this.surplusStepNums.string = 20;
  255. }
  256. }
  257. instantEffect.x = CELL_WIDTH * (cmd.pos.x - 0.5);
  258. instantEffect.y = CELL_WIDTH * (cmd.pos.y - 0.5);
  259. instantEffect.parent = this.node;
  260. animation.on("finished",function (){
  261. instantEffect.destroy();
  262. },this);
  263. },this);
  264. this.node.runAction(cc.sequence(delayTime, callFunc));
  265. },this);
  266. },
  267. start () {
  268. // console.log("one:",this.targetOneNum.string)
  269. // console.log("two:",this.targetTwoNum.string)
  270. // console.log("three:",this.targetThreeNum.string)
  271. },
  272. update (dt) {
  273. let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
  274. // this.curLevelNum = this.levelNum.string * 1 + 1;
  275. curLevel.string = "第" + this.curLevelNum + "关";
  276. },
  277. });