GamePlay.ts 37 KB

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