0753c3b3-b19c-4d4e-8c61-78062a1079d7.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. "use strict";
  2. cc._RF.push(module, '0753cOzsZxNToxheAYqEHnX', 'ZY_StarManager');
  3. // Texture/prefab/ZY_StarManager.js
  4. "use strict";
  5. /**
  6. * 游戏核心部分
  7. */
  8. var GameEvent = require('GameEvent');
  9. var ZYGameTool = require('GameTool');
  10. var Blast = require('Blast');
  11. cc.Class({
  12. "extends": require("ZY_GameLayer"),
  13. properties: {
  14. touchLayer: cc.Node,
  15. //触摸Layer
  16. clipDraw: cc.Node,
  17. //棋盘绘制节点
  18. clipDrawTemp: cc.Node,
  19. //棋盘绘制节点
  20. propNode: {
  21. tooltip: '道具',
  22. type: cc.Node,
  23. "default": []
  24. },
  25. leveNumLabel: cc.Label,
  26. //当前关卡
  27. targetScoreLabel: cc.Label,
  28. //目标分数
  29. scoreLabel: cc.Label,
  30. //当前分数
  31. coinNumLabel: cc.Label,
  32. //金币
  33. propTipNode: cc.Node,
  34. pauseBtn: cc.Node,
  35. gameEndLayer: cc.Prefab,
  36. labelTip: cc.Prefab,
  37. maskLayer: cc.Prefab,
  38. bombSpine: cc.Prefab,
  39. scoreNum: cc.Prefab,
  40. BLAST_PREFAB: {
  41. tooltip: '爆炸特效预制体',
  42. type: cc.Prefab,
  43. "default": null
  44. },
  45. topBg: cc.Node,
  46. isCanPauseTouch: true,
  47. isInitChessBg: false
  48. },
  49. onLoad: function onLoad() {
  50. if (!Module.GameManager) Module.GameManager = this;
  51. this.node.getChildByName("chessBg").getChildByName("Bg").scale = 0;
  52. },
  53. start: function start() {
  54. this.setGameState(GameState.STATE_STOP);
  55. zy.stopBgMusic();
  56. this.clipDraw.active = false;
  57. this.topBg.active = false;
  58. this.schedule(this.dataUpdate, 0.1);
  59. this.init();
  60. this.initData();
  61. this.initTouchLayer(); // this.retainScoreMotion(8, 10, 3.0); //奖励多少分
  62. this.node.runAction(cc.sequence(new cc.delayTime(0.9), cc.callFunc(function () {
  63. this.starDrop();
  64. }.bind(this)))); // this.gameFaild();
  65. //游戏顶部全面屏适配
  66. this.node.runAction(cc.sequence(cc.delayTime(0.01), cc.callFunc(function () {
  67. if (WINSIZE.width / WINSIZE.height < 0.53) {
  68. this.topBg.parent.y -= 60;
  69. this.node.getChildByName("btnNode").y -= 60;
  70. }
  71. this.topBg.active = true;
  72. this.topBg.y = this.topBg.y + 200;
  73. this.topBg.runAction(cc.moveBy(0.2, cc.v2(0, -200)));
  74. }.bind(this))));
  75. cc.game.on(cc.game.EVENT_HIDE, function () {
  76. if (!this.isCanPauseTouch) {
  77. gameLocalData.dataClear();
  78. } else {
  79. gameLocalData.save();
  80. }
  81. console.log("游戏进入后台", this.isCanPauseTouch); // gameLocalData.dataClear();
  82. // this.onHideGame();//处理游戏切到后台时的事件
  83. }, this);
  84. cc.game.on(cc.game.EVENT_SHOW, function () {
  85. console.log("重新返回游戏"); // this.onShowGame();//处理游戏切回前台时的事件
  86. }, this);
  87. },
  88. /**
  89. * 更新Label数据
  90. */
  91. dataUpdate: function dataUpdate() {
  92. this.leveNumLabel.string = this.getLevel().toString();
  93. this.targetScoreLabel.string = this.getTarget().toString();
  94. this.scoreLabel.string = this.getScore().toString();
  95. this.coinNumLabel.string = ZYGameTool.getInstance().getCoin().toString();
  96. },
  97. init: function init() {
  98. this.BANER_HEIGHT = 180;
  99. heightoffest = this.BANER_HEIGHT + 10;
  100. if (WINSIZE.width / WINSIZE.height < 0.53) {
  101. heightoffest += 45;
  102. console.log("iphoneX");
  103. }
  104. this.coinNumLabel.string = coinNum.toString();
  105. this._guide = ZYGameTool.getInstance().getIntegerForKey(localDataItem.gameGuide, 1);
  106. this._guide = this._guide === 1 ? true : false;
  107. this._guidenumber = -1;
  108. if (this._guide) {
  109. this.showHelpLayer();
  110. }
  111. this.initBtn(); //棋盘背景动画
  112. // this.node.getChildByName("chessBg").getChildByName("Bg").scaleY = 1;
  113. // this.node.getChildByName("chessBg").getChildByName("Bg").runAction(cc.sequence(cc.delayTime(0.3), cc.scaleTo(0.5, 1)));
  114. this.initProp();
  115. },
  116. showHelpLayer: function showHelpLayer() {
  117. cc.game.emit(GameEvent.EventType.GANE_HELP);
  118. },
  119. initBtn: function initBtn() {
  120. //暂停按钮
  121. this.pauseBtn.on('click', function (event) {
  122. this.pauseClick();
  123. }.bind(this));
  124. },
  125. pauseClick: function pauseClick() {
  126. if (!this.isCanPauseTouch) return;
  127. this.node.runAction(cc.sequence(cc.delayTime(0.1), cc.callFunc(function () {
  128. gameLocalData.save(this);
  129. }.bind(this))));
  130. cc.game.emit(GameEvent.EventType.GANE_PAUSE);
  131. },
  132. initProp: function initProp() {
  133. // this.propTipNode.active = true;
  134. for (var i = 0; i < 2; i++) {
  135. this._propNode[i] = this.propNode[i];
  136. this._propmotion[i] = this.propNode[i].getChildByName("effect");
  137. this._proptipsp[i] = this.propTipNode.getChildByName("propTip" + (i + 1));
  138. }
  139. },
  140. initChess: function initChess() {
  141. this.isInitChessBg = true;
  142. this.node.getChildByName("chessBg").y += heightoffest - 10;
  143. this.node.getChildByName("chessBg").getChildByName("Bg").scale = 1;
  144. this.clipDraw.active = true;
  145. },
  146. /**
  147. * 恢复上次存档
  148. */
  149. setLastData: function setLastData() {
  150. gameLocalData.getSaveData();
  151. var lastdata = gameLocalData;
  152. if (lastdata._issaved) {
  153. this._firstsavein = true;
  154. this.setLevel(lastdata._level);
  155. this.setScore(lastdata._score);
  156. this.setTarget(lastdata._target);
  157. this._lastLevelScore = lastdata._lastscore;
  158. var chessinfo = lastdata._chesspad;
  159. for (var i = 0; i < STAR_WIDTH; i++) {
  160. for (var j = 0; j < STAR_HEIGHT; j++) {
  161. if (parseInt(chessinfo[i * STAR_HEIGHT + j]) > 0) {
  162. this._chessInfo[i * STAR_HEIGHT + j] = parseInt(chessinfo[i * STAR_HEIGHT + j]);
  163. }
  164. }
  165. }
  166. this.node.runAction(cc.sequence(cc.delayTime(1.5), cc.callFunc(function () {
  167. this.handleHandle();
  168. }.bind(this))));
  169. }
  170. },
  171. /**
  172. * 初始化数据信息
  173. */
  174. initData: function initData() {
  175. this._candealwith = true;
  176. this.setLevel(1);
  177. this.setScore(0);
  178. this.setTarget(this.getTargetScoreByRound(1));
  179. this._lastLevelScore = 0;
  180. for (var i = 0; i < STAR_WIDTH; i++) {
  181. for (var j = 0; j < STAR_HEIGHT; j++) {
  182. this._chessInfo[i * STAR_HEIGHT + j] = 0;
  183. }
  184. }
  185. this._selectbox = [];
  186. this._eliminateNum = 0;
  187. this._eliminatePos = [];
  188. this.setLastData();
  189. },
  190. /**
  191. * 分数算法
  192. * @param level
  193. * @returns {number}
  194. */
  195. getTargetScoreByRound: function getTargetScoreByRound(level) {
  196. var targetscore = 0;
  197. if (level == 1) targetscore = 1000;else targetscore = 10 * level * level + 1950 * level - 1440;
  198. return targetscore;
  199. },
  200. /**
  201. * 设置游戏状态
  202. * @param state
  203. */
  204. setGameState: function setGameState(state) {
  205. this._gamestate = state;
  206. },
  207. /**
  208. * 生成棋盘
  209. */
  210. starDrop: function starDrop() {
  211. this.isCanPauseTouch = true;
  212. this.setGameState(GameState.STATE_STOP);
  213. this._max = this.getTarget() - this.score;
  214. cc.game.emit(GameEvent.EventType.GAME_PROGRESS, 0);
  215. if (!this._firstsavein) {
  216. for (var i = 0; i < STAR_WIDTH; i++) {
  217. for (var j = 0; j < STAR_HEIGHT; j++) {
  218. var color = zy.randNum(1, 5);
  219. this._chessInfo[i * STAR_HEIGHT + j] = color;
  220. }
  221. }
  222. }
  223. var time = this.chessAppear(6); //zy.randNum(1, 6)
  224. console.log("time: ", time);
  225. this.node.runAction(new cc.sequence(new cc.delayTime(time), new cc.callFunc(function () {
  226. this.setGameState(GameState.STATE_RUN);
  227. }.bind(this))));
  228. },
  229. /**
  230. * 棋盘出现特效
  231. * @param val 特效类型
  232. * @returns {number}
  233. */
  234. chessAppear: function chessAppear(val) {
  235. if (!this.isInitChessBg) this.initChess();
  236. var time = [0.1 * STAR_HEIGHT + 0.3, 0.4, 0.4, 1.1, 0.2, 0.3, 0.6, 0.02 * STAR_HEIGHT * STAR_WIDTH + 0.25];
  237. for (var i = 0; i < STAR_WIDTH; i++) {
  238. for (var j = 0; j < STAR_HEIGHT; j++) {
  239. var id = this._chessInfo[i * STAR_HEIGHT + j];
  240. if (id > 0) {
  241. var box = zy.getSprite("game/star/starchess" + id);
  242. box.setScale(STAR_CHESS_SCALE);
  243. this.clipDraw.addChild(box, CHESSMAN_LEVEL, this.getBoxTag(i * STAR_HEIGHT + j));
  244. var pos = this.chessPos(i, j);
  245. box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH)); // if((i*STAR_HEIGHT+j)==this._limitproptag){
  246. // box.setTexture(url_xmtg+ "res/animation/starpng/block_"+id+"_lb.png");
  247. // }
  248. if (val == 0) {
  249. box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH));
  250. box.runAction(cc.sequence(cc.delayTime(j * 0.1 + zy.randNum(0, 9) * 0.01), cc.moveBy(0.2, cc.v2(0, -STAR_SIZE_WIDTH * STAR_HEIGHT))));
  251. } else if (val == 1) {
  252. box.setPosition(cc.v2(pos.x - STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  253. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  254. } else if (val == 2) {
  255. box.setPosition(cc.v2(pos.x + STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  256. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  257. } else if (val == 3) {
  258. box.setPosition(pos);
  259. box.opacity = 0;
  260. box.runAction(cc.sequence(cc.delayTime(0), cc.fadeIn(1.0)));
  261. } else if (val == 4) {
  262. if (i < STAR_WIDTH / 2.0) {
  263. box.setPosition(cc.v2(pos.x - STAR_WIDTH * STAR_SIZE_WIDTH / 2.0, pos.y));
  264. } else {
  265. box.setPosition(cc.v2(pos.x + STAR_WIDTH * STAR_SIZE_WIDTH / 2.0, pos.y));
  266. }
  267. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  268. } else if (val == 5) {
  269. if (j < STAR_HEIGHT / 2.0) {
  270. box.setPosition(cc.v2(pos.x, pos.y - STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0));
  271. } else {
  272. box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0));
  273. }
  274. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  275. } else if (val == 6) {
  276. var k = 1;
  277. if (j % 2 == 0) k = -1;
  278. box.setPosition(cc.v2(pos.x + k * STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  279. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.5, pos)));
  280. }
  281. }
  282. }
  283. }
  284. return time[val];
  285. },
  286. chessPos: function chessPos(i, j) {
  287. return cc.v2(WINSIZE.width / 2.0 + (i + 0.5 - STAR_WIDTH / 2.0) * STAR_SIZE_WIDTH, heightoffest + (j + 0.5) * STAR_SIZE_WIDTH);
  288. },
  289. /**
  290. * 获取游戏状态
  291. * @returns {number}
  292. */
  293. getGameState: function getGameState() {
  294. return this._gamestate;
  295. },
  296. /**
  297. * 初始化监听层
  298. */
  299. initTouchLayer: function initTouchLayer() {
  300. this.touchLayer.on(cc.Node.EventType.TOUCH_START, this.onTouchBegan.bind(this), this);
  301. this.touchLayer.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoved.bind(this), this);
  302. this.touchLayer.on(cc.Node.EventType.TOUCH_END, this.onTouchEnded.bind(this), this);
  303. this.touchLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnded.bind(this), this);
  304. },
  305. txtTip: function txtTip(str) {
  306. var labelTip = cc.instantiate(this.labelTip);
  307. labelTip.parent = this.node;
  308. labelTip.scale = 0.7;
  309. labelTip.setPosition(cc.v2(0, 0));
  310. labelTip.getComponent(cc.Label).string = str.toString();
  311. labelTip.runAction(cc.sequence(cc.moveBy(0.5, cc.v2(0, WINSIZE.height / 2 - 50)), cc.delayTime(1.2), cc.removeSelf(true)));
  312. return labelTip;
  313. },
  314. /**
  315. * 打开提示界面
  316. */
  317. openTip: function openTip() {
  318. cc.game.emit(GameEvent.EventType.GAME_TIP);
  319. },
  320. /**
  321. * 开始监听
  322. * @param event
  323. * @returns {boolean}
  324. */
  325. onTouchBegan: function onTouchBegan(event) {
  326. cc.log("onTouchBegan");
  327. var position = event.getLocation();
  328. var target = this;
  329. if (target.getGameState() != GameState.STATE_RUN) {
  330. return false;
  331. }
  332. target._firstsavein = false;
  333. var k = target.propTouch(position);
  334. if (k > 0 && target._eliminateNum == 0) {
  335. if (PROPPRICE[k - 1] > coinNum) {
  336. this._selectprop = 0; // this.txtTip("金币不足");
  337. this.showPropTip(0);
  338. this.openTip();
  339. return false;
  340. }
  341. target.propMotion(k);
  342. return true;
  343. }
  344. if (position.x >= 0 && position.x < WINSIZE.width && position.y >= heightoffest && position.y <= heightoffest + STAR_SIZE_WIDTH * STAR_HEIGHT) {
  345. var pos = target.chessPt(position);
  346. if (target._chessInfo[pos.x * STAR_HEIGHT + pos.y] && ZYGameTool.getInstance().posIndexOf(target._eliminatePos, pos) == -1) {
  347. // if (target._selectprop == 2) target._selectprop =4 ;
  348. var temp = true;
  349. var vec = [];
  350. if (target._selectprop == 1 || target._selectprop == 2) {
  351. temp = target.propProcess(target._selectprop - 1, pos); // if(target._guide){
  352. // target.removeChildByTag(TIPFONTTAG);
  353. // target._guidenumber++;
  354. // }
  355. } else if (target._selectprop == 0) {
  356. target.boxTip(pos, vec);
  357. }
  358. var selectnumber = vec.length;
  359. if (selectnumber > 1 || target._selectprop > 0 && temp) {
  360. target.endTip();
  361. var ft = 0.0;
  362. if (target._selectprop > 0) {// ELSGameLogic.getInstance().gameCount("item","prop_"+target._selectprop);
  363. }
  364. if (target._selectprop == 0) {
  365. target._eliminateNum++;
  366. target.boxEliminate(vec);
  367. ft = boxremovesingletime * selectnumber + cleardelaytime;
  368. } else if (target._selectprop == 1) {
  369. ft = boxremovesingletime + 0.9;
  370. } else if (target._selectprop == 2) {
  371. ft = target._selectbox.length * 0.15;
  372. target.useProps4(pos);
  373. }
  374. if (target._selectprop == 1 || target._selectprop == 2) {
  375. target.setGameState(GameState.STATE_STOP);
  376. target.node.runAction(cc.sequence(cc.delayTime(ft), cc.callFunc(function () {
  377. target.touchHandle();
  378. }.bind(target))));
  379. target._selectprop = 0;
  380. target._selectbox = [];
  381. }
  382. }
  383. }
  384. return true;
  385. }
  386. return false;
  387. },
  388. //获取道具坐标
  389. propTouch: function propTouch(pos) {
  390. for (var i = 0; i < 2; i++) {
  391. if (this._propNode[i].getBoundingBoxToWorld().contains(pos)) return i + 1;
  392. }
  393. return 0;
  394. },
  395. //获取道具位置
  396. getPropPos: function getPropPos(key) {
  397. if (key > 0 && key < 2) {
  398. return this._propNode[key - 1].parent.convertToWorldSpaceAR(this._propNode[key - 1].getPosition());
  399. }
  400. return cc.v2(0, 0);
  401. },
  402. useProps4: function useProps4(pos) {
  403. // var maskLayer = cc.instantiate(this.maskLayer);
  404. // maskLayer.zIndex = 99;
  405. // maskLayer.parent = this.node.parent;
  406. // this.clipDrawTemp.zIndex = 100;
  407. this.node.getChildByName("maskLayer").active = true; // this.node.getChildByName("maskLayer").zIndex = 99;
  408. var tempk = this._selectbox[0];
  409. for (var i in this._selectbox) {
  410. if (this._selectbox[i].x == pos.x && this._selectbox[i].y == pos.y) {
  411. this._selectbox[i].x = tempk.x;
  412. this._selectbox[i].y = tempk.y;
  413. this._selectbox[0].x = pos.x;
  414. this._selectbox[0].y = pos.y;
  415. break;
  416. }
  417. }
  418. var selectbox = this._selectbox.slice(1, this._selectbox.length);
  419. selectbox.sort(function (a, b) {
  420. return Math.random() > 0.5 ? -1 : 1;
  421. });
  422. selectbox.splice(0, 0, this._selectbox[0]);
  423. var actions = [];
  424. for (var i = 0; i < selectbox.length; i++) {
  425. var key1 = selectbox[i];
  426. var node = this.getClipItem(key1.x * STAR_HEIGHT + key1.y);
  427. node.index = 101;
  428. actions.push(cc.callFunc(function (target, key) {
  429. this.addParticle(key);
  430. this.removeBox(key);
  431. }.bind(this), this, key1));
  432. if (i == selectbox.length - 1) {
  433. break;
  434. }
  435. var key2 = selectbox[i + 1];
  436. var position1 = this.chessPos(key1.x, key1.y);
  437. var position2 = this.chessPos(key2.x, key2.y);
  438. actions.push(cc.callFunc(function (target, data) {
  439. // var line=new cc.Sprite(starpng[wb.randNum(14,18)]);
  440. var line = zy.getSprite("game/prop/starprope" + zy.randNum(1, 5));
  441. line.setAnchorPoint(cc.v2(0, 0.5));
  442. var length = Math.sqrt(Math.abs(data.pos1.x - data.pos2.x) * Math.abs(data.pos1.x - data.pos2.x) + Math.abs(data.pos1.y - data.pos2.y) * Math.abs(data.pos1.y - data.pos2.y));
  443. var wid = 70;
  444. var lengthscale = length * 1.0 / wid;
  445. line.scaleX = 0.06 * lengthscale;
  446. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
  447. line.runAction(cc.sequence(cc.scaleTo(0.1, 1.0 * lengthscale, 1.5), cc.scaleTo(0.25, 1.0 * lengthscale, 0.06 * 1.5), cc.callFunc(function () {
  448. line.removeFromParent();
  449. })));
  450. line.setPosition(data.pos1);
  451. var angle1 = Math.atan2(data.pos2.y - data.pos1.y, data.pos2.x - data.pos1.x);
  452. var angle = -1 * cc.misc.radiansToDegrees(angle1);
  453. line.setRotation(angle);
  454. this.clipDrawTemp.addChild(line, 102);
  455. var score = this.getScoreByNum(1);
  456. this.updateScore(score);
  457. }.bind(this), this, {
  458. pos1: position1,
  459. pos2: position2
  460. }));
  461. actions.push(cc.delayTime(0.15));
  462. }
  463. actions.push(cc.callFunc(function () {
  464. // maskLayer.removeFromParent();
  465. this.node.getChildByName("maskLayer").active = false;
  466. this.clipDrawTemp.removeAllChildren(true);
  467. this.showPropTip(0);
  468. }.bind(this)));
  469. this.node.runAction(cc.sequence(actions));
  470. },
  471. //使用道具
  472. propProcess: function propProcess(id, pos, key) {
  473. if (!pos) {
  474. pos = cc.v2(0, 0);
  475. }
  476. if (!key) {
  477. key = 1;
  478. }
  479. if (this._selectprop > 0) {
  480. this.showPropMotion(this._selectprop, 0);
  481. } //
  482. if (key == 1) {
  483. console.log("id: ", id);
  484. if (PROPPRICE[id] > coinNum) {
  485. this._selectprop = 0;
  486. this.txtTip();
  487. return false;
  488. } else {
  489. //使用道具扣除金币
  490. this.txtTip("Use props to deduct gold coins " + PROPPRICE[id]);
  491. ZYGameTool.getInstance().useCoin(-PROPPRICE[id]);
  492. }
  493. }
  494. if (id == 1) {
  495. var key = this.getChessInfo(pos);
  496. console.log("---key--: ", key);
  497. for (var i = 0; i < STAR_WIDTH; i++) {
  498. for (var j = 0; j < STAR_HEIGHT; j++) {
  499. if (key == this.getChessInfo(cc.v2(i, j))) {
  500. this._selectbox.push(cc.v2(i, j));
  501. }
  502. }
  503. }
  504. } else if (id == 0) {
  505. // if(id==0){
  506. var ssp = zy.getSprite("game/prop/prop1");
  507. this.clipDraw.addChild(ssp, 1000);
  508. ssp.setPosition(this.getPropPos(1));
  509. var v1 = ssp.getPosition();
  510. var tempv = this.chessPos(pos.x, pos.y);
  511. var v2 = cc.v2(tempv.x + 10, tempv.y - 10);
  512. var v3 = cc.v2(0, 0);
  513. if (v2.x < WINSIZE.width / 2) v3 = cc.v2(v1.x + 200, v1.y - 100);else v3 = cc.v2(v1.x + 200, v1.y + 100);
  514. var bezierpath = [v1, v3, v2];
  515. var bezier = cc.bezierTo(0.7, bezierpath);
  516. var bombSpine = this.createBombSpine(tempv, this.clipDraw);
  517. bombSpine.active = false;
  518. var bombAction = cc.callFunc(function () {
  519. bombSpine.active = true;
  520. });
  521. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 6); //消除个数
  522. ssp.runAction(cc.sequence(bezier, bombAction, cc.delayTime(0.2), cc.callFunc(function (target, tempv) {
  523. bombSpine.removeFromParent();
  524. ssp.removeFromParent();
  525. }.bind(this), this, tempv)));
  526. ssp.runAction(cc.scaleTo(0.15, 1.5));
  527. this.node.runAction(cc.sequence(cc.delayTime(0.7), cc.callFunc(function (target, pos) {
  528. this.node.runAction(cc.sequence(cc.delayTime(0.0), cc.callFunc(function (target, pos) {
  529. var temp = 0;
  530. for (var i = pos.x - 1; i <= pos.x + 1; i++) {
  531. for (var j = pos.y - 1; j <= pos.y + 1; j++) {
  532. if (i >= 0 && i < STAR_WIDTH && j >= 0 && j < STAR_HEIGHT && this.getChessInfo(cc.v2(i, j))) {
  533. this.addParticle(cc.v2(i, j));
  534. this.removeBox(cc.v2(i, j));
  535. ++temp;
  536. }
  537. }
  538. }
  539. var score = this.getScoreByNum(temp);
  540. this.updateScore(score);
  541. }.bind(this), this, pos)));
  542. this.showPropTip(0);
  543. }.bind(this), this, pos)));
  544. }
  545. return true;
  546. },
  547. createBombSpine: function createBombSpine(pos, node, index) {
  548. if (index == undefined) index = 10000;
  549. var bombSpine = cc.instantiate(this.bombSpine);
  550. bombSpine.parent = node;
  551. bombSpine.zIndex = index;
  552. bombSpine.setPosition(pos);
  553. return bombSpine;
  554. },
  555. propMotion: function propMotion(k) {
  556. if (this._selectprop > 0) {
  557. this.showPropMotion(this._selectprop, 0);
  558. }
  559. cc.log("match touch began2", k);
  560. if (this._selectprop == k) {
  561. this._selectprop = 0;
  562. this.showPropTip(0);
  563. } else {
  564. this._selectprop = k;
  565. this.showPropTip(k);
  566. this.showPropMotion(k, 1);
  567. }
  568. },
  569. showPropTip: function showPropTip(k) {
  570. if (k == 0) {
  571. this.propTipNode.active = false;
  572. } else if (k > 0 && k < 3) {
  573. this.propTipNode.active = true;
  574. for (var i = 0; i < 2; i++) {
  575. if (i == k - 1) {
  576. this._proptipsp[i].active = true;
  577. } else {
  578. this._proptipsp[i].active = false;
  579. }
  580. }
  581. }
  582. },
  583. //道具点击动画
  584. showPropMotion: function showPropMotion(key, type) {
  585. if (type == 1) {
  586. this._propmotion[key - 1].active = true;
  587. this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.0, 1.0), cc.scaleTo(1.0, 1.5))));
  588. this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.fadeIn(0.0), cc.fadeOut(1.0))));
  589. } else if (type == 0) {
  590. this._propmotion[key - 1].active = false;
  591. this._propmotion[key - 1].stopAllActions();
  592. this._propmotion[key - 1].setScale(1.0);
  593. this._propmotion[key - 1].opacity = 255;
  594. }
  595. },
  596. getScoreByNum: function getScoreByNum(num) {
  597. var k = 5;
  598. var t = 5;
  599. for (var i = 0; i < num; i++) {
  600. k += t;
  601. t += 10;
  602. }
  603. return k;
  604. },
  605. updateScore: function updateScore(score) {
  606. this.score += score;
  607. },
  608. scoreMotion: function scoreMotion(score, pt) {
  609. var scoreNum = cc.instantiate(this.scoreNum);
  610. scoreNum.parent = this.clipDraw;
  611. scoreNum.zIndex = 10000;
  612. scoreNum.getComponent(cc.Label).string = score.toString();
  613. scoreNum.setPosition(this.chessPos(pt.x, pt.y));
  614. scoreNum.runAction(cc.sequence(cc.moveBy(1.0, cc.v2(0, STAR_SIZE_WIDTH)), cc.callFunc(function () {
  615. scoreNum.removeFromParent();
  616. })));
  617. },
  618. /**
  619. * 连消提示
  620. * @param vec
  621. */
  622. boxEliminate: function boxEliminate(vec) {
  623. var score = this.getScoreByNum(vec.length);
  624. this.updateScore(score);
  625. console.log("--score--: ", score);
  626. this.scoreMotion(score, vec[0]);
  627. if (this.getScore() >= this.getTarget() && this.getScore() - score < this.getTarget()) {
  628. this.spriteShow(zy_gxpng[0]);
  629. } else {
  630. if (vec.length == 5) {
  631. this.spriteShow("game/main_tip/great");
  632. } else if (vec.length > 5) {
  633. this.spriteShow("game/main_tip/zan");
  634. }
  635. }
  636. this.levelupmusic = 0;
  637. this.boxSequence(vec, true);
  638. var arrayOfActions = [];
  639. for (var i in vec) {
  640. if (i != "0") {
  641. arrayOfActions.push(cc.delayTime(boxremovesingletime));
  642. }
  643. var key = vec[i];
  644. arrayOfActions.push(cc.callFunc(function (target, data) {
  645. this.addParticle(data);
  646. this.removeBox(data);
  647. }.bind(this), this, key));
  648. }
  649. arrayOfActions.push(cc.delayTime(cleardelaytime));
  650. arrayOfActions.push(cc.callFunc(function () {
  651. this._eliminateNum--;
  652. if (this._eliminateNum == 0) {
  653. this._eliminatePos = [];
  654. this.setGameState(GameState.STATE_STOP);
  655. this.touchHandle();
  656. }
  657. }.bind(this)));
  658. this.node.runAction(cc.sequence(arrayOfActions));
  659. },
  660. spriteShow: function spriteShow(str) {
  661. if (str == zy_gxpng[0]) {
  662. var endpos = cc.v2(0, WINSIZE.height * Hkey - 180);
  663. var spr = zy.getSprite(str);
  664. this.node.addChild(spr, 1000, "777");
  665. spr.setPosition(cc.v2(0, 0 + heightoffest / 2.0));
  666. spr.runAction(cc.sequence(cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.scaleTo(0.2, 0.8), cc.delayTime(0.52), cc.moveTo(0.5, endpos)));
  667. spr.runAction(cc.sequence(new cc.delayTime(1.2), cc.scaleTo(0.5, 0.25), cc.callFunc(function () {
  668. spr.removeFromParent();
  669. var sp = zy.getSprite(str);
  670. sp.setScale(0.25); // this.getParent().getBackLayer().getChildByName("node").addChild(sp,10,777);
  671. this.node.addChild(spr, 12, "777");
  672. sp.setPosition(cc.v2(-170, -175));
  673. }.bind(this))));
  674. } else {
  675. this.spriteShow2(str, cc.v2(0, 0));
  676. }
  677. },
  678. spriteShow2: function spriteShow2(res, pos) {
  679. var sp = zy.getSprite(res);
  680. this.node.addChild(sp, 1000);
  681. sp.setPosition(pos);
  682. sp.setScale(1.0);
  683. if (res == "game/main_tip/xsyd") {
  684. sp.runAction(sequence(cc.moveBy(0.5, cc.v2(0, 50)), cc.delayTime(0.2), cc.fadeOut(0.3), cc.callFunc(function () {
  685. sp.removeFromParent();
  686. })));
  687. } else {
  688. sp.runAction(cc.sequence(cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.scaleTo(0.2, 0.8), cc.delayTime(0.2), cc.fadeOut(0.3), cc.callFunc(function () {
  689. sp.removeFromParent();
  690. })));
  691. }
  692. },
  693. /**
  694. * 可以消除的元素放入_eliminatePos
  695. * @param pos
  696. * @param vect
  697. */
  698. boxTip: function boxTip(pos, vect) {
  699. var vec = this.boxGet(pos);
  700. if (vec.length > 1) {
  701. for (var i in vec) {
  702. vect.push(vec[i]);
  703. this._eliminatePos.push(vec[i]);
  704. var box = this.getClipItem(vec[i].x * STAR_HEIGHT + vec[i].y);
  705. this.setBoxMotion(box, true);
  706. }
  707. }
  708. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, vect.length); //消除个数
  709. },
  710. getClipItem: function getClipItem(tag) {
  711. return this.clipDraw.getChildByName(tag.toString());
  712. },
  713. //TAG值转换为String类型
  714. getBoxTag: function getBoxTag(v) {
  715. return v.toString();
  716. },
  717. /**
  718. * 消除结束
  719. */
  720. endTip: function endTip() {
  721. this._clicktiptime = 0;
  722. for (var i in this._clicktipvec) {
  723. var key = this._clicktipvec[i];
  724. var box = this.getClipItem(key.x * STAR_HEIGHT + key.y);
  725. this.setBoxMotion(box, false);
  726. }
  727. this._clicktipvec = [];
  728. },
  729. /**
  730. * 获取可以消除的元素
  731. * @param pos
  732. * @returns {[]}
  733. */
  734. boxGet: function boxGet(pos) {
  735. var vec = [];
  736. this.boxAdd(pos, vec);
  737. return vec;
  738. },
  739. /**
  740. * 树状搜索消除元素
  741. * @param pos
  742. * @param vec
  743. */
  744. boxAdd: function boxAdd(pos, vec) {
  745. vec.push(pos); //x-1
  746. if (pos.x - 1 >= 0 && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x - 1, pos.y)) == -1 && this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x - 1, pos.y))) {
  747. this.boxAdd(cc.v2(pos.x - 1, pos.y), vec);
  748. } //x+1
  749. if (pos.x + 1 < STAR_WIDTH && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x + 1, pos.y)) == -1 && this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x + 1, pos.y))) {
  750. this.boxAdd(cc.v2(pos.x + 1, pos.y), vec);
  751. } //y-1
  752. if (pos.y - 1 >= 0 && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x, pos.y - 1)) == -1 && this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x, pos.y - 1))) {
  753. this.boxAdd(cc.v2(pos.x, pos.y - 1), vec);
  754. } //y+1
  755. if (pos.y + 1 < STAR_HEIGHT && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x, pos.y + 1)) == -1 && this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x, pos.y + 1))) {
  756. this.boxAdd(cc.v2(pos.x, pos.y + 1), vec);
  757. }
  758. },
  759. /**
  760. * 星星消除给个动作
  761. * @param box
  762. * @param b
  763. */
  764. setBoxMotion: function setBoxMotion(box, b) {
  765. if (box) {
  766. if (b) {
  767. box.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1.0, 0.89), cc.scaleTo(1.0, 1.0))));
  768. } else {
  769. box.stopAllActions();
  770. box.setScale(1.0);
  771. }
  772. }
  773. },
  774. /**
  775. * 通过坐标找到目标对象
  776. * @param pos
  777. * @returns {cc.Vec2}
  778. */
  779. chessPt: function chessPt(pos) {
  780. var x = parseInt((pos.x - WINSIZE.width / 2.0) / STAR_SIZE_WIDTH + STAR_WIDTH / 2.0);
  781. var y = parseInt((pos.y - heightoffest) / STAR_SIZE_WIDTH);
  782. return cc.v2(x, y);
  783. },
  784. touchHandle: function touchHandle() {
  785. var time = 0.0;
  786. if (this.chessMove()) {
  787. time += chessmovetime;
  788. }
  789. this.node.runAction(cc.sequence(cc.delayTime(time), cc.callFunc(function () {
  790. if (this._candealwith) {
  791. this.handleHandle();
  792. }
  793. }.bind(this))));
  794. },
  795. handleHandle: function handleHandle() {
  796. if (this.chessCanEliminate()) {
  797. this.setGameState(GameState.STATE_RUN);
  798. } else {
  799. this.node.runAction(cc.sequence(cc.delayTime(0.5), new cc.callFunc(function () {
  800. this.chessClear();
  801. }.bind(this))));
  802. }
  803. },
  804. chessClear: function chessClear() {
  805. this.isCanPauseTouch = false;
  806. var eliminatebox = [];
  807. for (var i = 0; i < STAR_WIDTH; i++) {
  808. for (var j = 0; j < STAR_HEIGHT; j++) {
  809. if (this.getChessInfo(cc.v2(i, j))) {
  810. eliminatebox.push(cc.v2(i, j));
  811. }
  812. }
  813. }
  814. if (eliminatebox.length > 0) {
  815. eliminatebox.sort(function (a, b) {
  816. return Math.random() > 0.5 ? -1 : 1;
  817. });
  818. }
  819. this.levelupmusic = 0;
  820. this.boxSequence(eliminatebox, false);
  821. var num = this.getRetainScore(eliminatebox.length);
  822. this.updateScore(num); // ELSGameData.getInstance().setDayHighScore(this._score,num);
  823. this.scoreMotion(num, cc.v2(WINSIZE.width / 2, WINSIZE.height / 2)); // ELSGameLogic.getInstance().showHyRank(this._score,false);
  824. var ftime = this.smallPeopleCollect(eliminatebox);
  825. this.retainScoreMotion(eliminatebox.length, num, 3.0); //奖励多少分
  826. var ft = Math.max(ftime, 3);
  827. if (this.getScore() > this.getTarget() && this.getScore() - num < this.getTarget()) {
  828. this.spriteShow(zy_gxpng[0]);
  829. } // gameLocalData.save(this);
  830. this.node.runAction(cc.sequence(cc.delayTime(ft), new cc.callFunc(function () {
  831. this.gameEnd();
  832. }.bind(this))));
  833. },
  834. retainScoreMotion: function retainScoreMotion(number, score, ft) {
  835. var fnt1 = cc.instantiate(this.labelTip);
  836. fnt1.zIndex = 100;
  837. fnt1.parent = this.node;
  838. fnt1.getComponent(cc.Label).string = "reward " + score + "score";
  839. fnt1.x = -(WINSIZE.width / 2 + 100);
  840. fnt1.y = heightoffest * 0.5;
  841. fnt1.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.2, cc.v2(0, heightoffest * 0.5))));
  842. var fnt2 = cc.instantiate(this.labelTip);
  843. fnt2.zIndex = 100;
  844. fnt2.parent = this.node;
  845. fnt2.getComponent(cc.Label).string = "surplus " + number + "blocks";
  846. fnt2.x = -(WINSIZE.width / 2 + 100);
  847. fnt2.y = heightoffest * 0.5 - 100;
  848. fnt2.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.2, cc.v2(0, heightoffest * 0.5 - 100)), cc.delayTime(ft - 0.2), cc.callFunc(function () {
  849. fnt1.removeFromParent();
  850. fnt2.removeFromParent();
  851. })));
  852. },
  853. /**
  854. * 游戏结束
  855. */
  856. gameEnd: function gameEnd() {
  857. // this.isCanPauseTouch = true;
  858. cc.game.emit(GameEvent.EventType.GAME_PASS_STAGE); //消除个数
  859. //闯关失败
  860. if (this.getScore() < this.getTarget()) {
  861. // this.gameFaild();
  862. cc.game.emit(GameEvent.EventType.GANE_FAIL); // cc.director.loadScene("homeScene");
  863. } else {
  864. //闯关成功
  865. // this.LevelUpMotion();
  866. if (this.getScore() >= this.getTarget()) {
  867. this.spriteShow(zy_gxpng[0]);
  868. }
  869. this.setLevel(this.getLevel() + 1);
  870. this.setTarget(this.getTargetScoreByRound(this.getLevel()));
  871. this._lastLevelScore = this.getScore();
  872. this.node.runAction(cc.sequence(cc.delayTime(0.8), cc.callFunc(function () {
  873. this._firstsavein = false;
  874. this.starDrop();
  875. }.bind(this))));
  876. }
  877. },
  878. clearData: function clearData() {
  879. this.score = 0;
  880. this._lastLevelScore = 0;
  881. this.level = 1;
  882. this.target = 0;
  883. this.hang = 0;
  884. this.chessInfo = []; //记录棋盘元素的颜色类型
  885. this._selectbox = [];
  886. this._eliminatePos = []; //消除
  887. this._eliminateNum = 0;
  888. this._clicktipvec = [];
  889. this._candealwith = true;
  890. this._limitproptag = -1;
  891. this._clicktiptime = 0;
  892. this._selectprop = 0;
  893. this.propNode = [];
  894. this._propmotion = [];
  895. this._proptipsp = [];
  896. this._firstsavein = false;
  897. },
  898. smallPeopleCollect: function smallPeopleCollect(vec) {
  899. var tt = cleardelaytime;
  900. var action = [];
  901. for (var i in vec) {
  902. var pos = vec[i];
  903. action.push(cc.callFunc(function (target, pos) {
  904. this.addParticle(pos, 2);
  905. this.removeBox(pos, 1);
  906. }.bind(this), this, pos));
  907. action.push(cc.delayTime(boxremovesingletime));
  908. tt += boxremovesingletime;
  909. }
  910. if (action.length > 0) {
  911. this.node.runAction(cc.sequence(action));
  912. }
  913. return tt;
  914. },
  915. addParticle: function addParticle(pos, key) {
  916. if (!key) key = 1;
  917. if (key == 1) this.addFkLizi(this.clipDraw, this.chessPos(pos.x, pos.y), this.getChessInfo(pos) - 1, 1.0, 2);else this.addFkLizi(this.clipDraw, this.chessPos(pos.x, pos.y), 5, 1.0, 2);
  918. },
  919. removeBox: function removeBox(pos, tag) {
  920. if (!tag) {
  921. tag = 2;
  922. }
  923. var node = this.getClipItem(pos.x * STAR_HEIGHT + pos.y);
  924. if (node && node.isValid) node.removeFromParent();
  925. this.setChessInfo(pos, 0);
  926. this.levelupmusic++;
  927. },
  928. /**
  929. * 星星粒子特效
  930. * @param node
  931. * @param pos
  932. * @param idx
  933. * @param scale
  934. * @param type
  935. */
  936. addFkLizi: function addFkLizi(node, pos, idx, scale, type) {
  937. if (!type) type = 1;
  938. if (!scale) scale = 1.0; // var spname=chesspng[idx];
  939. var spname = "";
  940. if (type == 2) {
  941. if (idx == 5) spname = "game/lizi/starpar2";else spname = "game/lizi/starpar" + (3 + idx);
  942. } else if (type == 3) {
  943. spname = "game/lizi/starpar1";
  944. }
  945. if (idx == 5) {
  946. this.blast(5, pos, zy.randNum(0, 4));
  947. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
  948. } else {
  949. this.blast(5, pos, idx);
  950. }
  951. },
  952. blast: function blast(score, pos, index) {
  953. var node = Blast.pool.get();
  954. if (!node) {
  955. node = cc.instantiate(this.BLAST_PREFAB);
  956. }
  957. node.position = pos;
  958. node.getComponent(this.BLAST_PREFAB.name).run(score, index);
  959. node.zIndex = 100; // node.scale = this.node.scale;
  960. node.parent = this.clipDraw;
  961. },
  962. getRetainScore: function getRetainScore(number) {
  963. var score = 1500;
  964. for (var i = 1; i <= number; i++) {
  965. score -= 30 * i - 15;
  966. }
  967. if (score < 0) score = 0;
  968. return score;
  969. },
  970. boxSequence: function boxSequence(vec, sx) {
  971. var k = vec.length;
  972. if (k > 0) {
  973. for (var i = 0; i < k; i++) {
  974. for (var j = k - 1; j > i; j--) {
  975. if (sx) {
  976. if (this.getnum(vec[j]) < this.getnum(vec[j - 1])) {
  977. var temp = vec[j];
  978. vec[j] = vec[j - 1];
  979. vec[j - 1] = temp;
  980. }
  981. } else {
  982. if (this.getrenum(vec[j]) < this.getrenum(vec[j - 1])) {
  983. var temp = vec[j];
  984. vec[j] = vec[j - 1];
  985. vec[j - 1] = temp;
  986. }
  987. }
  988. }
  989. }
  990. }
  991. },
  992. getnum: function getnum(pos) {
  993. return pos.x * STAR_HEIGHT + pos.y;
  994. },
  995. getrenum: function getrenum(pos) {
  996. return pos.x * STAR_HEIGHT + (STAR_HEIGHT - pos.y);
  997. },
  998. chessCanEliminate: function chessCanEliminate() {
  999. for (var i = 0; i < STAR_WIDTH; i++) {
  1000. for (var j = 0; j < STAR_HEIGHT; j++) {
  1001. if (this.singelCanEliminate(cc.v2(i, j))) {
  1002. return true;
  1003. }
  1004. }
  1005. }
  1006. return false;
  1007. },
  1008. chessMove: function chessMove() {
  1009. var temp = false;
  1010. var downstep = [];
  1011. var step = 0;
  1012. for (var i = 0; i < STAR_WIDTH; i++) {
  1013. step = 0;
  1014. for (var j = 0; j < STAR_HEIGHT; j++) {
  1015. if (this.getChessInfo(cc.v2(i, j)) == 0) {
  1016. step++;
  1017. } else if (step > 0) {
  1018. temp = true;
  1019. var box = this.getClipItem(i * STAR_HEIGHT + j);
  1020. if (box) {
  1021. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.15, this.chessPos(i, j - step)))); // box.setTag(i*STAR_HEIGHT+(j-step));
  1022. box.name = this.getBoxTag(i * STAR_HEIGHT + (j - step));
  1023. if (i * STAR_HEIGHT + j == this._limitproptag) {
  1024. this._limitproptag = i * STAR_HEIGHT + (j - step);
  1025. }
  1026. this.setChessInfo(cc.v2(i, j - step), this.getChessInfo(cc.v2(i, j)));
  1027. this.setChessInfo(cc.v2(i, j), 0);
  1028. }
  1029. }
  1030. }
  1031. }
  1032. step = 0;
  1033. for (var i = 0; i < STAR_WIDTH; i++) {
  1034. if (this.getChessInfo(cc.v2(i, 0)) == 0) {
  1035. step++;
  1036. } else if (step > 0) {
  1037. for (var j = 0; j < STAR_HEIGHT; j++) {
  1038. if (this.getChessInfo(cc.v2(i, j))) {
  1039. temp = true;
  1040. var box = this.getClipItem(i * STAR_HEIGHT + j);
  1041. if (box) {
  1042. box.runAction(cc.sequence(new cc.delayTime(0.1), new cc.moveBy(0.05, cc.v2(-step * STAR_SIZE_WIDTH, 0)))); // box.setTag((i-step)*STAR_HEIGHT+j);
  1043. box.name = this.getBoxTag((i - step) * STAR_HEIGHT + j);
  1044. this.setChessInfo(cc.v2(i - step, j), this.getChessInfo(cc.v2(i, j)));
  1045. this.setChessInfo(cc.v2(i, j), 0);
  1046. if (i * STAR_HEIGHT + j == this._limitproptag) {
  1047. this._limitproptag = (i - step) * STAR_HEIGHT + j;
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. return temp;
  1055. },
  1056. hessCanEliminate: function hessCanEliminate() {
  1057. for (var i = 0; i < STAR_WIDTH; i++) {
  1058. for (var j = 0; j < STAR_HEIGHT; j++) {
  1059. if (this.singelCanEliminate(cc.v2(i, j))) {
  1060. return true;
  1061. }
  1062. }
  1063. }
  1064. return false;
  1065. },
  1066. singelCanEliminate: function singelCanEliminate(pos) {
  1067. var i = pos.x;
  1068. var j = pos.y;
  1069. var key = this.getChessInfo(pos);
  1070. if (key > 0) {
  1071. if (i - 1 >= 0 && key == this.getChessInfo(cc.v2(i - 1, j))) {
  1072. return true;
  1073. }
  1074. if (i + 1 < STAR_WIDTH && key == this.getChessInfo(cc.v2(i + 1, j))) {
  1075. return true;
  1076. }
  1077. if (j - 1 >= 0 && key == this.getChessInfo(cc.v2(i, j - 1))) {
  1078. return true;
  1079. }
  1080. if (j + 1 < STAR_HEIGHT && key == this.getChessInfo(cc.v2(i, j + 1))) {
  1081. return true;
  1082. }
  1083. }
  1084. return false;
  1085. },
  1086. setChessInfo: function setChessInfo(pos, key) {
  1087. this._chessInfo[pos.x * STAR_HEIGHT + pos.y] = key;
  1088. },
  1089. getChessInfo: function getChessInfo(pos) {
  1090. return this._chessInfo[pos.x * STAR_HEIGHT + pos.y];
  1091. },
  1092. onTouchMoved: function onTouchMoved(event) {
  1093. cc.log("onTouchMoved");
  1094. },
  1095. onTouchEnded: function onTouchEnded(event) {
  1096. cc.log("onTouchEnded");
  1097. },
  1098. resurrenction: function resurrenction() {
  1099. this.setScore(this._lastLevelScore);
  1100. this.node.runAction(new cc.Sequence(new cc.DelayTime(0.8), new cc.CallFunc(function () {
  1101. this.starDrop();
  1102. }.bind(this))));
  1103. },
  1104. // update (dt) {},
  1105. onDestroy: function onDestroy() {
  1106. //关闭所有音乐、音效
  1107. cc.audioEngine.stopAll(); //移除所有事件监听
  1108. cc.game.targetOff(this);
  1109. }
  1110. });
  1111. cc._RF.pop();