GamePlay.ts 38 KB

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