GamePlay.ts 38 KB

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