GamePlay.ts 39 KB

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