1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276 |
- "use strict";
- cc._RF.push(module, '0753cOzsZxNToxheAYqEHnX', 'ZY_StarManager');
- // Texture/prefab/ZY_StarManager.js
- "use strict";
- /**
- * 游戏核心部分
- */
- var GameEvent = require('GameEvent');
- var ZYGameTool = require('GameTool');
- var Blast = require('Blast');
- cc.Class({
- "extends": require("ZY_GameLayer"),
- properties: {
- touchLayer: cc.Node,
- //触摸Layer
- clipDraw: cc.Node,
- //棋盘绘制节点
- clipDrawTemp: cc.Node,
- //棋盘绘制节点
- propNode: {
- tooltip: '道具',
- type: cc.Node,
- "default": []
- },
- leveNumLabel: cc.Label,
- //当前关卡
- targetScoreLabel: cc.Label,
- //目标分数
- scoreLabel: cc.Label,
- //当前分数
- coinNumLabel: cc.Label,
- //金币
- propTipNode: cc.Node,
- pauseBtn: cc.Node,
- gameEndLayer: cc.Prefab,
- labelTip: cc.Prefab,
- maskLayer: cc.Prefab,
- bombSpine: cc.Prefab,
- scoreNum: cc.Prefab,
- BLAST_PREFAB: {
- tooltip: '爆炸特效预制体',
- type: cc.Prefab,
- "default": null
- },
- topBg: cc.Node,
- isCanPauseTouch: true,
- isInitChessBg: false
- },
- onLoad: function onLoad() {
- if (!Module.GameManager) Module.GameManager = this;
- this.node.getChildByName("chessBg").getChildByName("Bg").scale = 0;
- },
- start: function start() {
- this.setGameState(GameState.STATE_STOP);
- zy.stopBgMusic();
- this.clipDraw.active = false;
- this.topBg.active = false;
- this.schedule(this.dataUpdate, 0.1);
- this.init();
- this.initData();
- this.initTouchLayer(); // this.retainScoreMotion(8, 10, 3.0); //奖励多少分
- this.node.runAction(cc.sequence(new cc.delayTime(0.9), cc.callFunc(function () {
- this.starDrop();
- }.bind(this)))); // this.gameFaild();
- //游戏顶部全面屏适配
- this.node.runAction(cc.sequence(cc.delayTime(0.01), cc.callFunc(function () {
- if (WINSIZE.width / WINSIZE.height < 0.53) {
- this.topBg.parent.y -= 60;
- this.node.getChildByName("btnNode").y -= 60;
- }
- this.topBg.active = true;
- this.topBg.y = this.topBg.y + 200;
- this.topBg.runAction(cc.moveBy(0.2, cc.v2(0, -200)));
- }.bind(this))));
- cc.game.on(cc.game.EVENT_HIDE, function () {
- if (!this.isCanPauseTouch) {
- gameLocalData.dataClear();
- } else {
- gameLocalData.save();
- }
- console.log("游戏进入后台", this.isCanPauseTouch); // gameLocalData.dataClear();
- // this.onHideGame();//处理游戏切到后台时的事件
- }, this);
- cc.game.on(cc.game.EVENT_SHOW, function () {
- console.log("重新返回游戏"); // this.onShowGame();//处理游戏切回前台时的事件
- }, this);
- },
- /**
- * 更新Label数据
- */
- dataUpdate: function dataUpdate() {
- this.leveNumLabel.string = this.getLevel().toString();
- this.targetScoreLabel.string = this.getTarget().toString();
- this.scoreLabel.string = this.getScore().toString();
- this.coinNumLabel.string = ZYGameTool.getInstance().getCoin().toString();
- },
- init: function init() {
- this.BANER_HEIGHT = 180;
- heightoffest = this.BANER_HEIGHT + 10;
- if (WINSIZE.width / WINSIZE.height < 0.53) {
- heightoffest += 45;
- console.log("iphoneX");
- }
- this.coinNumLabel.string = coinNum.toString();
- this._guide = ZYGameTool.getInstance().getIntegerForKey(localDataItem.gameGuide, 1);
- this._guide = this._guide === 1 ? true : false;
- this._guidenumber = -1;
- if (this._guide) {
- this.showHelpLayer();
- }
- this.initBtn(); //棋盘背景动画
- // this.node.getChildByName("chessBg").getChildByName("Bg").scaleY = 1;
- // this.node.getChildByName("chessBg").getChildByName("Bg").runAction(cc.sequence(cc.delayTime(0.3), cc.scaleTo(0.5, 1)));
- this.initProp();
- },
- showHelpLayer: function showHelpLayer() {
- cc.game.emit(GameEvent.EventType.GANE_HELP);
- },
- initBtn: function initBtn() {
- //暂停按钮
- this.pauseBtn.on('click', function (event) {
- this.pauseClick();
- }.bind(this));
- },
- pauseClick: function pauseClick() {
- if (!this.isCanPauseTouch) return;
- this.node.runAction(cc.sequence(cc.delayTime(0.1), cc.callFunc(function () {
- gameLocalData.save(this);
- }.bind(this))));
- cc.game.emit(GameEvent.EventType.GANE_PAUSE);
- },
- initProp: function initProp() {
- // this.propTipNode.active = true;
- for (var i = 0; i < 2; i++) {
- this._propNode[i] = this.propNode[i];
- this._propmotion[i] = this.propNode[i].getChildByName("effect");
- this._proptipsp[i] = this.propTipNode.getChildByName("propTip" + (i + 1));
- }
- },
- initChess: function initChess() {
- this.isInitChessBg = true;
- this.node.getChildByName("chessBg").y += heightoffest - 10;
- this.node.getChildByName("chessBg").getChildByName("Bg").scale = 1;
- this.clipDraw.active = true;
- },
- /**
- * 恢复上次存档
- */
- setLastData: function setLastData() {
- gameLocalData.getSaveData();
- var lastdata = gameLocalData;
- if (lastdata._issaved) {
- this._firstsavein = true;
- this.setLevel(lastdata._level);
- this.setScore(lastdata._score);
- this.setTarget(lastdata._target);
- this._lastLevelScore = lastdata._lastscore;
- var chessinfo = lastdata._chesspad;
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (parseInt(chessinfo[i * STAR_HEIGHT + j]) > 0) {
- this._chessInfo[i * STAR_HEIGHT + j] = parseInt(chessinfo[i * STAR_HEIGHT + j]);
- }
- }
- }
- this.node.runAction(cc.sequence(cc.delayTime(1.5), cc.callFunc(function () {
- this.handleHandle();
- }.bind(this))));
- }
- },
- /**
- * 初始化数据信息
- */
- initData: function initData() {
- this._candealwith = true;
- this.setLevel(1);
- this.setScore(0);
- this.setTarget(this.getTargetScoreByRound(1));
- this._lastLevelScore = 0;
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- this._chessInfo[i * STAR_HEIGHT + j] = 0;
- }
- }
- this._selectbox = [];
- this._eliminateNum = 0;
- this._eliminatePos = [];
- this.setLastData();
- },
- /**
- * 分数算法
- * @param level
- * @returns {number}
- */
- getTargetScoreByRound: function getTargetScoreByRound(level) {
- var targetscore = 0;
- if (level == 1) targetscore = 1000;else targetscore = 10 * level * level + 1950 * level - 1440;
- return targetscore;
- },
- /**
- * 设置游戏状态
- * @param state
- */
- setGameState: function setGameState(state) {
- this._gamestate = state;
- },
- /**
- * 生成棋盘
- */
- starDrop: function starDrop() {
- this.isCanPauseTouch = true;
- this.setGameState(GameState.STATE_STOP);
- this._max = this.getTarget() - this.score;
- cc.game.emit(GameEvent.EventType.GAME_PROGRESS, 0);
- if (!this._firstsavein) {
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- var color = zy.randNum(1, 5);
- this._chessInfo[i * STAR_HEIGHT + j] = color;
- }
- }
- }
- var time = this.chessAppear(6); //zy.randNum(1, 6)
- console.log("time: ", time);
- this.node.runAction(new cc.sequence(new cc.delayTime(time), new cc.callFunc(function () {
- this.setGameState(GameState.STATE_RUN);
- }.bind(this))));
- },
- /**
- * 棋盘出现特效
- * @param val 特效类型
- * @returns {number}
- */
- chessAppear: function chessAppear(val) {
- if (!this.isInitChessBg) this.initChess();
- 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];
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- var id = this._chessInfo[i * STAR_HEIGHT + j];
- if (id > 0) {
- var box = zy.getSprite("game/star/starchess" + id);
- box.setScale(STAR_CHESS_SCALE);
- this.clipDraw.addChild(box, CHESSMAN_LEVEL, this.getBoxTag(i * STAR_HEIGHT + j));
- var pos = this.chessPos(i, j);
- box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH)); // if((i*STAR_HEIGHT+j)==this._limitproptag){
- // box.setTexture(url_xmtg+ "res/animation/starpng/block_"+id+"_lb.png");
- // }
- if (val == 0) {
- box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH));
- 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))));
- } else if (val == 1) {
- box.setPosition(cc.v2(pos.x - STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
- } else if (val == 2) {
- box.setPosition(cc.v2(pos.x + STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
- } else if (val == 3) {
- box.setPosition(pos);
- box.opacity = 0;
- box.runAction(cc.sequence(cc.delayTime(0), cc.fadeIn(1.0)));
- } else if (val == 4) {
- if (i < STAR_WIDTH / 2.0) {
- box.setPosition(cc.v2(pos.x - STAR_WIDTH * STAR_SIZE_WIDTH / 2.0, pos.y));
- } else {
- box.setPosition(cc.v2(pos.x + STAR_WIDTH * STAR_SIZE_WIDTH / 2.0, pos.y));
- }
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
- } else if (val == 5) {
- if (j < STAR_HEIGHT / 2.0) {
- box.setPosition(cc.v2(pos.x, pos.y - STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0));
- } else {
- box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0));
- }
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
- } else if (val == 6) {
- var k = 1;
- if (j % 2 == 0) k = -1;
- box.setPosition(cc.v2(pos.x + k * STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.5, pos)));
- }
- }
- }
- }
- return time[val];
- },
- chessPos: function chessPos(i, j) {
- return cc.v2(WINSIZE.width / 2.0 + (i + 0.5 - STAR_WIDTH / 2.0) * STAR_SIZE_WIDTH, heightoffest + (j + 0.5) * STAR_SIZE_WIDTH);
- },
- /**
- * 获取游戏状态
- * @returns {number}
- */
- getGameState: function getGameState() {
- return this._gamestate;
- },
- /**
- * 初始化监听层
- */
- initTouchLayer: function initTouchLayer() {
- this.touchLayer.on(cc.Node.EventType.TOUCH_START, this.onTouchBegan.bind(this), this);
- this.touchLayer.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoved.bind(this), this);
- this.touchLayer.on(cc.Node.EventType.TOUCH_END, this.onTouchEnded.bind(this), this);
- this.touchLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnded.bind(this), this);
- },
- txtTip: function txtTip(str) {
- var labelTip = cc.instantiate(this.labelTip);
- labelTip.parent = this.node;
- labelTip.scale = 0.7;
- labelTip.setPosition(cc.v2(0, 0));
- labelTip.getComponent(cc.Label).string = str.toString();
- labelTip.runAction(cc.sequence(cc.moveBy(0.5, cc.v2(0, WINSIZE.height / 2 - 50)), cc.delayTime(1.2), cc.removeSelf(true)));
- return labelTip;
- },
- /**
- * 打开提示界面
- */
- openTip: function openTip() {
- cc.game.emit(GameEvent.EventType.GAME_TIP);
- },
- /**
- * 开始监听
- * @param event
- * @returns {boolean}
- */
- onTouchBegan: function onTouchBegan(event) {
- cc.log("onTouchBegan");
- var position = event.getLocation();
- var target = this;
- if (target.getGameState() != GameState.STATE_RUN) {
- return false;
- }
- target._firstsavein = false;
- var k = target.propTouch(position);
- if (k > 0 && target._eliminateNum == 0) {
- if (PROPPRICE[k - 1] > coinNum) {
- this._selectprop = 0; // this.txtTip("金币不足");
- this.showPropTip(0);
- this.openTip();
- return false;
- }
- target.propMotion(k);
- return true;
- }
- if (position.x >= 0 && position.x < WINSIZE.width && position.y >= heightoffest && position.y <= heightoffest + STAR_SIZE_WIDTH * STAR_HEIGHT) {
- var pos = target.chessPt(position);
- if (target._chessInfo[pos.x * STAR_HEIGHT + pos.y] && ZYGameTool.getInstance().posIndexOf(target._eliminatePos, pos) == -1) {
- // if (target._selectprop == 2) target._selectprop =4 ;
- var temp = true;
- var vec = [];
- if (target._selectprop == 1 || target._selectprop == 2) {
- temp = target.propProcess(target._selectprop - 1, pos); // if(target._guide){
- // target.removeChildByTag(TIPFONTTAG);
- // target._guidenumber++;
- // }
- } else if (target._selectprop == 0) {
- target.boxTip(pos, vec);
- }
- var selectnumber = vec.length;
- if (selectnumber > 1 || target._selectprop > 0 && temp) {
- target.endTip();
- var ft = 0.0;
- if (target._selectprop > 0) {// ELSGameLogic.getInstance().gameCount("item","prop_"+target._selectprop);
- }
- if (target._selectprop == 0) {
- target._eliminateNum++;
- target.boxEliminate(vec);
- ft = boxremovesingletime * selectnumber + cleardelaytime;
- } else if (target._selectprop == 1) {
- ft = boxremovesingletime + 0.9;
- } else if (target._selectprop == 2) {
- ft = target._selectbox.length * 0.15;
- target.useProps4(pos);
- }
- if (target._selectprop == 1 || target._selectprop == 2) {
- target.setGameState(GameState.STATE_STOP);
- target.node.runAction(cc.sequence(cc.delayTime(ft), cc.callFunc(function () {
- target.touchHandle();
- }.bind(target))));
- target._selectprop = 0;
- target._selectbox = [];
- }
- }
- }
- return true;
- }
- return false;
- },
- //获取道具坐标
- propTouch: function propTouch(pos) {
- for (var i = 0; i < 2; i++) {
- if (this._propNode[i].getBoundingBoxToWorld().contains(pos)) return i + 1;
- }
- return 0;
- },
- //获取道具位置
- getPropPos: function getPropPos(key) {
- if (key > 0 && key < 2) {
- return this._propNode[key - 1].parent.convertToWorldSpaceAR(this._propNode[key - 1].getPosition());
- }
- return cc.v2(0, 0);
- },
- useProps4: function useProps4(pos) {
- // var maskLayer = cc.instantiate(this.maskLayer);
- // maskLayer.zIndex = 99;
- // maskLayer.parent = this.node.parent;
- // this.clipDrawTemp.zIndex = 100;
- this.node.getChildByName("maskLayer").active = true; // this.node.getChildByName("maskLayer").zIndex = 99;
- var tempk = this._selectbox[0];
- for (var i in this._selectbox) {
- if (this._selectbox[i].x == pos.x && this._selectbox[i].y == pos.y) {
- this._selectbox[i].x = tempk.x;
- this._selectbox[i].y = tempk.y;
- this._selectbox[0].x = pos.x;
- this._selectbox[0].y = pos.y;
- break;
- }
- }
- var selectbox = this._selectbox.slice(1, this._selectbox.length);
- selectbox.sort(function (a, b) {
- return Math.random() > 0.5 ? -1 : 1;
- });
- selectbox.splice(0, 0, this._selectbox[0]);
- var actions = [];
- for (var i = 0; i < selectbox.length; i++) {
- var key1 = selectbox[i];
- var node = this.getClipItem(key1.x * STAR_HEIGHT + key1.y);
- node.index = 101;
- actions.push(cc.callFunc(function (target, key) {
- this.addParticle(key);
- this.removeBox(key);
- }.bind(this), this, key1));
- if (i == selectbox.length - 1) {
- break;
- }
- var key2 = selectbox[i + 1];
- var position1 = this.chessPos(key1.x, key1.y);
- var position2 = this.chessPos(key2.x, key2.y);
- actions.push(cc.callFunc(function (target, data) {
- // var line=new cc.Sprite(starpng[wb.randNum(14,18)]);
- var line = zy.getSprite("game/prop/starprope" + zy.randNum(1, 5));
- line.setAnchorPoint(cc.v2(0, 0.5));
- 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));
- var wid = 70;
- var lengthscale = length * 1.0 / wid;
- line.scaleX = 0.06 * lengthscale;
- cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
- 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 () {
- line.removeFromParent();
- })));
- line.setPosition(data.pos1);
- var angle1 = Math.atan2(data.pos2.y - data.pos1.y, data.pos2.x - data.pos1.x);
- var angle = -1 * cc.misc.radiansToDegrees(angle1);
- line.setRotation(angle);
- this.clipDrawTemp.addChild(line, 102);
- var score = this.getScoreByNum(1);
- this.updateScore(score);
- }.bind(this), this, {
- pos1: position1,
- pos2: position2
- }));
- actions.push(cc.delayTime(0.15));
- }
- actions.push(cc.callFunc(function () {
- // maskLayer.removeFromParent();
- this.node.getChildByName("maskLayer").active = false;
- this.clipDrawTemp.removeAllChildren(true);
- this.showPropTip(0);
- }.bind(this)));
- this.node.runAction(cc.sequence(actions));
- },
- //使用道具
- propProcess: function propProcess(id, pos, key) {
- if (!pos) {
- pos = cc.v2(0, 0);
- }
- if (!key) {
- key = 1;
- }
- if (this._selectprop > 0) {
- this.showPropMotion(this._selectprop, 0);
- } //
- if (key == 1) {
- console.log("id: ", id);
- if (PROPPRICE[id] > coinNum) {
- this._selectprop = 0;
- this.txtTip();
- return false;
- } else {
- //使用道具扣除金币
- this.txtTip("Use props to deduct gold coins " + PROPPRICE[id]);
- ZYGameTool.getInstance().useCoin(-PROPPRICE[id]);
- }
- }
- if (id == 1) {
- var key = this.getChessInfo(pos);
- console.log("---key--: ", key);
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (key == this.getChessInfo(cc.v2(i, j))) {
- this._selectbox.push(cc.v2(i, j));
- }
- }
- }
- } else if (id == 0) {
- // if(id==0){
- var ssp = zy.getSprite("game/prop/prop1");
- this.clipDraw.addChild(ssp, 1000);
- ssp.setPosition(this.getPropPos(1));
- var v1 = ssp.getPosition();
- var tempv = this.chessPos(pos.x, pos.y);
- var v2 = cc.v2(tempv.x + 10, tempv.y - 10);
- var v3 = cc.v2(0, 0);
- 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);
- var bezierpath = [v1, v3, v2];
- var bezier = cc.bezierTo(0.7, bezierpath);
- var bombSpine = this.createBombSpine(tempv, this.clipDraw);
- bombSpine.active = false;
- var bombAction = cc.callFunc(function () {
- bombSpine.active = true;
- });
- cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 6); //消除个数
- ssp.runAction(cc.sequence(bezier, bombAction, cc.delayTime(0.2), cc.callFunc(function (target, tempv) {
- bombSpine.removeFromParent();
- ssp.removeFromParent();
- }.bind(this), this, tempv)));
- ssp.runAction(cc.scaleTo(0.15, 1.5));
- this.node.runAction(cc.sequence(cc.delayTime(0.7), cc.callFunc(function (target, pos) {
- this.node.runAction(cc.sequence(cc.delayTime(0.0), cc.callFunc(function (target, pos) {
- var temp = 0;
- for (var i = pos.x - 1; i <= pos.x + 1; i++) {
- for (var j = pos.y - 1; j <= pos.y + 1; j++) {
- if (i >= 0 && i < STAR_WIDTH && j >= 0 && j < STAR_HEIGHT && this.getChessInfo(cc.v2(i, j))) {
- this.addParticle(cc.v2(i, j));
- this.removeBox(cc.v2(i, j));
- ++temp;
- }
- }
- }
- var score = this.getScoreByNum(temp);
- this.updateScore(score);
- }.bind(this), this, pos)));
- this.showPropTip(0);
- }.bind(this), this, pos)));
- }
- return true;
- },
- createBombSpine: function createBombSpine(pos, node, index) {
- if (index == undefined) index = 10000;
- var bombSpine = cc.instantiate(this.bombSpine);
- bombSpine.parent = node;
- bombSpine.zIndex = index;
- bombSpine.setPosition(pos);
- return bombSpine;
- },
- propMotion: function propMotion(k) {
- if (this._selectprop > 0) {
- this.showPropMotion(this._selectprop, 0);
- }
- cc.log("match touch began2", k);
- if (this._selectprop == k) {
- this._selectprop = 0;
- this.showPropTip(0);
- } else {
- this._selectprop = k;
- this.showPropTip(k);
- this.showPropMotion(k, 1);
- }
- },
- showPropTip: function showPropTip(k) {
- if (k == 0) {
- this.propTipNode.active = false;
- } else if (k > 0 && k < 3) {
- this.propTipNode.active = true;
- for (var i = 0; i < 2; i++) {
- if (i == k - 1) {
- this._proptipsp[i].active = true;
- } else {
- this._proptipsp[i].active = false;
- }
- }
- }
- },
- //道具点击动画
- showPropMotion: function showPropMotion(key, type) {
- if (type == 1) {
- this._propmotion[key - 1].active = true;
- this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.0, 1.0), cc.scaleTo(1.0, 1.5))));
- this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.fadeIn(0.0), cc.fadeOut(1.0))));
- } else if (type == 0) {
- this._propmotion[key - 1].active = false;
- this._propmotion[key - 1].stopAllActions();
- this._propmotion[key - 1].setScale(1.0);
- this._propmotion[key - 1].opacity = 255;
- }
- },
- getScoreByNum: function getScoreByNum(num) {
- var k = 5;
- var t = 5;
- for (var i = 0; i < num; i++) {
- k += t;
- t += 10;
- }
- return k;
- },
- updateScore: function updateScore(score) {
- this.score += score;
- },
- scoreMotion: function scoreMotion(score, pt) {
- var scoreNum = cc.instantiate(this.scoreNum);
- scoreNum.parent = this.clipDraw;
- scoreNum.zIndex = 10000;
- scoreNum.getComponent(cc.Label).string = score.toString();
- scoreNum.setPosition(this.chessPos(pt.x, pt.y));
- scoreNum.runAction(cc.sequence(cc.moveBy(1.0, cc.v2(0, STAR_SIZE_WIDTH)), cc.callFunc(function () {
- scoreNum.removeFromParent();
- })));
- },
- /**
- * 连消提示
- * @param vec
- */
- boxEliminate: function boxEliminate(vec) {
- var score = this.getScoreByNum(vec.length);
- this.updateScore(score);
- console.log("--score--: ", score);
- this.scoreMotion(score, vec[0]);
- if (this.getScore() >= this.getTarget() && this.getScore() - score < this.getTarget()) {
- this.spriteShow(zy_gxpng[0]);
- } else {
- if (vec.length == 5) {
- this.spriteShow("game/main_tip/great");
- } else if (vec.length > 5) {
- this.spriteShow("game/main_tip/zan");
- }
- }
- this.levelupmusic = 0;
- this.boxSequence(vec, true);
- var arrayOfActions = [];
- for (var i in vec) {
- if (i != "0") {
- arrayOfActions.push(cc.delayTime(boxremovesingletime));
- }
- var key = vec[i];
- arrayOfActions.push(cc.callFunc(function (target, data) {
- this.addParticle(data);
- this.removeBox(data);
- }.bind(this), this, key));
- }
- arrayOfActions.push(cc.delayTime(cleardelaytime));
- arrayOfActions.push(cc.callFunc(function () {
- this._eliminateNum--;
- if (this._eliminateNum == 0) {
- this._eliminatePos = [];
- this.setGameState(GameState.STATE_STOP);
- this.touchHandle();
- }
- }.bind(this)));
- this.node.runAction(cc.sequence(arrayOfActions));
- },
- spriteShow: function spriteShow(str) {
- if (str == zy_gxpng[0]) {
- var endpos = cc.v2(0, WINSIZE.height * Hkey - 180);
- var spr = zy.getSprite(str);
- this.node.addChild(spr, 1000, "777");
- spr.setPosition(cc.v2(0, 0 + heightoffest / 2.0));
- 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)));
- spr.runAction(cc.sequence(new cc.delayTime(1.2), cc.scaleTo(0.5, 0.25), cc.callFunc(function () {
- spr.removeFromParent();
- var sp = zy.getSprite(str);
- sp.setScale(0.25); // this.getParent().getBackLayer().getChildByName("node").addChild(sp,10,777);
- this.node.addChild(spr, 12, "777");
- sp.setPosition(cc.v2(-170, -175));
- }.bind(this))));
- } else {
- this.spriteShow2(str, cc.v2(0, 0));
- }
- },
- spriteShow2: function spriteShow2(res, pos) {
- var sp = zy.getSprite(res);
- this.node.addChild(sp, 1000);
- sp.setPosition(pos);
- sp.setScale(1.0);
- if (res == "game/main_tip/xsyd") {
- sp.runAction(sequence(cc.moveBy(0.5, cc.v2(0, 50)), cc.delayTime(0.2), cc.fadeOut(0.3), cc.callFunc(function () {
- sp.removeFromParent();
- })));
- } else {
- 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 () {
- sp.removeFromParent();
- })));
- }
- },
- /**
- * 可以消除的元素放入_eliminatePos
- * @param pos
- * @param vect
- */
- boxTip: function boxTip(pos, vect) {
- var vec = this.boxGet(pos);
- if (vec.length > 1) {
- for (var i in vec) {
- vect.push(vec[i]);
- this._eliminatePos.push(vec[i]);
- var box = this.getClipItem(vec[i].x * STAR_HEIGHT + vec[i].y);
- this.setBoxMotion(box, true);
- }
- }
- cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, vect.length); //消除个数
- },
- getClipItem: function getClipItem(tag) {
- return this.clipDraw.getChildByName(tag.toString());
- },
- //TAG值转换为String类型
- getBoxTag: function getBoxTag(v) {
- return v.toString();
- },
- /**
- * 消除结束
- */
- endTip: function endTip() {
- this._clicktiptime = 0;
- for (var i in this._clicktipvec) {
- var key = this._clicktipvec[i];
- var box = this.getClipItem(key.x * STAR_HEIGHT + key.y);
- this.setBoxMotion(box, false);
- }
- this._clicktipvec = [];
- },
- /**
- * 获取可以消除的元素
- * @param pos
- * @returns {[]}
- */
- boxGet: function boxGet(pos) {
- var vec = [];
- this.boxAdd(pos, vec);
- return vec;
- },
- /**
- * 树状搜索消除元素
- * @param pos
- * @param vec
- */
- boxAdd: function boxAdd(pos, vec) {
- vec.push(pos); //x-1
- 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))) {
- this.boxAdd(cc.v2(pos.x - 1, pos.y), vec);
- } //x+1
- 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))) {
- this.boxAdd(cc.v2(pos.x + 1, pos.y), vec);
- } //y-1
- 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))) {
- this.boxAdd(cc.v2(pos.x, pos.y - 1), vec);
- } //y+1
- 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))) {
- this.boxAdd(cc.v2(pos.x, pos.y + 1), vec);
- }
- },
- /**
- * 星星消除给个动作
- * @param box
- * @param b
- */
- setBoxMotion: function setBoxMotion(box, b) {
- if (box) {
- if (b) {
- box.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1.0, 0.89), cc.scaleTo(1.0, 1.0))));
- } else {
- box.stopAllActions();
- box.setScale(1.0);
- }
- }
- },
- /**
- * 通过坐标找到目标对象
- * @param pos
- * @returns {cc.Vec2}
- */
- chessPt: function chessPt(pos) {
- var x = parseInt((pos.x - WINSIZE.width / 2.0) / STAR_SIZE_WIDTH + STAR_WIDTH / 2.0);
- var y = parseInt((pos.y - heightoffest) / STAR_SIZE_WIDTH);
- return cc.v2(x, y);
- },
- touchHandle: function touchHandle() {
- var time = 0.0;
- if (this.chessMove()) {
- time += chessmovetime;
- }
- this.node.runAction(cc.sequence(cc.delayTime(time), cc.callFunc(function () {
- if (this._candealwith) {
- this.handleHandle();
- }
- }.bind(this))));
- },
- handleHandle: function handleHandle() {
- if (this.chessCanEliminate()) {
- this.setGameState(GameState.STATE_RUN);
- } else {
- this.node.runAction(cc.sequence(cc.delayTime(0.5), new cc.callFunc(function () {
- this.chessClear();
- }.bind(this))));
- }
- },
- chessClear: function chessClear() {
- this.isCanPauseTouch = false;
- var eliminatebox = [];
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (this.getChessInfo(cc.v2(i, j))) {
- eliminatebox.push(cc.v2(i, j));
- }
- }
- }
- if (eliminatebox.length > 0) {
- eliminatebox.sort(function (a, b) {
- return Math.random() > 0.5 ? -1 : 1;
- });
- }
- this.levelupmusic = 0;
- this.boxSequence(eliminatebox, false);
- var num = this.getRetainScore(eliminatebox.length);
- this.updateScore(num); // ELSGameData.getInstance().setDayHighScore(this._score,num);
- this.scoreMotion(num, cc.v2(WINSIZE.width / 2, WINSIZE.height / 2)); // ELSGameLogic.getInstance().showHyRank(this._score,false);
- var ftime = this.smallPeopleCollect(eliminatebox);
- this.retainScoreMotion(eliminatebox.length, num, 3.0); //奖励多少分
- var ft = Math.max(ftime, 3);
- if (this.getScore() > this.getTarget() && this.getScore() - num < this.getTarget()) {
- this.spriteShow(zy_gxpng[0]);
- } // gameLocalData.save(this);
- this.node.runAction(cc.sequence(cc.delayTime(ft), new cc.callFunc(function () {
- this.gameEnd();
- }.bind(this))));
- },
- retainScoreMotion: function retainScoreMotion(number, score, ft) {
- var fnt1 = cc.instantiate(this.labelTip);
- fnt1.zIndex = 100;
- fnt1.parent = this.node;
- fnt1.getComponent(cc.Label).string = "reward " + score + "score";
- fnt1.x = -(WINSIZE.width / 2 + 100);
- fnt1.y = heightoffest * 0.5;
- fnt1.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.2, cc.v2(0, heightoffest * 0.5))));
- var fnt2 = cc.instantiate(this.labelTip);
- fnt2.zIndex = 100;
- fnt2.parent = this.node;
- fnt2.getComponent(cc.Label).string = "surplus " + number + "blocks";
- fnt2.x = -(WINSIZE.width / 2 + 100);
- fnt2.y = heightoffest * 0.5 - 100;
- 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 () {
- fnt1.removeFromParent();
- fnt2.removeFromParent();
- })));
- },
- /**
- * 游戏结束
- */
- gameEnd: function gameEnd() {
- // this.isCanPauseTouch = true;
- cc.game.emit(GameEvent.EventType.GAME_PASS_STAGE); //消除个数
- //闯关失败
- if (this.getScore() < this.getTarget()) {
- // this.gameFaild();
- cc.game.emit(GameEvent.EventType.GANE_FAIL); // cc.director.loadScene("homeScene");
- } else {
- //闯关成功
- // this.LevelUpMotion();
- if (this.getScore() >= this.getTarget()) {
- this.spriteShow(zy_gxpng[0]);
- }
- this.setLevel(this.getLevel() + 1);
- this.setTarget(this.getTargetScoreByRound(this.getLevel()));
- this._lastLevelScore = this.getScore();
- this.node.runAction(cc.sequence(cc.delayTime(0.8), cc.callFunc(function () {
- this._firstsavein = false;
- this.starDrop();
- }.bind(this))));
- }
- },
- clearData: function clearData() {
- this.score = 0;
- this._lastLevelScore = 0;
- this.level = 1;
- this.target = 0;
- this.hang = 0;
- this.chessInfo = []; //记录棋盘元素的颜色类型
- this._selectbox = [];
- this._eliminatePos = []; //消除
- this._eliminateNum = 0;
- this._clicktipvec = [];
- this._candealwith = true;
- this._limitproptag = -1;
- this._clicktiptime = 0;
- this._selectprop = 0;
- this.propNode = [];
- this._propmotion = [];
- this._proptipsp = [];
- this._firstsavein = false;
- },
- smallPeopleCollect: function smallPeopleCollect(vec) {
- var tt = cleardelaytime;
- var action = [];
- for (var i in vec) {
- var pos = vec[i];
- action.push(cc.callFunc(function (target, pos) {
- this.addParticle(pos, 2);
- this.removeBox(pos, 1);
- }.bind(this), this, pos));
- action.push(cc.delayTime(boxremovesingletime));
- tt += boxremovesingletime;
- }
- if (action.length > 0) {
- this.node.runAction(cc.sequence(action));
- }
- return tt;
- },
- addParticle: function addParticle(pos, key) {
- if (!key) key = 1;
- 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);
- },
- removeBox: function removeBox(pos, tag) {
- if (!tag) {
- tag = 2;
- }
- var node = this.getClipItem(pos.x * STAR_HEIGHT + pos.y);
- if (node && node.isValid) node.removeFromParent();
- this.setChessInfo(pos, 0);
- this.levelupmusic++;
- },
- /**
- * 星星粒子特效
- * @param node
- * @param pos
- * @param idx
- * @param scale
- * @param type
- */
- addFkLizi: function addFkLizi(node, pos, idx, scale, type) {
- if (!type) type = 1;
- if (!scale) scale = 1.0; // var spname=chesspng[idx];
- var spname = "";
- if (type == 2) {
- if (idx == 5) spname = "game/lizi/starpar2";else spname = "game/lizi/starpar" + (3 + idx);
- } else if (type == 3) {
- spname = "game/lizi/starpar1";
- }
- if (idx == 5) {
- this.blast(5, pos, zy.randNum(0, 4));
- cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
- } else {
- this.blast(5, pos, idx);
- }
- },
- blast: function blast(score, pos, index) {
- var node = Blast.pool.get();
- if (!node) {
- node = cc.instantiate(this.BLAST_PREFAB);
- }
- node.position = pos;
- node.getComponent(this.BLAST_PREFAB.name).run(score, index);
- node.zIndex = 100; // node.scale = this.node.scale;
- node.parent = this.clipDraw;
- },
- getRetainScore: function getRetainScore(number) {
- var score = 1500;
- for (var i = 1; i <= number; i++) {
- score -= 30 * i - 15;
- }
- if (score < 0) score = 0;
- return score;
- },
- boxSequence: function boxSequence(vec, sx) {
- var k = vec.length;
- if (k > 0) {
- for (var i = 0; i < k; i++) {
- for (var j = k - 1; j > i; j--) {
- if (sx) {
- if (this.getnum(vec[j]) < this.getnum(vec[j - 1])) {
- var temp = vec[j];
- vec[j] = vec[j - 1];
- vec[j - 1] = temp;
- }
- } else {
- if (this.getrenum(vec[j]) < this.getrenum(vec[j - 1])) {
- var temp = vec[j];
- vec[j] = vec[j - 1];
- vec[j - 1] = temp;
- }
- }
- }
- }
- }
- },
- getnum: function getnum(pos) {
- return pos.x * STAR_HEIGHT + pos.y;
- },
- getrenum: function getrenum(pos) {
- return pos.x * STAR_HEIGHT + (STAR_HEIGHT - pos.y);
- },
- chessCanEliminate: function chessCanEliminate() {
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (this.singelCanEliminate(cc.v2(i, j))) {
- return true;
- }
- }
- }
- return false;
- },
- chessMove: function chessMove() {
- var temp = false;
- var downstep = [];
- var step = 0;
- for (var i = 0; i < STAR_WIDTH; i++) {
- step = 0;
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (this.getChessInfo(cc.v2(i, j)) == 0) {
- step++;
- } else if (step > 0) {
- temp = true;
- var box = this.getClipItem(i * STAR_HEIGHT + j);
- if (box) {
- box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.15, this.chessPos(i, j - step)))); // box.setTag(i*STAR_HEIGHT+(j-step));
- box.name = this.getBoxTag(i * STAR_HEIGHT + (j - step));
- if (i * STAR_HEIGHT + j == this._limitproptag) {
- this._limitproptag = i * STAR_HEIGHT + (j - step);
- }
- this.setChessInfo(cc.v2(i, j - step), this.getChessInfo(cc.v2(i, j)));
- this.setChessInfo(cc.v2(i, j), 0);
- }
- }
- }
- }
- step = 0;
- for (var i = 0; i < STAR_WIDTH; i++) {
- if (this.getChessInfo(cc.v2(i, 0)) == 0) {
- step++;
- } else if (step > 0) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (this.getChessInfo(cc.v2(i, j))) {
- temp = true;
- var box = this.getClipItem(i * STAR_HEIGHT + j);
- if (box) {
- 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);
- box.name = this.getBoxTag((i - step) * STAR_HEIGHT + j);
- this.setChessInfo(cc.v2(i - step, j), this.getChessInfo(cc.v2(i, j)));
- this.setChessInfo(cc.v2(i, j), 0);
- if (i * STAR_HEIGHT + j == this._limitproptag) {
- this._limitproptag = (i - step) * STAR_HEIGHT + j;
- }
- }
- }
- }
- }
- }
- return temp;
- },
- hessCanEliminate: function hessCanEliminate() {
- for (var i = 0; i < STAR_WIDTH; i++) {
- for (var j = 0; j < STAR_HEIGHT; j++) {
- if (this.singelCanEliminate(cc.v2(i, j))) {
- return true;
- }
- }
- }
- return false;
- },
- singelCanEliminate: function singelCanEliminate(pos) {
- var i = pos.x;
- var j = pos.y;
- var key = this.getChessInfo(pos);
- if (key > 0) {
- if (i - 1 >= 0 && key == this.getChessInfo(cc.v2(i - 1, j))) {
- return true;
- }
- if (i + 1 < STAR_WIDTH && key == this.getChessInfo(cc.v2(i + 1, j))) {
- return true;
- }
- if (j - 1 >= 0 && key == this.getChessInfo(cc.v2(i, j - 1))) {
- return true;
- }
- if (j + 1 < STAR_HEIGHT && key == this.getChessInfo(cc.v2(i, j + 1))) {
- return true;
- }
- }
- return false;
- },
- setChessInfo: function setChessInfo(pos, key) {
- this._chessInfo[pos.x * STAR_HEIGHT + pos.y] = key;
- },
- getChessInfo: function getChessInfo(pos) {
- return this._chessInfo[pos.x * STAR_HEIGHT + pos.y];
- },
- onTouchMoved: function onTouchMoved(event) {
- cc.log("onTouchMoved");
- },
- onTouchEnded: function onTouchEnded(event) {
- cc.log("onTouchEnded");
- },
- resurrenction: function resurrenction() {
- this.setScore(this._lastLevelScore);
- this.node.runAction(new cc.Sequence(new cc.DelayTime(0.8), new cc.CallFunc(function () {
- this.starDrop();
- }.bind(this))));
- },
- // update (dt) {},
- onDestroy: function onDestroy() {
- //关闭所有音乐、音效
- cc.audioEngine.stopAll(); //移除所有事件监听
- cc.game.targetOff(this);
- }
- });
- cc._RF.pop();
|