GamePlay.ts 39 KB

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