GamePlay.ts 39 KB

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