GamePlay.ts 40 KB

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