GamePlay.ts 39 KB

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