GamePlay.ts 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. import CellItem from "./view/uiItem/CellItem";
  2. import { PROPTYPE, CHECKDIR, SURPRISETASKTYPE } from "./data/Enum";
  3. import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
  4. import GameConst from "./data/GameConst";
  5. import GameLogic from "./util/GameLogic";
  6. import BonusTip from "./view/effect/BonusTip";
  7. import DataMgr from "./mgr/DataMgr";
  8. import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
  9. import GameMgr, { UI_NAME } from "./mgr/GameMgr";
  10. import { AUDIO_TYPE, DataEventId, EVENT_TYPE, GameProp, VideoAdType } from "../game/data/GameData";
  11. import JsbSystem from "../mk/system/JsbSystem";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class GamePlay extends cc.Component {
  15. /**单例模式 */
  16. public static Inst: GamePlay = null;
  17. /**背景 */
  18. @property(cc.Node)
  19. node_bg: cc.Node = null;
  20. /**标题 */
  21. @property(cc.Node)
  22. node_top: cc.Node = null;
  23. @property(cc.Label)
  24. label_level: cc.Label = null;
  25. @property(cc.Node)
  26. node_redPacketIcon: cc.Node = null;
  27. @property({ type: cc.Node, displayName: "气泡红包1" })
  28. btn_gameGetRed1: cc.Node = null;
  29. @property({ type: cc.Node, displayName: "气泡红包2" })
  30. btn_gameGetRed2: cc.Node = null;
  31. @property({ type: cc.Node, displayName: "气泡红包3" })
  32. btn_gameGetRed3: cc.Node = null;
  33. @property({ type: cc.Node, displayName: "气泡红包3" })
  34. btn_gameGetRed4: cc.Node = null;
  35. /**内容 */
  36. @property(cc.Node)
  37. node_content: cc.Node = null;
  38. /**cell背景块 */
  39. @property(cc.Node)
  40. node_cellBg: cc.Node = null;
  41. /**暂停按钮 */
  42. @property(cc.Node)
  43. node_pauseBtn: cc.Node = null;
  44. /**进度条UI */
  45. @property(cc.Node)
  46. node_progressUI: cc.Node = null;
  47. @property(cc.Sprite)
  48. spr_progress: cc.Sprite = null;
  49. /**重置按钮 */
  50. @property(cc.Node)
  51. node_resetBtn: cc.Node = null;
  52. @property(cc.Label)
  53. label_resetPropNum: cc.Label = null;
  54. /**锤子按钮 */
  55. @property(cc.Node)
  56. node_hammerBtn: cc.Node = null;
  57. @property(cc.Label)
  58. label_hammerPropNum: cc.Label = null;
  59. /**变色按钮 */
  60. @property(cc.Node)
  61. node_changeBtn: cc.Node = null;
  62. @property(cc.Label)
  63. label_changePropNum: cc.Label = null;
  64. /**更改CellItemUI */
  65. @property(cc.Node)
  66. node_changeCellItemUI: cc.Node = null;
  67. /**特效UI */
  68. @property(cc.Node)
  69. node_effectUI: cc.Node = null;
  70. /**关卡红包UI */
  71. @property(cc.Node)
  72. node_levelRedPacketUI: cc.Node = null;
  73. /**点击检测遮罩 */
  74. @property(cc.Node)
  75. node_touchListenMask: cc.Node = null;
  76. /**当前进度得分 */
  77. public curProgressScore: number = 0;
  78. /**当前得分 */
  79. public curGetScore: number = 0;
  80. /**目标分数 */
  81. public targetScore: number = 100000;
  82. /**最终得分 */
  83. public finalGetScore: number = 0;
  84. /**增加得分速度 */
  85. public addScoreSpeed: number = 4;
  86. // /**道具类型 */
  87. // public curPropType: PROPTYPE = PROPTYPE.Null;
  88. /**消消的方块数组
  89. * @param:key index_x
  90. * @param: value 整个纵列数组
  91. */
  92. public cellItemDic: { [key: number]: CellItem[] } = {};
  93. public cellItemArr: CellItem[] = [];
  94. /**清理CellItem的Vec数组 */
  95. public cleanedVecArr: cc.Vec2[] = [];
  96. /**能够清理的vecArr组 */
  97. public couldCleanVecArr: cc.Vec2[] = [];
  98. /**清理纵列的x */
  99. public cleanXIndexArr: number[] = [];
  100. /**所有的清理 */
  101. public allCleanedXArr: number[] = [];
  102. /**剩余未移除的xIndex */
  103. public leftXIndexArr: number[] = [];
  104. /**当前选择的cellItem */
  105. public curSelectCellItem: CellItem = null;
  106. /**当前点击得cellItem */
  107. public curClickCellItem: CellItem = null;
  108. /**当前选择的道具按钮 */
  109. public curSelectPropBtn: cc.Node = null;
  110. /**是否可以点击 */
  111. public ifCouldClick: boolean = true;
  112. /**是否已经通关 */
  113. public ifPass: boolean = false;
  114. /**是否获取后台回调 */
  115. public ifGetPass: boolean = false;
  116. /**是否打开积分红包 */
  117. public ifOpenScoreRedPacket: boolean = false;
  118. /**当前的道具类型 */
  119. private _curPropType: PROPTYPE;
  120. public get curPropType(): PROPTYPE {
  121. return this._curPropType;
  122. }
  123. public set curPropType(v: PROPTYPE) {
  124. //LogUtil.log("this.curSelectPropBtn", this.curSelectPropBtn);
  125. let ani = null;
  126. if (this.curSelectPropBtn) {
  127. mk.console.log("this.curSelectPropBtn", this.curSelectPropBtn);
  128. ani = this.curSelectPropBtn.children[1].getComponent(cc.Animation);
  129. }
  130. if (v == PROPTYPE.Null) {
  131. if (ani) {
  132. ani.play("ani_normalBtn");
  133. }
  134. this.setPropBtnNormalTip(this.curSelectPropBtn)
  135. }
  136. else {
  137. if (ani) {
  138. ani.play("ani_selectBtn");
  139. }
  140. this.setPropBtnSelectTip(this.curSelectPropBtn)
  141. }
  142. this._curPropType = v;
  143. }
  144. // LIFE-CYCLE CALLBACKS:
  145. onLoad() {
  146. GamePlay.Inst = this;
  147. mk.event.register("event_guide", this.clickGuide, this);
  148. }
  149. private clickGuide(data: string) {
  150. if (data == "1_3") {//点击即可消除哦!
  151. this.cellItemDic[0][0] && this.cellItemDic[0][0].onClick();
  152. }
  153. else if (data == "1_5") {//再点击一次增加大量进度哦
  154. this.cellItemDic[1][1] && this.cellItemDic[1][1].onClick();
  155. }
  156. }
  157. public start() {
  158. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  159. PoolMgr.Inst.initPoolPrefab();
  160. GameConst.loadConfig().then(() => {
  161. this.adapt();
  162. // AudioMgr.Inst.playMusic(AUDIO_CLIP_NAME.bg_game);
  163. mk.audio.playMusic("music_gameBg");
  164. //读取在线分数数据
  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. GameMgr.Inst.sendEvent(UI_NAME.Game, "进入游戏界面");
  184. // this.initLevel();
  185. }
  186. onDisable() {
  187. //退出游戏归置下道具状态
  188. this.curPropType = PROPTYPE.Null;
  189. if (this.curSelectCellItem) {
  190. this.curSelectCellItem.normal();
  191. }
  192. if (this.node_changeCellItemUI.active = true) {
  193. this.node_changeCellItemUI.active = false;
  194. }
  195. //this.clearSurpriseTask();
  196. }
  197. adapt() {
  198. mk.console.log("进行适配!!!!!!!!!!!!!!!!");
  199. //背景适配
  200. this.node_bg.setContentSize(new cc.Size(cc.winSize.width, cc.winSize.height));
  201. // this.node_top.y = (cc.winSize.height - this.node_top.height) * 0.5 + 5;
  202. const world_pos = gData.gameData.gameStyle.node_top_ui.parent.convertToWorldSpaceAR(gData.gameData.gameStyle.node_top_ui.getPosition());
  203. const node_pos = this.node_top.parent.convertToNodeSpaceAR(world_pos);
  204. this.node_top.y = node_pos.y - 40;
  205. }
  206. update(dt) {
  207. if (this.curProgressScore >= this.curGetScore) {
  208. if (this.curProgressScore == 0) {
  209. this.spr_progress.fillRange = 0;
  210. }
  211. return;
  212. }
  213. else {
  214. if (this.curProgressScore >= this.targetScore) {
  215. this.curProgressScore = this.curGetScore;
  216. this.initScore();
  217. }
  218. else {
  219. let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
  220. if (this.curProgressScore < GamePlay.Inst.targetScore && nextProgressScore >= GamePlay.Inst.targetScore) {
  221. let node_getTargetScoreTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
  222. GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
  223. // //进度到达开始显示
  224. gData.reward.subType = 2;
  225. mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  226. mk.ui.openPanel("module/reward/rewardLuck");
  227. }
  228. this.curProgressScore = nextProgressScore;
  229. if (this.curProgressScore >= this.curGetScore) {
  230. this.curProgressScore = this.curGetScore;
  231. }
  232. this.initScore();
  233. }
  234. }
  235. }
  236. /**初始化视图 */
  237. initView() {
  238. this.initLevel();
  239. this.initTotalScore();
  240. this.initScore();
  241. this.initProgress();
  242. this.initHammerPropNum();
  243. this.setPropBtnNormalTip(this.node_hammerBtn);
  244. this.initResetPropNum();
  245. this.setPropBtnNormalTip(this.node_resetBtn);
  246. this.initChanegPropNum();
  247. this.setPropBtnNormalTip(this.node_changeBtn);
  248. this.initCellBg();
  249. this.initCell();
  250. }
  251. /**初始化事件 */
  252. initEvent() {
  253. this.node_pauseBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  254. this.node_resetBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  255. this.node_hammerBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  256. this.node_changeBtn.on(cc.Node.EventType.TOUCH_END, this.onClickBtn, this);
  257. this.node_redPacketIcon.on(cc.Node.EventType.TOUCH_END, this.onClickRedPacketIcon, this);
  258. if (!GameConst.isAuth) {
  259. mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
  260. }
  261. }
  262. /**初始化关卡数目 */
  263. initLevel() {
  264. mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
  265. let level = gData.gameData.getProp(GameProp.levelNum);
  266. this.label_level.string = `第${level + 1}关`
  267. }
  268. /**初始化总分数 */
  269. initTotalScore() {
  270. let level = gData.gameData.getProp(GameProp.levelNum);
  271. //加入一些随机值,而不是都能获得过关红包
  272. this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
  273. // //测试切换
  274. // this.targetScore = 5000;
  275. this.addScoreSpeed = Math.floor(this.targetScore / 200) * 2 + 4;
  276. mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
  277. }
  278. /**初始化得分 */
  279. initScore() {
  280. this.initProgress();
  281. }
  282. /**初始化进度 */
  283. initProgress() {
  284. let progress = this.curProgressScore / this.targetScore;
  285. progress = progress > 1 ? 1 : progress;
  286. this.spr_progress.fillRange = progress;
  287. // if (progress >= 1) {
  288. // this.pass();
  289. // mk.ui.openPanel("module/reward/rewardMission");
  290. // }
  291. // LogUtil.log("progressprogressprogressprogressprogressprogress", progress);
  292. }
  293. /**初始化道具 */
  294. initPropNum() {
  295. this.initHammerPropNum();
  296. this.initResetPropNum();
  297. this.initChanegPropNum();
  298. }
  299. /**初始化锤子道具数目 */
  300. initHammerPropNum() {
  301. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  302. if (hammerPropNum) {
  303. this.label_hammerPropNum.string = hammerPropNum.toString();
  304. }
  305. else {
  306. this.label_hammerPropNum.string = "+";
  307. }
  308. }
  309. /**初始化重置道具数目 */
  310. initResetPropNum() {
  311. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  312. if (resetPropNum) {
  313. this.label_resetPropNum.string = resetPropNum.toString();
  314. }
  315. else {
  316. this.label_resetPropNum.string = "+";
  317. }
  318. }
  319. /**初始化替换道具数目 */
  320. initChanegPropNum() {
  321. let changePropNum = gData.gameData.getProp(GameProp.changePropNum);
  322. if (changePropNum) {
  323. this.label_changePropNum.string = changePropNum.toString();
  324. }
  325. else {
  326. this.label_changePropNum.string = "+";
  327. }
  328. }
  329. // update (dt) {}
  330. /**初始化cellBg */
  331. initCellBg() {
  332. for (var i = 0; i < GameConst.col_num; i++) {
  333. for (var j = 0; j < GameConst.row_num; j++) {
  334. let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  335. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  336. let node_cellBg = cc.instantiate(prefab_cellBg);
  337. this.node_cellBg.addChild(node_cellBg);
  338. }
  339. }
  340. }
  341. /**初始化cell */
  342. public initCell() {
  343. this.addCellItemFuc = () => { this.addCellItem(); };
  344. this.schedule(this.addCellItemFuc, 0.05);
  345. }
  346. public addCellItemFuc: Function = null;
  347. public curXIndex: number = 0;
  348. public curYIndex: number = 7;
  349. /**添加CellItem */
  350. public addCellItem() {
  351. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  352. this.addColCellItem();
  353. this.curXIndex++;
  354. if (this.curXIndex >= GameConst.col_num) {
  355. this.unschedule(this.addCellItemFuc);
  356. // this.getStartRedPacketCellItem();
  357. }
  358. }
  359. /**添加纵列的cellItem */
  360. public addColCellItem() {
  361. this.cellItemDic[this.curXIndex] = [];
  362. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  363. let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  364. let node_prefab = cc.instantiate(prefab_cellItem);
  365. let cellItem = node_prefab.getComponent(CellItem);
  366. cellItem.init(this.curXIndex, i);
  367. this.cellItemDic[this.curXIndex][i] = cellItem;
  368. this.cellItemArr.push(cellItem);
  369. this.node_content.addChild(node_prefab);
  370. }
  371. }
  372. /**点击按钮 */
  373. onClickBtn(event: cc.Event.EventTouch) {
  374. this.intervalShowGuide();
  375. this.intervalShowInter();
  376. //是否已经通关
  377. if (this.ifPass) {
  378. EffectMgr.Inst.addTip("通关结算啦,请稍后操作哈")
  379. return;
  380. }
  381. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.buttonClick);
  382. mk.audio.playEffect("button");
  383. switch (event.currentTarget) {
  384. case this.node_pauseBtn:
  385. this.onClickPauseBtn();
  386. break;
  387. case this.node_hammerBtn:
  388. this.onClickHammerBtn();
  389. break;
  390. case this.node_changeBtn:
  391. this.onClickChangeBtn();
  392. break;
  393. case this.node_resetBtn:
  394. this.onClickResetBtn();
  395. break;
  396. }
  397. }
  398. /**点击暂停按钮 */
  399. onClickPauseBtn() {
  400. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击暂停按钮");
  401. mk.ui.openPanel("game/prefab/uiPanel/PauseUI")
  402. }
  403. /**点击分享 */
  404. public onClickShare() {
  405. if (!gData.loginData.isAuth) {
  406. // mk.tip.pop("请先点击头像,在设置界面授权");
  407. JsbSystem.WxAuth();
  408. return;
  409. }
  410. JsbSystem.sharePic();
  411. }
  412. /**点击重置按钮 */
  413. onClickResetBtn() {
  414. //this.intervalShowGuide();
  415. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击重置道具按钮");
  416. //设置当前选择的道具按钮
  417. this.setCurSelectPropBtn(this.node_resetBtn);
  418. this.curPropType = PROPTYPE.Reset;
  419. let resetPropNum = gData.gameData.getProp(GameProp.resetPropNum);
  420. if (!resetPropNum || resetPropNum <= 0) {
  421. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  422. return;
  423. }
  424. // AudioMgr.Inst.playEffect(AUDIO_CLIP_NAME.refresh);
  425. mk.audio.playEffect("ef_refresh");
  426. let keys = Object.keys(this.cellItemDic);
  427. for (var i = 0; i < keys.length; i++) {
  428. let key = Number(keys[i]);
  429. let colCellItemArr = this.cellItemDic[key];
  430. for (var j = 0; j < colCellItemArr.length; j++) {
  431. let cellItem = colCellItemArr[j];
  432. if (cellItem) {
  433. cellItem.reset();
  434. }
  435. }
  436. }
  437. //暂时不扣
  438. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  439. this.curPropType = PROPTYPE.Null;
  440. //this.recycleAllCellItem();
  441. }
  442. //点击锤子按钮
  443. onClickHammerBtn() {
  444. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击消除锤道具按钮");
  445. //this.intervalShowGuide();
  446. //设置当前选择的道具按钮
  447. this.setCurSelectPropBtn(this.node_hammerBtn);
  448. this.curPropType = PROPTYPE.Hammer;
  449. let hammerPropNum = gData.gameData.getProp(GameProp.hammerPropNum);
  450. if (!hammerPropNum || hammerPropNum <= 0) {
  451. mk.ui.openPanel("game/prefab/uiPanel/GetPropUI");
  452. return;
  453. }
  454. DataMgr.Inst.updatePropNum(2, GamePlay.Inst.curPropType, -1);
  455. }
  456. //点击更换按钮
  457. onClickChangeBtn() {
  458. GameMgr.Inst.sendEvent(UI_NAME.Game, "点击变化方块按钮");
  459. //this.intervalShowGuide();
  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(false);
  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(ifMinusEnergy: boolean = false) {
  823. mk.console.log("restart!!!!!!!!!!!!!!!")
  824. this.refreshGame();
  825. }
  826. /**下一关 */
  827. nextLevel(ifMinusEnergy: boolean = false) {
  828. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  829. this.refreshGame();
  830. }
  831. /**刷新关卡 */
  832. refreshGame() {
  833. mk.data.sendDataEvent(DataEventId.level, "关卡开启");
  834. this.recycleAllCellItem();
  835. this.ifPass = false;
  836. this.ifGetPass = false;
  837. this.ifCouldClick = true;
  838. this.initLevel();
  839. this.initTotalScore();
  840. //FC:改成累分制而不是每关重置
  841. // this.curProgressScore = 0;
  842. // this.curGetScore = 0;
  843. // this.finalGetScore = 0;
  844. this.initScore();
  845. }
  846. /**回收所有的 */
  847. recycleAllCellItem() {
  848. for (var i = 0; i < GameConst.col_num; i++) {
  849. for (var j = 0; j < GameConst.row_num; j++) {
  850. let cellItem = this.cellItemDic[i][j];
  851. if (cellItem) {
  852. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  853. cellItem.recycle(true, false, false);
  854. }
  855. }
  856. }
  857. // while (this.cellItemList.length > 0) {
  858. // this.cellItemList.splice(0, 1);
  859. // this.cellItemList[0].recycle();
  860. // }
  861. this.cellItemArr = [];
  862. this.cellItemDic = {};
  863. this.curXIndex = 0;
  864. this.curYIndex = GameConst.row_num - 1;
  865. this.initCell();
  866. }
  867. /**通关 */
  868. pass() {
  869. //这边会多次进入
  870. if (GamePlay.Inst.node.active == false || this.ifPass) {
  871. return;
  872. }
  873. mk.data.sendDataEvent(DataEventId.level, "关卡通关");
  874. this.ifPass = true;
  875. GamePlay.Inst.ifGetPass = false;
  876. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  877. mk.console.log("[Game]pass passLevelNum", levelNum);
  878. GamePlay.Inst.ifGetPass = true;
  879. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  880. let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  881. if (node_rewardLuck) {
  882. return;
  883. }
  884. else {
  885. //游戏结算
  886. this.gameCount();
  887. console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  888. }
  889. }
  890. /**游戏结算 */
  891. gameCount() {
  892. let node_getPropUI = mk.ui.getCurOnPanel("GetPropUI");
  893. if (node_getPropUI) {
  894. mk.ui.closePanel("GetPropUI");
  895. }
  896. this.gameOver();
  897. }
  898. /**游戏结束 */
  899. gameOver() {
  900. mk.ui.openPanel("game/prefab/uiPanel/GameOverUI")
  901. }
  902. checkBonusNum(cleanCellItemNum: number) {
  903. if (cleanCellItemNum >= 4) {
  904. let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  905. let bonusTip = node_bonusTip.getComponent(BonusTip);
  906. //LogUtil.log("bonusTip",bonusTip);
  907. if (cleanCellItemNum == 4) {
  908. bonusTip.init(4);
  909. mk.audio.playEffect("ef_bonus4");
  910. }
  911. else if (cleanCellItemNum == 5) {
  912. bonusTip.init(5);
  913. mk.audio.playEffect("ef_bonus5");
  914. }
  915. else if (cleanCellItemNum == 6) {
  916. bonusTip.init(6);
  917. mk.audio.playEffect("ef_bonus6");
  918. }
  919. else if (cleanCellItemNum == 7) {
  920. bonusTip.init(7);
  921. mk.audio.playEffect("ef_bonus7");
  922. }
  923. else if (cleanCellItemNum == 8) {
  924. bonusTip.init(8);
  925. mk.audio.playEffect("ef_bonus8");
  926. }
  927. else {
  928. bonusTip.init(8);
  929. mk.audio.playEffect("ef_bonus8");
  930. }
  931. this.node_effectUI.addChild(node_bonusTip);
  932. }
  933. }
  934. checkAddLevelRedPacket(eliminateNum: number): boolean {
  935. let chance = (eliminateNum - 3) * 0.2;
  936. let random = Math.random();
  937. if (random < chance) {
  938. return true;
  939. }
  940. else {
  941. return false;
  942. }
  943. }
  944. public interval_ShowGuide: number = null;
  945. //间隔显示
  946. intervalShowGuide() {
  947. this.cancelShowCouldCleanCellItem();
  948. this.interval_ShowGuide = setInterval(() => {
  949. this.showCouldCleanCellItem();
  950. }, 10000);
  951. }
  952. /**显示 */
  953. showCouldCleanCellItem() {
  954. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  955. return;
  956. }
  957. if (this.couldCleanVecArr.length <= 0) {
  958. GameLogic.getCouldCleanVec();
  959. }
  960. if (this.couldCleanVecArr.length > 0) {
  961. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  962. let vec = this.couldCleanVecArr[i];
  963. if (this.cellItemDic[vec.x]) {
  964. let cellItem = this.cellItemDic[vec.x][vec.y];
  965. if (cellItem) {
  966. cellItem.shake();
  967. }
  968. }
  969. else {
  970. }
  971. }
  972. }
  973. }
  974. /**取消显示 */
  975. cancelShowCouldCleanCellItem() {
  976. if (this.interval_ShowGuide) {
  977. clearInterval(this.interval_ShowGuide);
  978. this.interval_ShowGuide = null;
  979. if (this.couldCleanVecArr.length > 0) {
  980. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  981. let vec = this.couldCleanVecArr[i];
  982. let cellItem = this.cellItemDic[vec.x][vec.y];
  983. if (cellItem) {
  984. cellItem.normal();
  985. }
  986. }
  987. }
  988. this.couldCleanVecArr = [];
  989. }
  990. }
  991. public interval_ShowInter: number = null;
  992. //间隔显示
  993. intervalShowInter() {
  994. let time = gData.gameData.configs.ServerConfig.interOpenGapTime;
  995. if (!time) {
  996. time = 15000;
  997. }
  998. else {
  999. time *= 1000;
  1000. }
  1001. this.cancelShowInter();
  1002. this.interval_ShowGuide = setInterval(() => {
  1003. mk.ad.showInterAd(0);
  1004. }, time);
  1005. }
  1006. cancelShowInter() {
  1007. if (this.interval_ShowGuide) {
  1008. clearInterval(this.interval_ShowGuide);
  1009. }
  1010. }
  1011. /**
  1012. * 气泡红包是否开启
  1013. */
  1014. private qipaoShow() {
  1015. for (let i = 0; i < 4; i++) {
  1016. this['btn_gameGetRed' + (i + 1)].active = gData.gameData.funBtns.btn8.active;
  1017. }
  1018. }
  1019. }