EffectLayer.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. import {CELL_HEIGHT, CELL_WIDTH, GRID_HEIGHT, GRID_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. stepTotal : 0, //已使用的步数
  59. curLevelNum : 0, //当前关卡
  60. },
  61. // LIFE-CYCLE CALLBACKS:
  62. onLoad () {
  63. // console.log("this.node:",this.node)
  64. this.node.width = GRID_WIDTH * CELL_WIDTH;
  65. this.node.height = GRID_HEIGHT * CELL_HEIGHT;
  66. this.levelNum.string = 0; //关卡
  67. // this.surplusStepNums.string = 20; //剩余步数
  68. // console.log("当前关卡:",this.curLevelNum)
  69. // this.targetOneNum.string = 60;
  70. // this.targetTwoNum.string = 55;
  71. // this.targetThreeNum.string = 58;
  72. // this.progressBar = cc.find("Canvas/BloodProgress/bar").getComponent(cc.Sprite)
  73. // console.log("onload进度:",this.progressBar)
  74. //当前的关卡数
  75. // let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
  76. this.curLevelNum = this.levelNum.string * 1 + 1;
  77. // console.log("curLevelNum:",this.curLevelNum)
  78. // curLevel.string = "第" + this.curLevelNum + "关";
  79. //获取关卡类型的目标区域
  80. // let sprite = cc.find("Canvas/TopResult/TargetArea")
  81. //关卡目标
  82. // if (this.levelNum.string >= 8){
  83. // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  84. // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo");
  85. // let targetThree = cc.find("Canvas/TopResult/TargetArea/Layout/TargetThree");
  86. // targetOne.active = true;
  87. // targetTwo.active = true;
  88. // targetThree.active = true;
  89. //
  90. // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  91. // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat;
  92. // targetThree.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").fox;
  93. //
  94. // this.targetOneNum.string = 60;
  95. // this.targetTwoNum.string = 55;
  96. // this.targetThreeNum.string = 58;
  97. //
  98. // }else if (this.levelNum.string >= 5){
  99. // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  100. // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo");
  101. // targetOne.active = true;
  102. // targetTwo.active = true;
  103. // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  104. // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat;
  105. //
  106. // this.targetOneNum.string = 60;
  107. // this.targetTwoNum.string = 55;
  108. // }else {
  109. // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne");
  110. // targetOne.active = true;
  111. // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear;
  112. //
  113. // this.targetOneNum.string = 60;
  114. // }
  115. },
  116. playEffects(effectQueue,gameController = null){
  117. // console.log("特效的effectQueue:",effectQueue)
  118. if (!effectQueue || effectQueue.length <= 0){
  119. return;
  120. }
  121. let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放
  122. effectQueue.forEach(function (cmd) {
  123. // console.log("cmd:", cmd)
  124. let delayTime = cc.delayTime(cmd.playTime);
  125. let callFunc = cc.callFunc(function (){
  126. let instantEffect = null;
  127. let animation = null;
  128. // console.log("cmd的action:",cmd.action)
  129. if (cmd.action == "crush"){
  130. // console.log("常规消除")
  131. instantEffect = cc.instantiate(this.crushEffect);
  132. animation = instantEffect.getComponent(cc.Animation);
  133. animation.play("effect");
  134. !soundMap["crush" + cmd.playTime] && this.audioUtils.playEliminate(cmd.step);
  135. soundMap["crush" + cmd.playTime] = true;
  136. }else if (cmd.action == "rowBomb"){
  137. // console.log("正常消除了整行")
  138. instantEffect = cc.instantiate(this.bombWhite);
  139. animation = instantEffect.getComponent(cc.Animation);
  140. animation.play("effect_line");
  141. }else if (cmd.action == "colBomb"){
  142. // console.log("正常消除了整列")
  143. instantEffect = cc.instantiate(this.bombWhite);
  144. animation = instantEffect.getComponent(cc.Animation);
  145. animation.play("effect_col");
  146. }
  147. else if (cmd.action == "crushRow"){
  148. // console.log("道具消除整行")
  149. instantEffect = cc.instantiate(this.bombWhite);
  150. animation = instantEffect.getComponent(cc.Animation);
  151. animation.play("effect_line");
  152. // this.down()
  153. }else if (cmd.action == "crushCol"){
  154. // console.log("道具消除整列")
  155. instantEffect = cc.instantiate(this.bombWhite);
  156. animation = instantEffect.getComponent(cc.Animation);
  157. animation.play("effect_col");
  158. }
  159. else if (cmd.action == "typeBomb"){
  160. //道具消除一种类型
  161. instantEffect = cc.instantiate(this.crushEffect);
  162. animation = instantEffect.getComponent(cc.Animation);
  163. animation.play("effect");
  164. }
  165. else if (cmd.action == "crushNums"){
  166. //分数动画
  167. instantEffect = cc.instantiate(this.crushNumsEffect);
  168. instantEffect.getComponent(cc.Label).string = `${cmd.nums * 10}`;
  169. animation = instantEffect.getComponent(cc.Animation);
  170. animation.play("crushNums");
  171. //每完成一次,已使用的步数+1
  172. this.stepTotal += 1;
  173. //分数统计
  174. let currentNum = this.currentNums.string * 1; //当前分数
  175. // let tnum = this.targetNum.string * 1;
  176. let stepNum = this.surplusStepNums.string * 1;
  177. let surplusStep = this.surplusStepNums.string * 1;
  178. if (gameController.isStepPause){
  179. //计步暂停
  180. gameController.isStepPause = false;
  181. gameController.showSkillTip(false);
  182. }else {
  183. //计步减1
  184. stepNum -= 1;
  185. }
  186. currentNum += cmd.nums * 10;
  187. this.currentNums.string = `${currentNum}`;
  188. this.surplusStepNums.string = `${stepNum}`;
  189. //通关后闪现弹窗,时长3秒
  190. // if (cnum >= tnum){
  191. // // this.guan++;
  192. // this.levelNum.string++;
  193. // // Toast("难度疯狂递增...",{duration:3});
  194. // Toast(`第${this.levelNum.string-1}关已完成`,{duration:3});
  195. // this.targetNum.string = `${cnum + 2500}`;
  196. //
  197. // this.stepNums.string = "20";
  198. // }else {
  199. // if (snum <= 0){
  200. // Toast(`挑战失败,最高分${cnum}`,{duration:3})
  201. // this.currentNums.string = 0;
  202. // this.stepNums.string = 20;
  203. // this.targetNum.string = 1000;
  204. // }
  205. // }
  206. // console.log("cmd:",cmd)
  207. //分类通关目标
  208. // let targetOneNow = cmd.oneNums;
  209. // let targetTwoNow = cmd.twoNums;
  210. // let targetThreeNow = cmd.threeNums;
  211. // console.log("targetOneNow:",targetOneNow)
  212. // this.targetOneNum.string -= targetOneNow;
  213. // this.targetTwoNum.string -= targetTwoNow;
  214. // this.targetThreeNum.string -= targetThreeNow;
  215. // let targetOneNum = this.targetOneNum.string * 1;
  216. // let targetTwoNum = this.targetTwoNum.string * 1;
  217. // let targetThreeNum = this.targetThreeNum.string * 1;
  218. // if (targetOneNum <= 0){
  219. // this.targetOneNum.string = 0;
  220. // }
  221. // if (targetTwoNum <= 0){
  222. // this.targetTwoNum.string = 0;
  223. // }
  224. // if (targetThreeNum <= 0){
  225. // this.targetThreeNum.string = 0;
  226. // }
  227. // console.log("剩余步数:",this.surplusStepNums.string)
  228. //结果弹窗:类型消除
  229. // if (this.surplusStepNums.string * 1 >= 0 && targetOneNum <= 0 && targetTwoNum <= 0 && targetThreeNum <= 0){
  230. // // Toast(`第${this.curLevelNum}关完成`, {duration:5})
  231. // // this.targetOneNum.string = 0;
  232. // // this.targetTwoNum.string = 0;
  233. // // this.targetThreeNum.string = 0;
  234. // // this.surplusStepNums.string = 20;
  235. //
  236. // let resultMask = cc.find("Canvas/Result")
  237. // //展示关卡
  238. // resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.curLevelNum}关完成`;
  239. // //展示当前分数
  240. // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  241. // //展示金币
  242. // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20;
  243. // //展示星星
  244. // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20;
  245. //
  246. // // console.log("resultTitle",resultTitle)
  247. // setTimeout(function (){
  248. //
  249. // resultMask.active = true;
  250. //
  251. // },500);
  252. // this.curLevelNum++;
  253. // this.targetOneNum.string = 60;
  254. // this.targetTwoNum.string = 55;
  255. // this.targetThreeNum.string = 58;
  256. // this.surplusStepNums.string = 20;
  257. // cc.find("Canvas/TopResult").active = false;
  258. // }
  259. // else if (this.surplusStepNums.string * 1 == 0 && (targetOneNum > 0 && targetTwoNum > 0 && targetThreeNum > 0)) {
  260. // Toast("闯关失败!",{duration:6})
  261. //
  262. // let resultMask = cc.find("Canvas/Result")
  263. // //展示关卡
  264. // resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦";
  265. // //展示当前分数
  266. // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  267. // //展示金币
  268. // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0;
  269. // //展示星星
  270. // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0;
  271. //
  272. // // console.log("resultTitle",resultTitle)
  273. // setTimeout(function (){
  274. //
  275. // resultMask.active = true;
  276. // let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom")
  277. // zoom.active = false;
  278. //
  279. // },500);
  280. // this.targetOneNum.string = 60;
  281. // this.targetTwoNum.string = 55;
  282. // this.targetThreeNum.string = 58;
  283. // this.surplusStepNums.string = 20;
  284. // }
  285. //结果弹窗:boss进度条
  286. // if (this.surplusStepNums.string * 1 >= 0 && this.progressBarFillRange == 0){
  287. // //闯关成功
  288. // let resultMask = cc.find("Canvas/Result")
  289. // //展示关卡
  290. // resultMask.getChildByName("Title").getComponent(cc.Label).string = `第${this.curLevelNum}关完成`;
  291. // //展示当前分数
  292. // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  293. // //展示金币
  294. // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 20;
  295. // //展示星星
  296. // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 20;
  297. //
  298. // // console.log("resultTitle",resultTitle)
  299. // setTimeout(function (){
  300. //
  301. // resultMask.active = true;
  302. //
  303. // },500);
  304. // this.curLevelNum++;
  305. //
  306. // if (this.curLevelNum > 2){
  307. // this.surplusStepNums.string = 28;
  308. // }else {
  309. // this.surplusStepNums.string = 20;
  310. // }
  311. // // this.surplusStepNums.string = 20;
  312. // this.progressBarFillRange = 1;
  313. // this.currentNums.string = 0;
  314. //
  315. // cc.find("Canvas/TopResult").active = false;
  316. // cc.find("Canvas/BloodProgress").active = false;
  317. // }
  318. // else if (this.surplusStepNums.string * 1 == 0 && this.progressBarFillRange > 0) {
  319. // // Toast("闯关失败!",{duration:6})
  320. // //闯关失败
  321. // let resultMask = cc.find("Canvas/Result")
  322. // //展示关卡
  323. // resultMask.getChildByName("Title").getComponent(cc.Label).string = "差一点点就成功了哦";
  324. // //展示当前分数
  325. // resultMask.getChildByName("ScoreSum").getChildByName("ScoreDetail").getComponent(cc.Label).string = currentNum;
  326. // //展示金币
  327. // resultMask.getChildByName("Golden").getChildByName("GoldenDetail").getComponent(cc.Label).string = 0;
  328. // //展示星星
  329. // resultMask.getChildByName("Star").getChildByName("StarDetail").getComponent(cc.Label).string = 0;
  330. //
  331. // // console.log("resultTitle",resultTitle)
  332. // setTimeout(function (){
  333. //
  334. // resultMask.active = true;
  335. // //闯关失败,不展示去动物园按钮
  336. // let zoom = cc.find("Canvas/Result/BtnLayout/ToZoom")
  337. // zoom.active = false;
  338. //
  339. // },500);
  340. //
  341. // if (this.curLevelNum > 2){
  342. // this.surplusStepNums.string = 28;
  343. // }else {
  344. // this.surplusStepNums.string = 20;
  345. // }
  346. //
  347. // // this.surplusStepNums.string = 20;
  348. // this.progressBarFillRange = 1;
  349. // this.currentNums.string = 0;
  350. //
  351. // cc.find("Canvas/TopResult").active = false;
  352. // cc.find("Canvas/BloodProgress").active = false;
  353. // }
  354. }
  355. instantEffect.x = CELL_WIDTH * (cmd.pos.x - 0.5);
  356. instantEffect.y = CELL_WIDTH * (cmd.pos.y - 0.5);
  357. instantEffect.parent = this.node;
  358. animation.on("finished",function (){
  359. instantEffect.destroy();
  360. },this);
  361. },this);
  362. this.node.runAction(cc.sequence(delayTime, callFunc));
  363. },this);
  364. },
  365. start () {
  366. },
  367. update (dt) {
  368. //顶部当前关卡展示
  369. let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label)
  370. curLevel.string = "第" + this.curLevelNum + "关";
  371. },
  372. });