GamePlay.ts 38 KB

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