GamePlay.ts 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. import CellItem from "./view/uiItem/CellItem";
  2. import { PROPTYPE, CHECKDIR, SURPRISETASKTYPE } from "./data/Enum";
  3. import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
  4. import GameConst from "./data/GameConst";
  5. import GameLogic from "./util/GameLogic";
  6. import BonusTip from "./view/effect/BonusTip";
  7. import DataMgr from "./mgr/DataMgr";
  8. import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
  9. import GameMgr, { UI_NAME } from "./mgr/GameMgr";
  10. import { AUDIO_TYPE, EVENT_TYPE, GameProp } from "../game/data/GameData";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class GamePlay extends cc.Component {
  14. /**单例模式 */
  15. public static Inst: GamePlay = null;
  16. /**背景 */
  17. @property(cc.Node)
  18. node_bg: cc.Node = null;
  19. /**标题 */
  20. @property(cc.Node)
  21. node_top: cc.Node = null;
  22. @property(cc.Label)
  23. label_level: cc.Label = null;
  24. @property(cc.Node)
  25. node_redPacketIcon: cc.Node = null;
  26. @property({ type: cc.Node, displayName: "气泡红包1" })
  27. btn_gameGetRed1: cc.Node = null;
  28. @property({ type: cc.Node, displayName: "气泡红包2" })
  29. btn_gameGetRed2: cc.Node = null;
  30. @property({ type: cc.Node, displayName: "气泡红包3" })
  31. btn_gameGetRed3: cc.Node = null;
  32. @property({ type: cc.Node, displayName: "气泡红包3" })
  33. btn_gameGetRed4: cc.Node = null;
  34. /**内容 */
  35. @property(cc.Node)
  36. node_content: cc.Node = null;
  37. /**cell背景块 */
  38. @property(cc.Node)
  39. node_cellBg: cc.Node = null;
  40. /**暂停按钮 */
  41. @property(cc.Node)
  42. node_pauseBtn: cc.Node = null;
  43. /**进度条UI */
  44. @property(cc.Node)
  45. node_progressUI: cc.Node = null;
  46. @property(cc.Sprite)
  47. spr_progress: cc.Sprite = null;
  48. /**重置按钮 */
  49. @property(cc.Node)
  50. node_resetBtn: cc.Node = null;
  51. @property(cc.Label)
  52. label_resetPropNum: cc.Label = null;
  53. /**锤子按钮 */
  54. @property(cc.Node)
  55. node_hammerBtn: cc.Node = null;
  56. @property(cc.Label)
  57. label_hammerPropNum: cc.Label = null;
  58. /**变色按钮 */
  59. @property(cc.Node)
  60. node_changeBtn: cc.Node = null;
  61. @property(cc.Label)
  62. label_changePropNum: cc.Label = null;
  63. /**更改CellItemUI */
  64. @property(cc.Node)
  65. node_changeCellItemUI: cc.Node = null;
  66. /**特效UI */
  67. @property(cc.Node)
  68. node_effectUI: cc.Node = null;
  69. /**关卡红包UI */
  70. @property(cc.Node)
  71. node_levelRedPacketUI: cc.Node = null;
  72. /**点击检测遮罩 */
  73. @property(cc.Node)
  74. node_touchListenMask: cc.Node = null;
  75. /**当前进度得分 */
  76. public curProgressScore: number = 0;
  77. /**当前得分 */
  78. public curGetScore: number = 0;
  79. /**目标分数 */
  80. public targetScore: number = 100000;
  81. /**最终得分 */
  82. public finalGetScore: number = 0;
  83. /**增加得分速度 */
  84. public addScoreSpeed: number = 4;
  85. // /**道具类型 */
  86. // public curPropType: PROPTYPE = PROPTYPE.Null;
  87. /**消消的方块数组
  88. * @param:key index_x
  89. * @param: value 整个纵列数组
  90. */
  91. public cellItemDic: { [key: number]: CellItem[] } = {};
  92. public cellItemArr: CellItem[] = [];
  93. /**清理CellItem的Vec数组 */
  94. public cleanedVecArr: cc.Vec2[] = [];
  95. /**能够清理的vecArr组 */
  96. public couldCleanVecArr: cc.Vec2[] = [];
  97. /**清理纵列的x */
  98. public cleanXIndexArr: number[] = [];
  99. /**所有的清理 */
  100. public allCleanedXArr: number[] = [];
  101. /**剩余未移除的xIndex */
  102. public leftXIndexArr: number[] = [];
  103. /**当前选择的cellItem */
  104. public curSelectCellItem: CellItem = null;
  105. /**当前点击得cellItem */
  106. public curClickCellItem: CellItem = null;
  107. /**当前选择的道具按钮 */
  108. public curSelectPropBtn: cc.Node = null;
  109. /**是否可以点击 */
  110. public ifCouldClick: boolean = true;
  111. /**是否已经通关 */
  112. public ifPass: boolean = false;
  113. /**是否获取后台回调 */
  114. public ifGetPass: boolean = false;
  115. /**当前的道具类型 */
  116. private _curPropType: PROPTYPE;
  117. public get curPropType(): PROPTYPE {
  118. return this._curPropType;
  119. }
  120. public set curPropType(v: PROPTYPE) {
  121. //LogUtil.log("this.curSelectPropBtn", this.curSelectPropBtn);
  122. let ani = null;
  123. if (this.curSelectPropBtn) {
  124. mk.console.log("this.curSelectPropBtn", this.curSelectPropBtn);
  125. ani = this.curSelectPropBtn.children[1].getComponent(cc.Animation);
  126. }
  127. if (v == PROPTYPE.Null) {
  128. if (ani) {
  129. ani.play("ani_normalBtn");
  130. }
  131. this.setPropBtnNormalTip(this.curSelectPropBtn)
  132. }
  133. else {
  134. if (ani) {
  135. ani.play("ani_selectBtn");
  136. }
  137. this.setPropBtnSelectTip(this.curSelectPropBtn)
  138. }
  139. this._curPropType = v;
  140. }
  141. // LIFE-CYCLE CALLBACKS:
  142. onLoad() {
  143. GamePlay.Inst = this;
  144. mk.event.register("event_guide", this.clickGuide, this);
  145. }
  146. private clickGuide(data: string) {
  147. if (data == "1_2") {//点击即可消除哦!
  148. this.cellItemDic[0][1].onClick();
  149. }
  150. else if (data == "1_3") {//再点击一次增加大量进度哦
  151. this.cellItemDic[1][0].onClick();
  152. }
  153. }
  154. public start() {
  155. PoolMgr.Inst.initPoolPrefab();
  156. GameConst.loadConfig().then(() => {
  157. this.adapt();
  158. // AudioMgr.Inst.playMusic(AUDIO_CLIP_NAME.bg_game);
  159. mk.audio.playMusic("music_gameBg");
  160. this.initView();
  161. this.initEvent();
  162. this.intervalShowGuide();
  163. this.intervalShowInter();
  164. cc.tween(this.btn_gameGetRed1).delay(0.2).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  165. cc.tween(this.btn_gameGetRed2).delay(0.4).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  166. cc.tween(this.btn_gameGetRed3).delay(0.2).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  167. cc.tween(this.btn_gameGetRed4).delay(0.4).to(1, { y: 60 }, { easing: "" }).to(1, { y: 0 }, { easing: "" }).union().repeatForever().start();
  168. }).catch();
  169. this.qipaoShow();
  170. }
  171. onEnable() {
  172. mk.console.log("PROPTYPE[PROPTYPE.Change]", PROPTYPE.Change);
  173. GameMgr.Inst.sendEvent(UI_NAME.Game, "进入游戏界面");
  174. // this.initLevel();
  175. }
  176. onDisable() {
  177. //退出游戏归置下道具状态
  178. this.curPropType = PROPTYPE.Null;
  179. if (this.curSelectCellItem) {
  180. this.curSelectCellItem.normal();
  181. }
  182. if (this.node_changeCellItemUI.active = true) {
  183. this.node_changeCellItemUI.active = false;
  184. }
  185. //this.clearSurpriseTask();
  186. }
  187. adapt() {
  188. mk.console.log("进行适配!!!!!!!!!!!!!!!!");
  189. //背景适配
  190. this.node_bg.setContentSize(new cc.Size(cc.winSize.width, cc.winSize.height));
  191. // this.node_top.y = (cc.winSize.height - this.node_top.height) * 0.5 + 5;
  192. const world_pos = gData.gameData.gameStyle.node_top_ui.parent.convertToWorldSpaceAR(gData.gameData.gameStyle.node_top_ui.getPosition());
  193. const node_pos = this.node_top.parent.convertToNodeSpaceAR(world_pos);
  194. this.node_top.y = node_pos.y - 40;
  195. }
  196. update(dt) {
  197. if (this.curProgressScore >= this.curGetScore) {
  198. if (this.curProgressScore == 0) {
  199. this.spr_progress.fillRange = 0;
  200. }
  201. return;
  202. }
  203. else {
  204. if (this.curProgressScore >= this.targetScore) {
  205. this.curProgressScore = this.curGetScore;
  206. this.initScore();
  207. }
  208. else {
  209. let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
  210. if (this.curProgressScore < GamePlay.Inst.targetScore && nextProgressScore >= GamePlay.Inst.targetScore) {
  211. let node_getTargetScoreTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
  212. GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
  213. }
  214. this.curProgressScore = nextProgressScore;
  215. if (this.curProgressScore >= this.curGetScore) {
  216. this.curProgressScore = this.curGetScore;
  217. }
  218. this.initScore();
  219. }
  220. }
  221. }
  222. /**初始化视图 */
  223. initView() {
  224. this.initLevel();
  225. this.initTotalScore();
  226. this.initScore();
  227. this.initProgress();
  228. this.initHammerPropNum();
  229. this.setPropBtnNormalTip(this.node_hammerBtn);
  230. this.initResetPropNum();
  231. this.setPropBtnNormalTip(this.node_resetBtn);
  232. this.initChanegPropNum();
  233. this.setPropBtnNormalTip(this.node_changeBtn);
  234. this.initCellBg();
  235. this.initCell();
  236. }
  237. /**初始化事件 */
  238. initEvent() {
  239. this.node_pauseBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  240. this.node_resetBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  241. this.node_hammerBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  242. this.node_changeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  243. this.node_redPacketIcon.on(cc.Node.EventType.TOUCH_END, this.onClickRedPacketIcon, this);
  244. if (!GameConst.isAuth) {
  245. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  246. }
  247. }
  248. /**初始化关卡数目 */
  249. initLevel() {
  250. mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
  251. let level = gData.gameData.getProp(GameProp.levelNum);
  252. this.label_level.string = `第${level + 1}关`
  253. }
  254. /**初始化总分数 */
  255. initTotalScore() {
  256. let level = gData.gameData.getProp(GameProp.levelNum);
  257. //加入一些随机值,而不是都能获得过关红包
  258. this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
  259. // //测试切换
  260. // this.targetScore = 5000;
  261. this.addScoreSpeed = Math.floor(this.targetScore / 400) * 2 + 4;
  262. mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
  263. }
  264. /**初始化得分 */
  265. initScore() {
  266. this.initProgress();
  267. }
  268. /**初始化进度 */
  269. initProgress() {
  270. let progress = this.curProgressScore / this.targetScore;
  271. progress = progress > 1 ? 1 : progress;
  272. this.spr_progress.fillRange = progress;
  273. if (progress >= 1) {
  274. this.pass();
  275. mk.ui.openPanel("module/reward/rewardMission");
  276. }
  277. // LogUtil.log("progressprogressprogressprogressprogressprogress", progress);
  278. }
  279. /**初始化道具 */
  280. initPropNum() {
  281. this.initHammerPropNum();
  282. this.initResetPropNum();
  283. this.initChanegPropNum();
  284. }
  285. /**初始化锤子道具数目 */
  286. initHammerPropNum() {
  287. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  288. if (hammerPropNum) {
  289. this.label_hammerPropNum.string = hammerPropNum.toString();
  290. }
  291. else {
  292. this.label_hammerPropNum.string = "+";
  293. }
  294. }
  295. /**初始化重置道具数目 */
  296. initResetPropNum() {
  297. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  298. if (resetPropNum) {
  299. this.label_resetPropNum.string = resetPropNum.toString();
  300. }
  301. else {
  302. this.label_resetPropNum.string = "+";
  303. }
  304. }
  305. /**初始化替换道具数目 */
  306. initChanegPropNum() {
  307. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  308. if (changePropNum) {
  309. this.label_changePropNum.string = changePropNum.toString();
  310. }
  311. else {
  312. this.label_changePropNum.string = "+";
  313. }
  314. }
  315. // update (dt) {}
  316. /**初始化cellBg */
  317. initCellBg() {
  318. for (var i = 0; i < GameConst.col_num; i++) {
  319. for (var j = 0; j < GameConst.row_num; j++) {
  320. let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  321. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  322. let node_cellBg = cc.instantiate(prefab_cellBg);
  323. this.node_cellBg.addChild(node_cellBg);
  324. }
  325. }
  326. }
  327. /**初始化cell */
  328. public initCell() {
  329. this.addCellItemFuc = () => { this.addCellItem(); };
  330. this.schedule(this.addCellItemFuc, 0.05);
  331. }
  332. public addCellItemFuc: Function = null;
  333. public curXIndex: number = 0;
  334. public curYIndex: number = 7;
  335. /**添加CellItem */
  336. public addCellItem() {
  337. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  338. this.addColCellItem();
  339. this.curXIndex++;
  340. if (this.curXIndex >= GameConst.col_num) {
  341. this.unschedule(this.addCellItemFuc);
  342. this.getStartRedPacketCellItem();
  343. }
  344. }
  345. /**添加纵列的cellItem */
  346. public addColCellItem() {
  347. this.cellItemDic[this.curXIndex] = [];
  348. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  349. let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  350. let node_prefab = cc.instantiate(prefab_cellItem);
  351. let cellItem = node_prefab.getComponent(CellItem);
  352. cellItem.init(this.curXIndex, i);
  353. this.cellItemDic[this.curXIndex][i] = cellItem;
  354. this.cellItemArr.push(cellItem);
  355. this.node_content.addChild(node_prefab);
  356. }
  357. }
  358. /**点击按钮 */
  359. onClickBtn(event: cc.Event.EventTouch) {
  360. this.intervalShowGuide();
  361. this.intervalShowInter();
  362. //是否已经通关
  363. if (this.ifPass) {
  364. EffectMgr.Inst.addTip("通关结算啦,请稍后操作哈")
  365. return;
  366. }
  367. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  368. mk.audio.playEffect("button");
  369. switch (event.currentTarget) {
  370. case this.node_pauseBtn:
  371. this.onClickPauseBtn();
  372. break;
  373. case this.node_hammerBtn:
  374. this.onClickHammerBtn();
  375. break;
  376. case this.node_changeBtn:
  377. this.onClickChangeBtn();
  378. break;
  379. case this.node_resetBtn:
  380. this.onClickResetBtn();
  381. break;
  382. }
  383. }
  384. /**点击暂停按钮 */
  385. onClickPauseBtn() {
  386. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击暂停按钮");
  387. mk.ui.openPanel("game/prefab/uiPanel/PauseUI")
  388. }
  389. /**点击重置按钮 */
  390. onClickResetBtn() {
  391. //this.intervalShowGuide();
  392. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击重置道具按钮");
  393. //设置当前选择的道具按钮
  394. this.setCurSelectPropBtn(this.node_resetBtn);
  395. this.curPropType = PROPTYPE.Reset;
  396. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  397. if (!resetPropNum || resetPropNum <= 0) {
  398. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  399. return;
  400. }
  401. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.refresh);
  402. mk.audio.playEffect("ef_refresh");
  403. let keys = Object.keys(this.cellItemDic);
  404. for (var i = 0; i < keys.length; i++) {
  405. let key = Number(keys[i]);
  406. let colCellItemArr = this.cellItemDic[key];
  407. for (var j = 0; j < colCellItemArr.length; j++) {
  408. let cellItem = colCellItemArr[j];
  409. if (cellItem) {
  410. cellItem.reset();
  411. }
  412. }
  413. }
  414. //暂时不扣
  415. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  416. this.curPropType = PROPTYPE.Null;
  417. //this.recycleAllCellItem();
  418. }
  419. //点击锤子按钮
  420. onClickHammerBtn() {
  421. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击消除锤道具按钮");
  422. //this.intervalShowGuide();
  423. //设置当前选择的道具按钮
  424. this.setCurSelectPropBtn(this.node_hammerBtn);
  425. this.curPropType = PROPTYPE.Hammer;
  426. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  427. if (!hammerPropNum || hammerPropNum <= 0) {
  428. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  429. return;
  430. }
  431. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  432. }
  433. //点击更换按钮
  434. onClickChangeBtn() {
  435. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击变化方块按钮");
  436. //this.intervalShowGuide();
  437. //设置当前选择的道具按钮
  438. this.setCurSelectPropBtn(this.node_changeBtn);
  439. this.curPropType = PROPTYPE.Change;
  440. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  441. if (!changePropNum || changePropNum <= 0) {
  442. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  443. return;
  444. }
  445. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  446. }
  447. /**更改cellItem类型
  448. * @param cellItemType
  449. */
  450. changeCellItemType(cellItemType: number) {
  451. let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
  452. let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
  453. let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
  454. node_change.setPosition(pos_x, pos_y);
  455. GamePlay.Inst.node_effectUI.addChild(node_change);
  456. this.curSelectCellItem.setType(cellItemType)
  457. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.change);
  458. mk.audio.playEffect("ef_change");
  459. this.curSelectCellItem = null;
  460. }
  461. /**设置当前 */
  462. setCurSelectPropBtn(propBtn: cc.Node) {
  463. if (this.curSelectPropBtn) {
  464. let node_ani = this.curSelectPropBtn.children[1];
  465. if (node_ani) {
  466. let ani = node_ani.getComponent(cc.Animation);
  467. if (ani) {
  468. ani.play("ani_normalBtn");
  469. }
  470. }
  471. this.setPropBtnNormalTip(this.curSelectPropBtn);
  472. }
  473. this.curSelectPropBtn = propBtn;
  474. }
  475. /**设置道具普通提示 */
  476. setPropBtnNormalTip(propBtn: cc.Node) {
  477. if (!propBtn) {
  478. return;
  479. }
  480. let node_tip = propBtn.children[2];
  481. if (node_tip) {
  482. let label = null;
  483. switch (propBtn) {
  484. case this.node_hammerBtn:
  485. label = this.label_hammerPropNum;
  486. break;
  487. case this.node_resetBtn:
  488. label = this.label_resetPropNum;
  489. break;
  490. case this.node_changeBtn:
  491. label = this.label_changePropNum;
  492. break;
  493. }
  494. let str = label.string;
  495. let num = Number(str);
  496. let label_tip = node_tip.getComponent(cc.Label);
  497. mk.console.log("propBtn.name", propBtn.name);
  498. mk.console.log("num", num);
  499. if (num && num >= 1) {
  500. label_tip.string = "";
  501. }
  502. else {
  503. label_tip.string = "点我领取";
  504. }
  505. }
  506. }
  507. /**设置道具使用提示 */
  508. setPropBtnSelectTip(propBtn: cc.Node) {
  509. if (!propBtn) {
  510. return;
  511. }
  512. let node_tip = propBtn.children[2];
  513. if (node_tip) {
  514. let label = node_tip.getComponent(cc.Label)
  515. label.string = "道具使用中";
  516. }
  517. }
  518. /**显示CellItemUI */
  519. showChangeCellItemUI() {
  520. let cruSelectCellItem = this.curSelectCellItem;
  521. GamePlay.Inst.node_changeCellItemUI.active = true;
  522. // let min_x = -this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  523. // let max_x = this.node_content.width * 0.5 + this.node_changeCellItemUI.width * 0.5;
  524. GamePlay.Inst.node_changeCellItemUI.y = cruSelectCellItem.node.y + cruSelectCellItem.node.height * 0.5 + GamePlay.Inst.node_changeCellItemUI.height * 0.5 + 20;
  525. }
  526. //onClick
  527. onClickRedPacketIcon() {
  528. if (this.spr_progress.fillRange == 1) {
  529. EffectMgr.Inst.addTip("已达成目标啦,过关发放哦");
  530. }
  531. else {
  532. EffectMgr.Inst.addTip("达到目标分数,才能领取哦");
  533. }
  534. }
  535. //找到红包的那个水果
  536. /**
  537. * 获取红包cellItem
  538. */
  539. public getStartRedPacketCellItem() {
  540. let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
  541. let largeCellItemVec: cc.Vec2[] = [];
  542. for (var i = 0; i < totalCellItemArr.length; i++) {
  543. let cellItem = totalCellItemArr[i];
  544. if (!!cellItem) {
  545. GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
  546. // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
  547. console.log("largeCellItemVec.length", largeCellItemVec.length)
  548. if (largeCellItemVec.length < this.couldCleanVecArr.length) {
  549. largeCellItemVec = this.couldCleanVecArr;
  550. }
  551. this.couldCleanVecArr.forEach(element => {
  552. let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
  553. totalCellItemArr[index] = null;
  554. this.cellItemDic[element.x][element.y].ifRemoved = false;
  555. });
  556. this.couldCleanVecArr = [];
  557. }
  558. }
  559. console.log("FC------------------------------------------------------------");
  560. let random_index = mk.math.random(0, largeCellItemVec.length - 1);
  561. let vec = largeCellItemVec[random_index];
  562. let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
  563. redPcaketCellItem.showRedPacket();
  564. return redPcaketCellItem;
  565. }
  566. //自定义事件---------------------------------------------------------------------
  567. /**微信授权返回 */
  568. onWxAuthBack() {
  569. if (this.node.active) {
  570. this.restart(false);
  571. //
  572. let node_redPacketUI = mk.ui.getCurOnPanel("RedPacketUI")
  573. if (node_redPacketUI) {
  574. mk.ui.closePanel("RedPacketUI");
  575. }
  576. }
  577. this.initLevel();
  578. this.initTotalScore();
  579. this.initPropNum();
  580. mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  581. }
  582. //其他显示或逻辑项-------------------------------------------------------------------
  583. /**根据vecList清除cellItem */
  584. public cleanCellItemByVecList() {
  585. //LogUtil.log("[Game] Game.Inst.cleanCellItemVecArr", Game.Inst.cleanCellItemVecArr);
  586. //没有可清清除
  587. if (GamePlay.Inst.cleanedVecArr.length <= 0) {
  588. //FC:+ 是否可以点击
  589. this.ifCouldClick = true;
  590. EffectMgr.Inst.addTip("点击两个或以上消除哦");
  591. return;
  592. }
  593. //区分消除音效
  594. if (GamePlay.Inst.cleanedVecArr.length >= 4) {
  595. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate_bonus);
  596. mk.audio.playEffect("ef_eliminate_bonus");
  597. }
  598. else {
  599. //AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.eliminate);
  600. mk.audio.playEffect("ef_eliminate");
  601. }
  602. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.fly);
  603. mk.audio.playEffect("ef_fly");
  604. //同时消除
  605. for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
  606. let vec = GamePlay.Inst.cleanedVecArr[i];
  607. //最后一个判定
  608. if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
  609. this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
  610. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
  611. }
  612. else {
  613. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
  614. }
  615. //回收 注释 改成如上
  616. //Game.Inst.cellItemDic[vec.x][vec.y].recycle();
  617. //Game.Inst.cellItemDic[vec.x][vec.y] = null;
  618. if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
  619. this.cleanXIndexArr.push(vec.x);
  620. }
  621. }
  622. this.cleanXIndexArr.sort();
  623. //计算下全部移除的
  624. this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
  625. //FC:移除完,检测下落
  626. this.scheduleOnce(() => {
  627. //检测下落
  628. this.checkMoveDownCellItem();
  629. }, 0.2)
  630. }
  631. /**检测向下移动的cellItem */
  632. checkMoveDownCellItem() {
  633. mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
  634. for (var i = 0; i < this.cleanXIndexArr.length; i++) {
  635. let xIndex = this.cleanXIndexArr[i];
  636. this.moveYCellItem(xIndex);
  637. }
  638. }
  639. /**移动
  640. * @param xIndex 移除的纵列
  641. * @param removedYIndex 移除的横向index
  642. */
  643. public moveYCellItem(xIndex: number) {
  644. // LogUtil.log("moveYCellItem x", xIndex, this.allCleanedXArr);
  645. /**移动的次序(第几个移动的用来控制延迟移动的时间) */
  646. let movedIndex: number = 0;
  647. //移动位置间隔(比如前面两个空位就移动两格)
  648. let intervalNum: number = 0;
  649. /**是否是全部清理的x */
  650. let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
  651. /**是否是最后清理的x(全部清理完才开始左移) */
  652. let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
  653. let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
  654. //计算y方向移动的最后一位(这样只计算一次不用循环)
  655. let lastMoveCellItemY: number = null;
  656. let leftLastCellItemY: number = null;
  657. if (ifLastCleanX) {
  658. let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
  659. lastMoveCellItemY = lastCellItemArrSort[0].y;
  660. // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
  661. for (var i = 0; i < GameConst.row_num; i++) {
  662. if (cellItemDic) {
  663. let cellItem = cellItemDic[i];
  664. if (cellItem) {
  665. leftLastCellItemY = cellItem.y;
  666. // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
  667. break;
  668. }
  669. }
  670. }
  671. // let leftCellItemArrSort = this.cl
  672. }
  673. //如果最后一行 并且 是被全部清除的x
  674. if (ifLastCleanX && ifAllCleanedX) {
  675. // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
  676. this.checkMoveLeftCellItem();
  677. return;
  678. }
  679. //y方向从下至上循环排查
  680. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  681. if (cellItemDic) {
  682. let cellItem = cellItemDic[i];
  683. //该xIndex纵列没有全部移除
  684. if (cellItem) {
  685. if (ifLastCleanX && i == leftLastCellItemY) {
  686. // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
  687. cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
  688. }
  689. else {
  690. cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
  691. }
  692. movedIndex++;
  693. }
  694. else {
  695. intervalNum += 1;
  696. }
  697. }
  698. else {
  699. continue;
  700. }
  701. }
  702. }
  703. /**检测向左移动的cellItem */
  704. checkMoveLeftCellItem() {
  705. //计算消除的纵列中,有没有被全部移除
  706. //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
  707. // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
  708. //如果没有全部移除得就return
  709. if (this.allCleanedXArr.length <= 0) {
  710. //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
  711. GamePlay.Inst.ifCouldClick = true;
  712. GamePlay.Inst.checkIfEliminate();
  713. return;
  714. }
  715. //剩余一列未移除的xIndex
  716. let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
  717. let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
  718. if (leftXIndexArr.length <= 0) {
  719. //检测是否移除
  720. this.checkIfEliminate();
  721. }
  722. else {
  723. mk.console.log("leftXIndexArr", leftXIndexArr);
  724. let intervalNum: number = 0;
  725. for (var i = 0; i < GameConst.col_num; i++) {
  726. let cellItemArr = GamePlay.Inst.cellItemDic[i];
  727. if (this.allCleanedXArr.indexOf(i) == -1) {
  728. //剩余存在的cellItem
  729. let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
  730. if (intervalNum > 0) {
  731. for (var j = 0; j < cellItemArr.length; j++) {
  732. let cellItem = cellItemArr[j];
  733. if (cellItem) {
  734. if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
  735. mk.console.log("i,j,intervalNum", i, j, intervalNum);
  736. cellItem.moveLeft(i - intervalNum, j, true);
  737. }
  738. else {
  739. cellItem.moveLeft(i - intervalNum, j);
  740. }
  741. }
  742. }
  743. }
  744. else {
  745. //对应 1 2 3 列 中 3全部消除
  746. if (i == leftMaxXIndex) {
  747. GamePlay.Inst.ifCouldClick = true;
  748. GamePlay.Inst.checkIfEliminate();
  749. }
  750. }
  751. }
  752. else {
  753. intervalNum += 1;
  754. }
  755. }
  756. }
  757. }
  758. public timeout_pass: number = 0;
  759. /**检测是否能移除 */
  760. checkIfEliminate() {
  761. mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
  762. //FC:测试替换
  763. GameLogic.getCouldCleanVec();
  764. if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  765. this.ifPass = true;
  766. EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
  767. let timeOut = setTimeout(() => {
  768. this.pass();
  769. clearTimeout(timeOut);
  770. }, 1500);
  771. }
  772. //FC:正式使用
  773. // let timeOut = setTimeout(() => {
  774. // GameUtil.getCouldCleanVec();
  775. // if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  776. // this.pass();
  777. // }
  778. // clearTimeout(timeOut);
  779. // }, 1500);
  780. }
  781. getCouldCleanCellItem() {
  782. for (var i = 0; this.cellItemArr.length; i++) {
  783. let cellItem = this.cellItemArr[i];
  784. let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
  785. if (aroundSameType.length > 0) {
  786. return;
  787. }
  788. }
  789. //this.nextLevel();
  790. this.pass();
  791. //this.recycleAllCellItem();
  792. }
  793. /**restart
  794. * @param 是否扣除体力
  795. */
  796. restart(ifMinusEnergy: boolean = false) {
  797. mk.console.log("restart!!!!!!!!!!!!!!!")
  798. this.refreshGame();
  799. }
  800. /**下一关 */
  801. nextLevel(ifMinusEnergy: boolean = false) {
  802. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  803. this.refreshGame();
  804. }
  805. /**刷新关卡 */
  806. refreshGame() {
  807. this.recycleAllCellItem();
  808. this.ifPass = false;
  809. this.ifGetPass = false;
  810. this.ifCouldClick = true;
  811. this.initLevel();
  812. this.initTotalScore();
  813. this.curProgressScore = 0;
  814. this.curGetScore = 0;
  815. this.finalGetScore = 0;
  816. this.initScore();
  817. }
  818. /**回收所有的 */
  819. recycleAllCellItem() {
  820. for (var i = 0; i < GameConst.col_num; i++) {
  821. for (var j = 0; j < GameConst.row_num; j++) {
  822. let cellItem = this.cellItemDic[i][j];
  823. if (cellItem) {
  824. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  825. cellItem.recycle(true, false, false);
  826. }
  827. }
  828. }
  829. // while (this.cellItemList.length > 0) {
  830. // this.cellItemList.splice(0, 1);
  831. // this.cellItemList[0].recycle();
  832. // }
  833. this.cellItemArr = [];
  834. this.cellItemDic = {};
  835. this.curXIndex = 0;
  836. this.curYIndex = GameConst.row_num - 1;
  837. this.initCell();
  838. }
  839. /**通关 */
  840. pass() {
  841. //这边会多次进入
  842. if (GamePlay.Inst.node.active == false || this.ifPass) {
  843. return;
  844. }
  845. this.ifPass = true;
  846. GamePlay.Inst.ifGetPass = false;
  847. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  848. mk.console.log("[Game]pass passLevelNum", levelNum);
  849. GamePlay.Inst.ifGetPass = true;
  850. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  851. //游戏结算
  852. this.gameCount();
  853. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  854. }
  855. /**游戏结算 */
  856. gameCount() {
  857. let node_getPropUI = mk.ui.getCurOnPanel("GetPropUI");
  858. if (node_getPropUI) {
  859. mk.ui.closePanel("GetPropUI");
  860. }
  861. let node_rewardLcuk = mk.ui.getCurOnPanel("rewardLuck")
  862. if (node_rewardLcuk) {
  863. mk.ui.closePanel("rewardLuck")
  864. }
  865. this.gameOver();
  866. }
  867. /**游戏结束 */
  868. gameOver() {
  869. mk.ui.openPanel("module/reward/rewardMission");
  870. }
  871. checkBonusNum(cleanCellItemNum: number) {
  872. if (cleanCellItemNum >= 4) {
  873. let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  874. let bonusTip = node_bonusTip.getComponent(BonusTip);
  875. //LogUtil.log("bonusTip",bonusTip);
  876. if (cleanCellItemNum == 4) {
  877. bonusTip.init(4);
  878. mk.audio.playEffect("ef_bonus4");
  879. }
  880. else if (cleanCellItemNum == 5) {
  881. bonusTip.init(5);
  882. mk.audio.playEffect("ef_bonus5");
  883. }
  884. else if (cleanCellItemNum == 6) {
  885. bonusTip.init(6);
  886. mk.audio.playEffect("ef_bonus6");
  887. }
  888. else if (cleanCellItemNum == 7) {
  889. bonusTip.init(7);
  890. mk.audio.playEffect("ef_bonus7");
  891. }
  892. else if (cleanCellItemNum == 8) {
  893. bonusTip.init(8);
  894. mk.audio.playEffect("ef_bonus8");
  895. }
  896. else {
  897. bonusTip.init(8);
  898. mk.audio.playEffect("ef_bonus8");
  899. }
  900. this.node_effectUI.addChild(node_bonusTip);
  901. }
  902. }
  903. checkAddLevelRedPacket(eliminateNum: number): boolean {
  904. let chance = (eliminateNum - 3) * 0.2;
  905. let random = Math.random();
  906. if (random < chance) {
  907. return true;
  908. }
  909. else {
  910. return false;
  911. }
  912. }
  913. public interval_ShowGuide: number = null;
  914. //间隔显示
  915. intervalShowGuide() {
  916. this.cancelShowCouldCleanCellItem();
  917. this.interval_ShowGuide = setInterval(() => {
  918. this.showCouldCleanCellItem();
  919. }, 10000);
  920. }
  921. /**显示 */
  922. showCouldCleanCellItem() {
  923. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  924. return;
  925. }
  926. if (this.couldCleanVecArr.length <= 0) {
  927. GameLogic.getCouldCleanVec();
  928. }
  929. if (this.couldCleanVecArr.length > 0) {
  930. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  931. let vec = this.couldCleanVecArr[i];
  932. if (this.cellItemDic[vec.x]) {
  933. let cellItem = this.cellItemDic[vec.x][vec.y];
  934. if (cellItem) {
  935. cellItem.shake();
  936. }
  937. }
  938. else {
  939. }
  940. }
  941. }
  942. }
  943. /**取消显示 */
  944. cancelShowCouldCleanCellItem() {
  945. if (this.interval_ShowGuide) {
  946. clearInterval(this.interval_ShowGuide);
  947. this.interval_ShowGuide = null;
  948. if (this.couldCleanVecArr.length > 0) {
  949. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  950. let vec = this.couldCleanVecArr[i];
  951. let cellItem = this.cellItemDic[vec.x][vec.y];
  952. if (cellItem) {
  953. cellItem.normal();
  954. }
  955. }
  956. }
  957. this.couldCleanVecArr = [];
  958. }
  959. }
  960. public interval_ShowInter: number = null;
  961. //间隔显示
  962. intervalShowInter() {
  963. this.cancelShowInter();
  964. this.interval_ShowGuide = setInterval(() => {
  965. mk.ad.showInterAd(0);
  966. }, 15000);
  967. }
  968. cancelShowInter() {
  969. if (this.interval_ShowGuide) {
  970. clearInterval(this.interval_ShowGuide);
  971. }
  972. }
  973. /**
  974. * 气泡红包是否开启
  975. */
  976. private qipaoShow() {
  977. for (let i = 0; i < 4; i++) {
  978. this['btn_gameGetRed' + (i + 1)].active = gData.gameData.funBtns.btn8.active;
  979. }
  980. }
  981. }