game.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /**
  2. * @author heyuchang
  3. * @file 游戏控制
  4. */
  5. import ATSDK from "./AnyThinkAds/ATJSSDK";
  6. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoJSSDK";
  7. import AAJS2 from "./ATAndroidJS2";
  8. import AESUtil from "./AESUtil"
  9. var AC = require('GameAct')
  10. //AD播放完毕后需要进行什么奖励的标记,如:fuHuo等,启用游戏的时候需要清空该KEY
  11. var yxAdMark = 'yxAdMark'
  12. /**
  13. * AD播放完毕标识
  14. */
  15. var adPalyOverEve_ = 'adPalyOverEve'
  16. var state = false;//AD 专用的
  17. cc.Class({
  18. extends: cc.Component,
  19. properties: {
  20. _status: 0, //0 未开始 1 游戏开始 2 游戏暂停 3 游戏结束 4 下落状态 5无法触摸状态
  21. blockPrefab: cc.Prefab,
  22. blockSprite: [cc.SpriteFrame], //todo: 换成动态生成 暂不处理
  23. warningSpriteFrame: [cc.SpriteFrame],
  24. propSpriteFrame: [cc.SpriteFrame],
  25. checkMgr: require("elementCheck"),
  26. revivePage: cc.Node,
  27. },
  28. onLoad() {
  29. console.log('zh:1111game.js onload...')
  30. cc.sys.localStorage.removeItem(yxAdMark)
  31. this.yxAdEventInit();
  32. },
  33. start() {
  34. console.log('zh:game.js start...')
  35. console.log('zh: ad over 开始测试发送事件s')
  36. this.node.emit(adPalyOverEve_, 'test');
  37. console.log('zh: ad over 开始测试发送事件e')
  38. this.bindNode()
  39. this.generatePool()
  40. this.loadRes()
  41. this.initAd()
  42. setTimeout(() => {
  43. this.initAdForPage();
  44. }, 300);
  45. },
  46. //ad相关的事件初始化
  47. yxAdEventInit() {
  48. let that = this;
  49. this.node.on(adPalyOverEve_, function (msg) {
  50. console.log('zh:接收到事件调用adPalyOverEve msg=' + msg);
  51. switch (msg) {
  52. case 'AdClosed':
  53. console.log('zh:ad over AdClosed')
  54. break;
  55. case 'AdPlayEnd':
  56. console.log('zh:好的,我知道广告播放完毕了,我进行奖励处理')
  57. that.yxAdPlayEndAction();
  58. break;
  59. default:
  60. break;
  61. }
  62. });
  63. },
  64. initAdForPage() {
  65. console.log('zh:game.js initAdForPage start')
  66. let deviceId = AAJS2.getDeviceUserId();
  67. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementID()));
  68. var setting = {};
  69. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  70. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementID(), setting);
  71. },
  72. // 看完了广告那么就要发放奖励(道具)
  73. yxAdPlayEndAction() {
  74. let mark = cc.sys.localStorage.getItem(yxAdMark);//看广告用于 xx 标记
  75. console.log('zh:yxAdMark=' + mark);
  76. switch (mark) {
  77. case 'fuHuo'://复活
  78. console.log('zh:因为你看完了AD,所以开始发放复活道具')
  79. this.showReviveSuccess()
  80. //this.askRevive()
  81. break;
  82. case "step2"://双倍步数奖励
  83. console.log('zh:因为你看完了AD,所以开始发放双倍步数奖励道具')
  84. this._score.onLevelUpButton(2)
  85. break;
  86. default:
  87. console.log('zh:没有找到yxAdMark 相关的信息!!!!!!!')
  88. break;
  89. }
  90. this.clearAdMark();
  91. },
  92. /**
  93. * 清除AD 奖励标识
  94. */
  95. clearAdMark() {
  96. cc.sys.localStorage.removeItem(yxAdMark)
  97. },
  98. //#region "AD 监听start"
  99. onRewardedVideoAdLoaded(placementId) {
  100. console.log('zh:onRewardedVideoAdLoaded')
  101. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  102. },
  103. onRewardedVideoAdFailed(placementId, errorInfo) {
  104. console.log('zh:onRewardedVideoAdFailed')
  105. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  106. // BrickMsger.emit(BrickMsger.on_play_sound, 1);
  107. // BrickMsger.emit(BrickMsger.on_changeto_start);
  108. //测试AD 事件
  109. // console.log('zh: ad over 开始发送事件aaaa')
  110. // this.node.emit("handleCustomEvent");
  111. // console.log('zh: ad over 开始发送事件bbb')
  112. },
  113. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  114. console.log('zh:onRewardedVideoAdPlayStart')
  115. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  116. let deviceId = AAJS2.getDeviceUserId();
  117. var setting = {};
  118. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  119. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementID(), setting);
  120. },
  121. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  122. console.log('zh:onRewardedVideoAdPlayEnd')
  123. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  124. //that.retrive();
  125. // BrickMsger.emit(BrickMsger.on_play_sound, 1);
  126. // BrickMsger.emit(BrickMsger.on_changeto_start);
  127. console.log('zh: ad onRewardedVideoAdPlayEnd 开始发送事件s')
  128. this.node.emit(adPalyOverEve_, 'AdPlayEnd');
  129. console.log('zh: ad onRewardedVideoAdPlayEnd 发送事件e')
  130. },
  131. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  132. console.log('zh:onRewardedVideoAdPlayFailed')
  133. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  134. // BrickMsger.emit(BrickMsger.on_play_sound, 1);
  135. // BrickMsger.emit(BrickMsger.on_changeto_start);
  136. },
  137. onRewardedVideoAdClosed(placementId, callbackInfo) {
  138. try {
  139. //console.log('zh:onRewardedVideoAdClosed')
  140. //ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  141. //console.log("zh:onRewardedVideoAdClosed", this.state);
  142. if (this.state == true) {
  143. console.log('zh: ad onRewardedVideoAdClosed 开始发送事件s')
  144. this.node.emit(adPalyOverEve_, 'AdClosed');
  145. console.log('zh: ad onRewardedVideoAdClosed 发送事件e')
  146. this.state = false;
  147. } else {
  148. this.state = false;
  149. }
  150. } catch (error) {
  151. console.log('zh:onRewardedVideoAdClosed error',error)
  152. }
  153. },
  154. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  155. console.log('zh:onRewardedVideoAdPlayClicked')
  156. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  157. },
  158. onReward(placementId, callbackInfo) {
  159. console.log('zh:onReward')
  160. ATSDK.printLog("AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  161. console.log("onRewardxxxxxx");
  162. //BrickMsger.emit(BrickMsger.on_play_sound, 1);
  163. //BrickMsger.emit(BrickMsger.on_game_revie);
  164. this.state = true;
  165. },
  166. //#endregion "AD 监听end"
  167. /**
  168. * 初始化广告
  169. */
  170. initAd() {
  171. console.log('zh:AD init start1')
  172. let placementID = AAJS2.getPlacementID();
  173. let deviceId = AAJS2.getDeviceUserId();
  174. var setting = {};
  175. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  176. ATRewardedVideoSDK.loadRewardedVideo(placementID, setting);
  177. //console.log('zh:bbb222')
  178. var customPlacementId = "";
  179. if (cc.sys.os === cc.sys.OS_IOS) {
  180. customPlacementId = placementID;
  181. } else if (cc.sys.os === cc.sys.OS_ANDROID) {
  182. customPlacementId = placementID;
  183. }
  184. // 初始化SDK
  185. //ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");//测试专用,可以显示广告 ???
  186. ATSDK.initSDK("h672d7ac280581", "a899a1cd61dd62b83793d38c70486c750");//hxz
  187. //ATSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是打砖块的已经上架的
  188. ATSDK.setLogDebug(false);//ZH:DIY
  189. var GDPRLevel = ATSDK.getGDPRLevel();
  190. //var state = false;
  191. // const listener = {
  192. // //。。。。。。。。
  193. // };
  194. // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  195. ATSDK.getUserLocation(function (userLocation) {
  196. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  197. if (userLocation === ATSDK.kATUserLocationInEU) {
  198. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  199. ATSDK.showGDPRAuth();
  200. }
  201. }
  202. });
  203. ATRewardedVideoSDK.setAdListener(this);
  204. if (cc.sys.os === cc.sys.OS_ANDROID) {
  205. setTimeout(() => {
  206. var allInfo = AAJS2.allInfo();
  207. ATSDK.printLog("zh:allInfo=" + allInfo);
  208. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  209. let iv = "Jn0.aWsOu$y-Dbqb";
  210. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  211. ATSDK.printLog("zh:allInfo-jm=" + JSON.stringify(data));
  212. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  213. }, 300);
  214. }
  215. console.log('zh:AD init end11111')
  216. },
  217. loadRes() {
  218. },
  219. init(c) {
  220. this._controller = c
  221. this._score = c.scoreMgr
  222. this.rowNum = c.config.json.rowNum
  223. this.gap = c.config.json.gap
  224. this.animationSpeed = c.config.json.gap
  225. this.blockWidth = (730 - (this.rowNum + 1) * this.gap) / this.rowNum
  226. this.reviveTimer = null
  227. //console.log(this.gap)
  228. //console.log(this.blockWidth)
  229. },
  230. // 动态获取需要动态控制的组件
  231. bindNode() {
  232. this.blocksContainer = this.node.getChildByName('map')
  233. },
  234. //---------------- 游戏控制 ---------------------
  235. // 游戏开始
  236. gameStart() {
  237. this.recoveryAllBlocks().then()
  238. this._score.init(this)
  239. this.mapSet(this.rowNum).then((result) => {
  240. // console.log('游戏状态改变', result)
  241. this._status = 1
  242. })
  243. },
  244. // 初始化地图
  245. mapSet(num) {
  246. this.map = new Array()
  247. console.log('h:mamez.js mapSet 0 ')
  248. let self = this
  249. // 生成两个随机的对象数组
  250. let a = Math.floor(Math.random() * num)
  251. let b = Math.floor(Math.random() * num)
  252. let c = Math.floor(1 + Math.random() * (num - 1)) - 1
  253. a == c ? c++ : ''
  254. let d = Math.floor(Math.random() * num)
  255. return new Promise((resolve, reject) => {
  256. for (let i = 0; i < num; i++) { //行
  257. this.map[i] = new Array()
  258. for (let j = 0; j < num; j++) { //列
  259. let itemType = (i == a && j == b) ? 1 : (i == c && j == d) ? 2 : 0
  260. self.map[i][j] = self.instantiateBlock(self, {
  261. x: j,
  262. y: i,
  263. width: self.blockWidth,
  264. startTime: (i + j + 1) * self._controller.config.json.startAnimationTime / num * 2
  265. }, self.blocksContainer, itemType)
  266. }
  267. }
  268. this.checkMgr.init(this)
  269. setTimeout(() => {
  270. resolve('200 OK');
  271. this.checkMgr.elementCheck(this)
  272. }, self._controller.config.json.startAnimationTime * num / 2 / 1
  273. // (cc.game.getFrameRate() / 60)
  274. )
  275. })
  276. },
  277. //防抖动 判断是否需要检测下落
  278. checkNeedFall() {
  279. if (this.checkNeedFallTimer) {
  280. clearTimeout(this.checkNeedFallTimer)
  281. }
  282. this.checkNeedFallTimer = setTimeout(() => {
  283. if (this._status == 5) {
  284. this._status = 4
  285. this.onFall()
  286. }
  287. }, 300 / 1
  288. // (cc.game.getFrameRate() / 60)
  289. )
  290. },
  291. //方块下落
  292. onFall() {
  293. this.checkGenerateProp(this._score.chain).then(() => {
  294. let self = this
  295. let canFall = 0
  296. //从每一列的最下面一个开始往上判断
  297. //如果有空 就判断有几个空 然后让最上方的方块掉落下来
  298. for (let j = this.rowNum - 1; j >= 0; j--) {
  299. canFall = 0
  300. for (let i = this.rowNum - 1; i >= 0; i--) {
  301. if (this.map[i][j].getComponent('element')._status == 2) {
  302. this.blockPool.put(this.map[i][j])
  303. this.map[i][j] = null
  304. canFall++
  305. } else {
  306. if (canFall != 0) {
  307. this.map[i + canFall][j] = this.map[i][j]
  308. this.map[i][j] = null
  309. this.map[i + canFall][j].getComponent('element').playFallAction(canFall, {
  310. x: j,
  311. y: i + canFall,
  312. })
  313. }
  314. }
  315. }
  316. for (var k = 0; k < canFall; k++) {
  317. this.map[k][j] = this.instantiateBlock(this, {
  318. x: j,
  319. y: k,
  320. width: this.blockWidth,
  321. startTime: null
  322. }, this.blocksContainer, '', {
  323. x: j,
  324. y: -canFall + k
  325. })
  326. this.map[k][j].getComponent('element').playFallAction(canFall, null)
  327. }
  328. }
  329. setTimeout(() => {
  330. this.checkMgr.init(this)
  331. this.checkMgr.elementCheck(this)
  332. this._status = 1
  333. }, 250)
  334. })
  335. },
  336. gameOver() {
  337. this._status = 3
  338. this._controller.pageManager.addPage(2)
  339. this._controller.pageManager.addPage(4)
  340. if (this._controller.social.node.active) {
  341. this._controller.social.closeBannerAdv()
  342. }
  343. },
  344. // todo 复活
  345. askRevive() {
  346. console.log('zh:askRevive 1')
  347. this._controller.pageManager.addPage(2)
  348. this._controller.pageManager.addPage(5)
  349. this.revivePage.active = true
  350. this.revivePage.getChildByName('askRevive').active = true
  351. this.revivePage.getChildByName('successRevive').active = false
  352. this.rangeSprite = this.revivePage.getChildByName('askRevive').getChildByName('numBg').getChildByName('sprite').getComponent(cc.Sprite)
  353. this.rangeSprite.fillRange = 1
  354. this.isRangeAction = true
  355. let numLabel = this.revivePage.getChildByName('askRevive').getChildByName('numBg').getChildByName('num').getComponent(cc.Label)
  356. numLabel.string = 9
  357. if (this.reviveTimer) {
  358. clearInterval(this.reviveTimer)
  359. }
  360. //zh:下面是原始的代码
  361. this.reviveTimer = setInterval(() => {
  362. console.log('zh:timer ...')
  363. if (+numLabel.string > 0) {
  364. numLabel.string--
  365. this.rangeSprite.fillRange = 1
  366. } else {
  367. console.log('zh:askRevive 2')
  368. //this.onSkipRevive() 这是有BUG的
  369. this.onSkipReviveForDiy();
  370. }
  371. }, 1000)
  372. },
  373. onReviveButton() {
  374. console.log('zh:点击复活按钮3')
  375. // console.log('zh: 复活BUT 开始测试发送事件s')
  376. // cc.sys.localStorage.setItem(yxAdMark, 'fuHuo');//看广告用于 复活 标记
  377. // this.node.emit(adPalyOverEve_, 'AdPlayEnd');
  378. // console.log('zh: 复活BUT 开始测试发送事件e')
  379. //下面是上线后的逻辑
  380. setTimeout(() => {
  381. if (cc.sys.os === cc.sys.OS_ANDROID) {
  382. let placementID = AAJS2.getPlacementID();
  383. if (ATRewardedVideoSDK.hasAdReady(placementID)) {
  384. cc.sys.localStorage.setItem(yxAdMark, 'fuHuo');//看广告用于 复活 标记
  385. ATRewardedVideoSDK.showAd(placementID);
  386. console.log('zh:clear timer s')
  387. if (this.reviveTimer) {
  388. clearInterval(this.reviveTimer)
  389. }
  390. console.log('zh:clear timer e')
  391. } else {
  392. this.clearAdMark();
  393. console.log('zh:AD 没有准备好')
  394. console.log('zh:clear timer s1')
  395. if (this.reviveTimer) {
  396. clearInterval(this.reviveTimer)
  397. }
  398. this.showReviveSuccess()
  399. console.log('zh:clear timer e1')
  400. }
  401. }
  402. }, 300)
  403. let testMark = true;//是否跳过
  404. if (testMark) {
  405. return;
  406. }
  407. console.log('zh: onReviveButton 下面的是原始的逻辑')
  408. clearInterval(this.reviveTimer)
  409. this.isRangeAction = false
  410. if (this._controller.social.node.active) {
  411. this._controller.social.onReviveButton(1)
  412. } else {
  413. this.showReviveSuccess()
  414. }
  415. },
  416. showReviveSuccess() {
  417. console.log('zh:打开复活成功页面')
  418. this.revivePage.getChildByName('askRevive').active = false
  419. this.revivePage.getChildByName('successRevive').active = true
  420. },
  421. onReviveCertainBtn() {//应该是看了广告点击获取步数后执行
  422. console.log('zh:onReviveCertainBtn 看了广告点击获取步数后执行')
  423. this._controller.pageManager.removePage(2)
  424. this.revivePage.active = false
  425. this._status = 1
  426. this._score.onRevive()
  427. },
  428. update() {
  429. if (this.isRangeAction) {
  430. this.rangeSprite.fillRange -= 1 / 60
  431. }
  432. },
  433. ///解决BUG
  434. onSkipReviveForDiy() {
  435. console.log('zh:onSkipReviveForDiy zh ')
  436. clearInterval(this.reviveTimer)
  437. this.onReviveButton();
  438. // 5 复活页面
  439. //this._controller.pageManager.pages[5].active = false
  440. //this._score.onGameOver(true)
  441. //this.isRangeAction = false
  442. },
  443. onSkipRevive() {
  444. console.log('zh:onSkipRevive')
  445. clearInterval(this.reviveTimer)
  446. this._controller.pageManager.pages[5].active = false
  447. this._score.onGameOver(true)
  448. this.isRangeAction = false
  449. },
  450. restart() {//再来一局
  451. console.log('zh:restart')
  452. this._controller.pageManager.onOpenPage(1)
  453. this.recoveryAllBlocks().then(() => {
  454. this.gameStart()
  455. })
  456. },
  457. // -----------------道具相关---------------
  458. // 储存用户点击时的方块 用于生成道具
  459. onUserTouched(iid, jid, itemType, color, warning, pos) {
  460. this.target = {
  461. i: iid,
  462. j: jid,
  463. color: color,
  464. itemType: itemType,
  465. x: pos.x,
  466. y: pos.y,
  467. warning: warning
  468. }
  469. },
  470. // 生成道具 type 1为双倍倍数 2为炸弹 3为加五百
  471. generatePropItem(type) {
  472. return new Promise((resolve, reject) => {
  473. // 是否做道具生成动画
  474. this.map[this.target.i][this.target.j] = this.instantiateBlock(this, {
  475. x: this.target.j,
  476. y: this.target.i,
  477. color: this.target.color,
  478. width: this.blockWidth,
  479. startTime: null
  480. }, this.blocksContainer, type)
  481. setTimeout(() => {
  482. resolve()
  483. }, 300)
  484. })
  485. },
  486. checkGenerateProp(chain) {
  487. return new Promise((resolve, reject) => {
  488. if (this.target.warning) {
  489. this.generatePropItem(this.target.warning).then(() => {
  490. resolve()
  491. return
  492. })
  493. }
  494. resolve()
  495. })
  496. },
  497. onItem(type, color, pos) {
  498. switch (type) {
  499. case 1:
  500. // 分数翻倍 最高八倍
  501. this._score.tipBox.init(this._score, 1)
  502. this._score.addMult(color, pos)
  503. this._controller.musicManager.onDouble()
  504. for (let i = 0; i < this.rowNum; i++) { //行
  505. for (let j = 0; j < this.rowNum; j++) { //列
  506. if (this.map[i][j] && this.map[i][j].getComponent('element')._status == 1) {
  507. let distance = Math.sqrt(Math.pow(pos.x - this.map[i][j].x, 2) + Math.pow(pos.y - this.map[i][j].y, 2))
  508. if (distance != 0) {
  509. this.map[i][j].getComponent('element').surfaceAction(distance)
  510. }
  511. }
  512. }
  513. }
  514. break
  515. case 2:
  516. // 炸弹 消除同种颜色的
  517. this._score.tipBox.init(this._score, 2)
  518. this.node.runAction(AC.shackAction(0.1, 10))
  519. if (this._controller.social.node.active) {
  520. this._controller.social.onShakePhone()
  521. }
  522. this.isPropChain = true
  523. this._controller.musicManager.onBoom()
  524. for (let i = 0; i < this.rowNum; i++) { //行
  525. for (let j = 0; j < this.rowNum; j++) { //列
  526. if (this.map[i][j] && this.map[i][j].getComponent('element').color == color && this.map[i][j] && this.map[i][j].getComponent('element')._status != 2) {
  527. this.map[i][j].getComponent('element').onTouched(color, false, true)
  528. }
  529. else {
  530. this.map[i][j].runAction(AC.rockAction(0.2, 10))
  531. }
  532. }
  533. }
  534. break
  535. case 3: //: 加步数
  536. this._score.tipBox.init(this._score, 4)
  537. this._controller.musicManager.onDouble()
  538. for (let i = 0; i < this.rowNum; i++) { //行
  539. for (let j = 0; j < this.rowNum; j++) { //列
  540. if (this.map[i][j] && this.map[i][j].getComponent('element')._status == 1) {
  541. let distance = Math.sqrt(Math.pow(pos.x - this.map[i][j].x, 2) + Math.pow(pos.y - this.map[i][j].y, 2))
  542. if (distance != 0) {
  543. this.map[i][j].getComponent('element').surfaceAction(distance)
  544. }
  545. }
  546. }
  547. }
  548. this._score.onStep(3).then()
  549. break;
  550. case 4: // : 消除全部单身的方块
  551. this._score.tipBox.init(this._score, 5)
  552. this.isPropChain = true
  553. this._controller.musicManager.onMagic()
  554. for (let i = 0; i < this.rowNum; i++) { //行
  555. for (let j = 0; j < this.rowNum; j++) { //列
  556. if (this.map[i][j] && this.map[i][j].getComponent('element').isSingle && this.map[i][j] && this.map[i][j].getComponent('element')._status != 2) {
  557. let distance = Math.sqrt(Math.pow(pos.x - this.map[i][j].x, 2) + Math.pow(pos.y - this.map[i][j].y, 2))
  558. this.map[i][j].getComponent('element').onTouched(color, false, true, distance)
  559. console.log("魔法棒触发的点", i, j, this.map[i][j].getComponent('element').color, this.map[i][j].getComponent('element').isSingle)
  560. }
  561. }
  562. }
  563. break;
  564. }
  565. },
  566. //--------------------- 预制体实例化---------------------
  567. // 生成对象池
  568. generatePool() {
  569. this.blockPool = new cc.NodePool()
  570. for (let i = 0; i < Math.pow(this.rowNum, 2); i++) {
  571. let block = cc.instantiate(this.blockPrefab)
  572. this.blockPool.put(block)
  573. }
  574. },
  575. // 实例化单个方块
  576. instantiateBlock(self, data, parent, itemType, pos) {
  577. itemType = itemType ? itemType : 0
  578. if (itemType != 0) {
  579. // console.log("道具节点数据", data, itemType)
  580. }
  581. let block = null
  582. if (self.blockPool && self.blockPool.size() > 0) {
  583. block = self.blockPool.get()
  584. } else {
  585. block = cc.instantiate(self.blockPrefab)
  586. }
  587. block.parent = parent
  588. block.scale = 1
  589. block.x = 0
  590. block.y = 0
  591. block.getComponent('element').init(self, data, this.blockWidth, itemType, pos)
  592. return block
  593. },
  594. // 回收所有节点
  595. recoveryAllBlocks() {
  596. return new Promise((resolve, reject) => {
  597. let children = this.blocksContainer.children
  598. if (children.length != 0) {
  599. let length = children.length
  600. // console.log(length)
  601. for (let i = 0; i < length; i++) {
  602. this.blockPool.put(children[0])
  603. }
  604. for (let i = 0; i < this.rowNum; i++) {
  605. for (let j = 0; j < this.rowNum; j++) {
  606. this.map[i][j] = null
  607. }
  608. }
  609. }
  610. resolve('')
  611. })
  612. },
  613. });