JSGame = "lt_blockquest"; // 로그 버전 번호 const LOG_VER = "1222.01"; // 테스트모드 1: 테스트, 0: 릴리즈 모드 const TEST_MODE = 0; var GameBoost = {}; var InBanner = null; const GAMEBOOST_CFG = "blockquest_gb.cfg"; const INAD = "INAD_"; const INAD_ID = 1; var SelfBanner = null; G.W = 480; G.H = 800; G.RW = G.W; G.RH = G.H; G.X = 0; G.Y = 0; G.RX2 = G.W; G.RY2 = G.H; const B_SIZE = 52; const B_HSIZE = B_SIZE*0.5; const MAP_X = 0; const MAP_Y = 0; const MAP_XS = 8; const MAP_YS = 8; const MOVE_SPEED = 0.09; const BTN_OK = 99; const BTN_OPTION = 100; var COLLECTION_FINISH = 10; const BTN_GOLDSHOP = 101; const BTN_GETFREE = 102; const BTN_COLLECTION = 103; const BTN_SOUND = 104; const BTN_LANGUAGE = 105; const BTN_LOGIN = 106; const BTN_HELP = 107; const BTN_CLOSE = 108; const LOGIN_GOOGLE = 109; const LOGOUT_GOOGLE = 110; const BTN_RANKSCORE = 111; const BTN_ACHIEVEMENT = 112; const BTN_REPLAY = 113; const BTN_BLOCKBOX=114; const BTN_BLOCKSELECT=115; const BTN_INBANNER=116; const BTN_PAUSE=117; const BTN_CLEAR=118; const BTN_BLOCK_PREV=119; const BTN_BLOCK_NEXT=120; const BTN_SHARE2=121; var CMyInfo = cc.Class.extend({ id:"guest", ltype:-1, gift:0, giftNew:0, giftTime:0, cash:0, gitem:{}, lvCheckSum:0, star:0, hint:0, memo:0, gold:0, ugold:0, cstage:0, ucstage:0, ustar:0, test:0, helpItem:null, arcadeHighScore:0, ctor:function() { cc.associateWithNative( this, cc.Class ); }, setItem:function(item, num) { this.gitem[item] = num; Noti.push(item, num); }, setCash:function(cash) { this.cash = cash; Noti.push("cash", cash); }, loadGold:function() { this.gold = LocalDB.ival("gold"); Noti.push("gold", this.gold); }, setGold:function(gold) { this.gold = gold; Noti.push("gold", gold); LocalDB.update("gold", gold); }, addGold:function(gold) { this.setGold(this.gold + int(gold)); }, }); MyInfo = new CMyInfo(); var CScore = cc.Layer.extend({ m_txtTitle:null, m_txtScore:null, ctor:function(w, code, color) { this._super(); cc.associateWithNative( this, cc.Layer ); // 배경화면 // var ibBack = new zg.ImageBox(); // ibBack.init(Main.m_gameDB.getSprite("bgScore"), w, 64, 20); // ibBack.setPosition(0, 0); // ibBack.setAnchorPoint(0.5, 0.5); // this.addChild(ibBack); this.addChild(Main.newSprite("bgScore", 0, 0)); // 점수 타이틀 this.m_txtTitle = BFont.create(0, 12, TEXT_CENTER, LnkLang.val(code), 16); this.addChild(this.m_txtTitle); // 점수 this.m_txtScore = BFont.create(0, -12, TEXT_CENTER, 0, 20); this.addChild(this.m_txtScore); this.m_txtScore.setBold(); this.m_txtScore.setColorHex(color); }, setScore:function(score) { this.m_txtScore.setString(score); }, }); var CRndBlock = cc.Layer.extend({ m_arrBlock:null, m_arrShadow:null, m_poolBlock:null, m_width:0, m_height:0, m_bMatched:false, m_parent:null, m_pos:0, m_no:0, m_bEnable:false, m_nPieceNo:0, ctor:function(parent) { this._super(); cc.associateWithNative( this, cc.Layer ); this.m_poolBlock = new zg.SpritePool(Main.m_gameDB, this); this.setAnchorPoint(0, 0); this.m_arrBlock = []; this.m_arrShadow = []; this.hide(); }, create:function(parent, pos) { this.m_parent = parent; this.m_pos = pos; spr = this.m_poolBlock.newSprite("block", 10, 10); }, set:function(arrBlock) { // 블록, 배열 초기화 this.m_arrBlock.length = 0; this.m_arrShadow.length = 0; this.m_poolBlock.hideAll(); this.m_bMatched = false; var i; var spr; var block; var no = arrBlock[0]; this.m_no = no; this.m_width = 0; this.m_height = 0; for(i=arrBlock.length-1; i>=1; i--) { block = arrBlock[i]; spr = this.m_poolBlock.newSprite("block", block[0]*B_SIZE, block[1]*B_SIZE); spr.stop(no); spr.setLocalZOrder(2); spr.bx = block[0]; spr.by = block[1]; spr.matched = null; this.m_arrBlock.push(spr); if(this.m_width < block[0]) this.m_width = block[0]; if(this.m_height < block[1]) this.m_height = block[1]; spr = this.m_poolBlock.newSprite("block", spr.x+20, spr.y+20); spr.stop(no); spr.setLocalZOrder(0); spr.setColorHex(0); spr.setOpacity(0x33); this.m_arrShadow.push(spr); } this.m_width = this.m_width * B_SIZE + B_SIZE; this.m_height = this.m_height * B_SIZE + B_SIZE; // this.setAnchorPoint(0.5, 0); this.m_bEnable = true; }, select:function() { GameSnd.play("SOUND_BLOCK_GET"); // this.stopAllActions(); // this.runAction( // cc.sequence( // cc.spawn( // cc.scaleTo(0.1, 0.4), // cc.moveTo(0.1, cc.p(this.tx, this.ty)) // ) // ) // ); var block; for(var i=this.m_arrBlock.length; i--; ) { block = this.m_arrBlock[i]; block.runAction(cc.scaleTo(0.1, 0.92)); block.select = null; this.m_arrShadow[i].hide(); } block = null; }, restore:function() { GameSnd.play("SOUND_BLOCK_RESTORE"); this.stopAllActions(); this.runAction( cc.sequence( cc.spawn( cc.scaleTo(0.1, 0.5), cc.moveTo(0.1, cc.p(this.tx, this.ty)) ) ) ); var block; for(var i=this.m_arrBlock.length; i--; ) { block = this.m_arrBlock[i]; block.matched = null; block.runAction(cc.scaleTo(0.1, 1)); this.m_arrShadow[i].show(); } i = null; block = null; }, clearMatched:function() { var rndBlock; for(var i=this.m_arrBlock.length; i--; ) { this.m_arrBlock[i].matched = null; } rndBlock = null; }, startPoint:function(no) { this.clearMatched(); this.m_nPieceNo = no || zg.rand(this.m_parent.m_rndBlockList.length); this.set(this.m_parent.m_rndBlockList[this.m_nPieceNo]); this.regenPiece(); }, regenPiece:function() { y = int((this.m_height/B_SIZE)/2); x = int((this.m_width/B_SIZE)/2); // if(y >= 2) // y = (1-y)*B_SIZE; this.tx = (this.m_pos-1)*135+175-x-(this.m_width/4); this.ty = y*0.5-85; this.cx = (this.m_pos-1)*135+175-x-(this.m_width/4); this.cy = y*0.5-85; this.show(); this.setScale(0.5); this.setPosition(this.tx-G.W, this.ty); this.stopAllActions(); this.runAction( cc.moveTo(0.3, this.tx, this.ty) ); }, getPieceNo:function() { if(!this.isVisible()) return -1; return this.m_nPieceNo; }, setMatchEnd:function() { var block; for(var i=this.m_arrBlock.length; i--; ) { if(!this.m_arrBlock[i].matched) continue; block = this.m_arrBlock[i].matched; block.spr.setOpacity(0xff); // 골드가 존재하면 골드 획득하기 if(block.gold) { block.gold.hide(); var gold = this.m_parent.m_poolGoldGet.newSprite("gold", this.m_parent.m_lyrGame.convertToWorldSpace(block.gold)); var pt = cc.p(345, 660); // 보너스 아이템 이동하기 gold.runAction( cc.sequence( cc.spawn( cc.easeIn(cc.moveBy(0.55, cc.p((pt.x - gold.x), 0)), 3), cc.easeIn(cc.moveBy(0.55, cc.p(0, (pt.y - gold.y))), 2), cc.sequence( cc.scaleTo(0.5, 1.5), cc.scaleTo(0.3, 0.7) ) ), cc.callFunc(this.goldGet, this, block), cc.fadeOut(0.3), cc.show() ) ); block.gold = null; GameSnd.play("SOUND_GOLD_GET"); } } this.hide(); this.m_parent.checkRealMatched(this); GameSnd.play("SOUND_BLOCK_PUT"); }, goldGet:function() { MyInfo.addGold(1); }, setMatch:function() { this.runAction( cc.sequence( cc.spawn( cc.moveTo(0.07, cc.p(this.mx*B_SIZE+B_HSIZE, this.my*B_SIZE+B_HSIZE)) ), cc.callFunc(this.setMatchEnd, this) ) ); var block; for(var i=this.m_arrBlock.length; i--; ) { block = this.m_arrBlock[i]; if(!block.matched) continue; block.runAction(cc.scaleTo(0.07, 1)); block.matched.spr.show(); block.matched.no = this.m_no; } }, setEnable:function(bEnable) { if(this.m_bEnable == bEnable) return; var block; for(var i=this.m_arrBlock.length; i--; ) { block = this.m_arrBlock[i]; block.setHexColor(bEnable ? 0xffffff : 0x555555); } this.m_bEnable = bEnable; }, refresh:function() { if(!this.isVisible()) return; for(var i=this.m_arrBlock.length; i--; ) { this.m_arrBlock[i].refresh(); this.m_arrShadow[i].refresh(); } }, }); const MAX_RND_BLOCK = 3; var CGame = cc.Layer.extend({ m_bCreate:false, m_lyrTop:null, m_nLv:0, m_bChanged:false, m_btnSetting:null, m_btnMore:null, m_btnShare:null, m_btnBlockBox:null, m_btnBlockSelect:null, m_txtBlockBoxGold:null, m_bUpdate:false, m_lyrBlock:null, m_lyrEffect:null, m_poolEffect:null, m_poolGold:null, m_poolGoldGet:null, m_arrMap:[], m_arrMap2:[], m_arrBlock:[], m_arrTile:[], m_arrBack:[], m_arrNo:[], m_mapInfo:null, m_bnBlock:null, m_sprTitle:null, m_sprTitle2:null, m_state:0, m_nGameScore:0, m_bnScore:null, m_lyrScore:null, m_bTouch:false, m_bMoved:false, m_bReady:false, m_nFinishNum:0, m_nFinishTime:0, m_bScoreSave:false, m_nBestScore:0, m_nMaxNo:0, m_bContinue:true, m_txtGold:null, m_sprGold:null, m_btnGoldShop:null, m_txtGoldTarget:null, m_nGold:0, m_btnInBanner:null, m_btnGetFree:null, m_lyrGame:null, m_lyrGoldGet:null, m_rndBlock:[], m_selRndBlock:null, m_nGoldRate:50, m_rndBlockList: [ [ 2, [0,0], [1,0] ], [ 3, [0,0], [1,0], [0,1], [1,1] ], [ 7, [0,0], [1,0], [2,0], [0,1], [1,1], [2, 1], [0, 2], [1, 2], [2, 2] ], [ 4, [0,0], [1,0], [1,1] ], [ 8, [0,0], [1,0], [2,0], [1,1] ], [ 8, [0,0] ], [ 5, [0,0], [0,1], [0,2], [0,3] ], [ 6, [0,0], [0,1], [0,2] ] ], m_arrBest:null, m_http:null, m_psPang:null, m_nXS:MAP_XS, m_nYS:MAP_YS, m_txtContent:null, m_lyrReplay:null, m_lyrScore:null, m_lyrBestScore:null, m_lyrTxt:null, m_refResult:0, m_refCheck:0, m_refMatched:0, m_nMatch:0, m_arrMatch:[], m_nBlock:-1, ctor:function(db) { this._super(); cc.associateWithNative( this, cc.Layer ); var listener1 = cc.EventListener.create({ event: cc.EventListener.TOUCH_ONE_BY_ONE, swallowTouches: true, onTouchBegan: this.onTouchBegan.bind(this), onTouchMoved: this.onTouchMoved.bind(this), onTouchEnded: this.onTouchEnded.bind(this) }); cc.eventManager.addListener(listener1, this); this.hide(); }, create:function() { if(this.m_bCreate) return; // 바닥, 블록 배경 this.addChild(Main.newSprite("game_bg", G.CX, G.CY)); this.addChild(Main.newSprite("game_bg", G.CX, G.CY+500)); this.addChild(Main.newSprite("block_bg", G.CX, G.CY-28)); var i, j; for(i=0; i= GAME_CLEAR) break; this.pauseGame(); Main.m_lyrPause.open(); break; // 재시작 case BTN_REPLAY : // Main.refreshGame(); // this.continueGame(); Main.m_lyrRestart.open(); // Main.m_lyrContinue.open(); break; // 옵션 case BTN_OPTION : Main.m_lyrOption.open(); break; case BTN_BLOCKBOX : // 뽑기상자 구입골드가 부족하면 골드상점 띄우기 if(MyInfo.gold < LnkCfg.ival("BLOCKBOX_GOLD")) { Main.m_lyrGoldShop.open(); break; } // 뽑기 상자 띄우기 Main.m_lyrBlockBox.open(); MyInfo.addGold(-LnkCfg.ival("BLOCKBOX_GOLD")); break; case BTN_BLOCKSELECT : Main.m_lyrBlockSelect.open(); break; // 앱 공유하기 case BTN_SHARE2 : zs.update("$PACKAGE_NAME", Game.packageName); zs.update("$APP_URL", zs.parse(LnkG.val(Game.strOS + "_URL"))); Game.callNative("share", zs.parse(LnkLang.val("SHARE"))); break; // 스코어 보기 case BTN_RANKSCORE : Game.openLeaderBoard(LEADERBOARD("SCORE")); break; // 업적보기 case BTN_ACHIEVEMENT : Game.callNative("openAchievement"); break; case BTN_GOLDSHOP : Main.m_lyrGoldShop.open(); break; case BTN_GETFREE : this.showVideoAD(); break; case BTN_INBANNER : if(!InBanner) break; Game.sendEvent("자체배너#", encode_utf8(InBanner.id)+ "#", "클릭"); Game.openURL(InBanner.adlink); break; } }, showVideoAD:function() { return; this.m_btnGetFree.hide(); if(!Main.checkNetwork()) return; if(VideoAD.show()) { // Main.m_lyrLoading.open("REQUEST", 5); // Game.sendEvent("광고", "동영상#", "시작"); MyInfo.addGold(200); // Main.m_lyrLoading.close(); } }, onVideoAd:function(json) { // trace(json.replace('"', "")); try { json = JSON.parse(json); } catch(e) { Main.log("Error", "onVideoAd: "+ json); json = null; } if(!json) { Game.sendEvent("동영상#", "null"); Main.m_lyrLoading.close(); return; } switch(json.state) { // 동영상 광고 출력 완료 및 리워드 처리(확률: 50%) case VAD_REWARD : // this.resumeGame(); GameSnd.play("SOUND_BOX_GET"); MyInfo.addGold(LnkCfg.ival("VAD_REWARD_GOLD")); Game.sendEvent("동영상#", "성공"); LocalDB.uadd("vadCnt", 1); LocalDB.uadd("vadGold", LnkCfg.ival("VAD_REWARD_GOLD")); break; // 리워드 실패시 처리 case VAD_REWARD_FAIL : // this.setTimer(10); Game.sendEvent("동영상#", "실패"); break; case VAD_REWARD_CANCEL : // this.setTimer(10); Game.sendEvent("동영상#", "취소"); break; } Main.m_lyrLoading.close(); json = null; }, checkVideoAD:function() { return; if(!this.m_bCreate) return; this.m_btnGetFree.setVisible(VideoAD.isReady()); if(!this.m_btnGetFree.isVisible()) return; this.m_btnGetFree.mspr.stopAllActions(); this.m_btnGetFree.mspr.runAction( cc.repeatForever( cc.sequence( cc.scaleTo(0.3, 1.08), cc.scaleTo(0.2, 1), cc.delayTime(0.3) ) ) ); }, onChangeGold:function() { // 현재 화면이 보이지 않으면 골드 바로 갱신하고 아니면 슬로우 모션으로 갱신하기 if(this.isVisible() == false) this.m_txtGold.setString(MyInfo.gold); else this.slowCountGold(MyInfo.gold); this.m_nGold = MyInfo.gold; }, slowCountGold:function(gold) { this.m_sprGold.stopAllActions(); this.unscheduleUpdate(); this.m_txtGoldTarget.setPosition(this.m_nGold, this.m_nGold); // 점수 글자 1.5배 키우기 this.m_txtGold.runAction( cc.sequence( cc.easeElasticOut( cc.scaleTo(1.0, 1.2/G.TF), 0.8 ) ) ); // 점수 천천히 올리기 this.m_txtGoldTarget.runAction( cc.sequence( cc.easeSineIn( cc.moveTo(0.7, cc.p(gold, gold)) ), cc.delayTime(0.15), cc.callFunc(this.endUpdate, this) ) ); this.m_sprGold.runAction( cc.repeatForever( cc.sequence( cc.scaleTo(0.2, 1.1), cc.scaleTo(0.2, 0.75) ) ) ); this.scheduleUpdate(); }, update:function() { this.m_txtGold.setString(int(this.m_txtGoldTarget.x)); }, endUpdate:function() { this.unscheduleUpdate(); this.m_txtGold.setString(this.m_nGold); this.m_txtGold.runAction( cc.sequence( cc.easeElasticIn( cc.scaleTo(0.4, 1/G.TF), 0.8 ) ) ); this.m_sprGold.stopAllActions(); this.m_sprGold.setScale(0.75); }, addScore:function(nScore) { this.m_nGameScore += nScore; this.m_lyrScore.setScore(this.m_nGameScore); ScoreCrypt.add(nScore); }, readyGame:function(lv) { this.m_nLv = lv; this.create(); this.show(); Main.m_fadeBlock.fade(0.12, FADE_IN); // this.m_sprTitle2.visible = false; this.m_poolGold.hideAll(); var tile; var spr; for(var i=0; i=0) this.m_rndBlock[i].startPoint(arrData.piece[i]); } arrData = null; i = null; tile = null; this.checkResult(); // Main.m_lyrContinue.open(); } else { // 점수 초기화 this.m_lyrScore.setScore(0); this.regenRndBlock(true); } this.m_bChanged = false; /* this.checkVideoAD(); // 동영상 광고가 보이지 않으면 3초후에 체크하기 if(!this.m_btnGetFree.isVisible()) { this.m_btnGetFree.runAction( cc.sequence( cc.delayTime(1.5), cc.callFunc(this.checkVideoAD, this) ) ); } */ // GameSnd.playMusic("music", true); this.resumeGame(); GC(); // cc.sys.garbageCollect(); // 도움말 if(G.iVal("HELP") < 1) { Main.m_lyrHelp.open(); } // 평가하기 보여주지 않았으면 처리하기 else if(G.iVal("REVIEW_OK") < 1 && G.iVal("REVIEW_SHOW_OK") < 1) { // 기록갱신 2회정도 이루어 졌다면 평가하기 보여주기 for(var i=1; i<=3; i++) { // 평가하기 보이기 체크하기 if(G.iVal("BESTSCORE_CNT") != LnkCfg.ival("REVIEW_SHOW" + i)) continue; Main.m_lyrReview.open(); G.setVal("REVIEW_SHOW_OK", 1); } } // Game.callNative("AdColony_load"); VideoAD.load(); this.requestInAD(); this.m_bMoved = false; this.m_bTouch = false; this.m_bReady = false; // 이어하기 여부 this.m_bContinue = true; }, saveGame:function() { // 변경이 되지 않았으면 패스... if(!this.m_bChanged) return; var arrData = { "score": ScoreCrypt.getIntScore(), "data": [], "piece":[], }; var i, j, tile; for(i=0; i0) continue; match = 0; for(j=rndBlock.m_arrBlock.length; j--;) { block = rndBlock.m_arrBlock[j]; if(tile.by+block.by >= this.m_nYS) break; if(tile.bx+block.bx >= this.m_nXS) break; cblock = arrMap[tile.by+block.by][tile.bx+block.bx]; if(!cblock || cblock.no > 0) break; match++; } // 매치 성공했으면 빠져나가기 if(match == rndBlock.m_arrBlock.length) break; } i = null; j = null; tile = null; block = null; arrMap = null; cblock = null; return match == rndBlock.m_arrBlock.length; }, checkResult:function() { var rndBlock; var nCnt = 0; var i, j; // 랜덤블록 체크하기 for(i=0; i 0) return; nCnt = null; Main.m_lyrContinue.open(); }, readyResult:function() { // 더이상 끼워넣을 공간이 없을경우 결과창 띄우기 this.m_refResult = 0; var map; for(i=0; i 0) return; this.runAction( cc.sequence( cc.delayTime(0.5), cc.callFunc(this.gameover, this) ) ); }, checkTestMatched:function(rndBlock) { var arrBlock = rndBlock.m_arrBlock; var arrMap = this.m_arrMap; var map; var bx, by; var arrMatched = []; // this.m_arrMap[wpt.y][wpt.x].spr.show(); for(var i=arrBlock.length; i--; ) { bx = arrBlock[i].bx+rndBlock.mx; by = arrBlock[i].by+rndBlock.my; if(bx<0 || by<0) break; if(bx >= this.m_nXS) break; if(by >= this.m_nYS) break; map = arrMap[by][bx]; if(map == null) continue; if(map.no) break; arrMatched.push([map, arrBlock[i]]); } for(var i=arrBlock.length; i--; ) { if(arrBlock[i].matched) { arrBlock[i].matched.spr.hide(); } } rndBlock.m_bMatched = arrMatched.length == arrBlock.length; // 되돌리기 this.testRestoreMatch(); // 매치되는게 있는지 체크하기 if(rndBlock.m_bMatched) { for(i=arrMatched.length; i--;) { arrMatched[i][0].spr.show(); arrMatched[i][0].spr.setOpacity(0x88); arrMatched[i][0].spr.stop(rndBlock.m_no); arrMatched[i][1].matched = arrMatched[i][0]; } // 맞춰지는게 있는지 체크하기 this.testMatched(rndBlock); } arrBlock = null; arrMap = null; map = null; bx = null; by = null; arrMatched = null; }, testRestoreMatch:function() { if(this.m_nMatch < 1) return; var i; var block; for(i=this.m_nMatch; i--; ) { block = this.m_arrMatch[i][0]; block.spr.stop(this.m_arrMatch[i][1]); } this.m_nMatch = 0; }, testMatched:function(selRndBlock) { this.m_nMatch = 0; var block; var arrHLine = null; var arrVLine = null; var i, j; var arrCheckHLine = []; var arrCheckVLine = []; for(i=selRndBlock.m_arrBlock.length; i--; ) { block = selRndBlock.m_arrBlock[i].matched; if(block == null) continue; // 가로라인 조사하기 if(!arrCheckHLine[block.by] && this.testHLine(block.by)) { if(!arrHLine) arrHLine = []; arrHLine.push(block); arrCheckHLine[block.by] = 1; } // 세로라인 조사하기 if(!arrCheckVLine[block.bx] && this.testVLine(block.bx)) { if(!arrVLine) arrVLine = []; arrVLine.push(block); arrCheckVLine[block.bx] = 1; } } var bx, by; var score = 0; var combo = 0; // 가로라인 없애기 if(arrHLine) { for(i=arrHLine.length; i--;) { bx = arrHLine[i].bx; by = arrHLine[i].by; for(j=0; j= this.m_nXS || wpt.y >= this.m_nYS) return false; // this.m_arrMap[wpt.y][wpt.x].spr.show(); this.m_bMoved = false; this.m_bTouch = true; this.m_bReady = false; // this.m_ptMoved = touch[0].getLocation(); this.m_ptMoved = touch.getLocation(); return true; }, onTouchMoved: function(touch, event) { // 이미 이동하였으면 처리... if(this.m_bMoved == true) { touch = null; event = null; return; } // var pt = touch[0].getLocation(); var pt = touch.getLocation(); var wpt = this.m_lyrGame.convertToNodeSpace(pt); if(this.m_selRndBlock) { this.m_selRndBlock.setPosition(wpt.x, wpt.y+100); var mx, my; mx = int((this.m_selRndBlock.x)/B_SIZE); my = int((this.m_selRndBlock.y)/B_SIZE); if(mx != this.m_selRndBlock.mx || my != this.m_selRndBlock.my) { this.m_selRndBlock.mx = mx; this.m_selRndBlock.my = my; this.checkTestMatched(this.m_selRndBlock); } } return; if(Math.abs(this.m_ptMoved.x - pt.x) > 30 || Math.abs(this.m_ptMoved.y - pt.y) > 30) { this.m_bMoved = true; this.m_bReady = true; if(this.checkGameOver() == false) { // this.moveBlock(pt.x - this.m_ptMoved.x, pt.y - this.m_ptMoved.y); // if(int(Game.callGetJni("AdColony_isReady")) == 1) // { // Main.m_lyrContinue.open(); // } // Game.adMob(true); // trace("///"); } else { // 이어하기 가능이면 처리하기 if(this.m_bContinue == true && VideoAD.isReady() == true) { Main.m_lyrContinue.open(); // 이어하기 불가로 설정하기 // this.m_bContinue = false; } else { // this.m_state = GAME_OVER; this.gameover(); } } } touch = null; event = null; pt = null; }, onTouchEnded: function(touch, event) { this.m_ptMoved = null; this.m_bTouch = false; this.m_bReady = false; // 선택된 랜덤블록이 있으면 처리하기 if(this.m_selRndBlock) { // 매치 가능하면 처리하기 if(this.m_selRndBlock.m_bMatched) { this.setMatch(); } // 매치 가능한 블록이 없으면, 되돌리기 else { this.m_selRndBlock.restore(); } this.m_selRndBlock = null; } touch = null; event = null; }, checkGameOver:function() { var i, j; var arrTile = this.m_arrTile; // 타일이 모두 생성되었는지 체크한다... for(i=arrTile.length-1; i>=0; i--) { if(arrTile[i].spr == null) { i = null; j = null; arrTile = null; return false; } } // 실제로 타일 체크하기... for(i=0; i=0; i--) { if(arrTile[i].spr == null) return false; ScoreCrypt.add(Math.pow(2, arrTile[i].spr.no)); } } i = null; j = null; arrTile = null; return true; }, onEmpty:function(obj) { obj.bHide = null; }, onHide:function(obj) { if(obj.bHide == null) return; obj.no = 0; obj.tile = null; obj.hide(); obj.bHide = null; }, getDirection:function(dia, angle) { return cc.p(dia * Math.cos(angle * M_DEG), -dia * Math.sin(angle * M_DEG)); }, onUp:function(obj) { if(obj.bUp == null) return; obj.bUp = null; obj.no++; obj.stop(obj.no); obj.setScale(0.8); obj.runAction( cc.sequence( cc.easeElasticOut(cc.scaleTo(0.4, 1.0), 1.0) ) ); if(obj.no >= 7) { spr = this.m_poolEffect.newSprite("effCircle", obj.x, obj.y); spr.setScale(0.4); spr.runAction( cc.sequence( cc.spawn( cc.scaleTo(0.4, 1.5), cc.fadeOut(0.4) ), cc.hide() ) ); // 별 이팩트 var arrStar = [ [0.3, 1, 75, -120], [0.2, 0.5, 70, -45], [0.3, 0.5, 75, 45], ]; var starNum = obj.no - 3; var angleStep = 360/starNum; var angle = zg.rand(angleStep); for(i=0; i this.m_nFinishNum) { /* var alpha = int(Math.pow(1.5, obj.no) / this.m_nMaxNo * 255); // var alpha = int((obj.no * obj.no) / this.m_nMaxNo * 255); if(alpha > 255) alpha = 255; // this.m_sprTitle.setColor(cc.color(alpha, alpha, alpha, 0xff)); */ this.m_nFinishNum = obj.no; var nNo = Math.pow(2, obj.no); // 구글 로그인이 되어 있을 경우에만 처리하기 // 32부터 32768사이이면 업적 unlock하기 if(Login.type == LOGIN_GOOGLE && (nNo >= 32 && nNo <= 32768)) { var aCode = "MAKE_" + nNo; // 업데이트가 안된 업적이면 처리하기 if(G.iVal(aCode) < 1) { Game.callNative("unlockAchievement", Game.getRes(aCode)); G.setVal(aCode, 1) } } nNo = null; //unlockAchievement /* if(obj.no < 8) { this.lyrBg.setColor(XRGB(0x826218)); } else { // 2:4, 3:8, 4:16, 5:32, 6:64, 7:128, 8:256, 9:512, 10:1024, 11:2048, 12:4096 // 256-083501 // 512-601060 // 1024-620101 // 2048-a50078 switch(obj.no) { case 8 : this.lyrBg.setColor(XRGB(0x083518)); break; case 9 : this.lyrBg.setColor(XRGB(0x601060)); break; case 10 : this.lyrBg.setColor(XRGB(0x620101)); break; case 11 : this.lyrBg.setColor(XRGB(0xa50078)); break; default : this.lyrBg.setColor(XRGB(0xa50078)); break; } } */ // 4096에 도달했다면 도달 시간 저장하기... if(obj.no == LnkCfg.ival("GAME_FINISH")) { this.finish4096(); Game.submitScore("TIME", Math.round(this.m_nFinishTime), true); } // Game.saveScore(LEADERBOARD_TIME, Math.round(this.m_nFinishTime), true); } this.addScore(Math.pow(2, obj.no)); // this.m_bnScore.add(obj.getPositionX(), obj.getPositionY(), Math.pow(2, obj.no), 101); }, gameover:function() { GameSnd.stopMusic(); if(this.m_bScoreSave == false) { // this.m_nBestScore = Game.getHighScore(LEADERBOARD_SCORE); // Game.saveScore(LEADERBOARD_SCORE, ScoreCrypt.getIntScore()); this.m_nBestScore = Game.getScore("SCORE"); Game.submitScore("SCORE", ScoreCrypt.getIntScore()); this.m_bScoreSave = true; } // 미션실패 (4096보다 작으면 처리하기) if(this.m_nFinishNum < LnkCfg.ival("GAME_FINISH")) { // Game.openInterstitial(1); // GameSnd.play("fail"); } else { // GameSnd.playMusic("success"); } this.pauseGame(); Main.m_fadeBlock.fade(0.12, 200); Main.m_lyrResult.open(this.m_nFinishNum, ScoreCrypt.getIntScore(), this.m_nBestScore); GC(); this.m_state = 99; }, /* update:function(dt) { trace("sfsfsdf"); this.m_nFinishTime += dt; switch(this.m_state) { case GAME_OVER : GameSnd.stopMusic(); if(this.m_bScoreSave == false) { // this.m_nBestScore = Game.getHighScore(LEADERBOARD_SCORE); // Game.saveScore(LEADERBOARD_SCORE, ScoreCrypt.getIntScore()); this.m_nBestScore = Game.getScore("SCORE"); Game.submitScore("SCORE", ScoreCrypt.getIntScore()); this.m_bScoreSave = true; } // 미션실패 (4096보다 작으면 처리하기) if(this.m_nFinishNum < LnkCfg.ival("GAME_FINISH")) { // Game.openInterstitial(1); // GameSnd.play("fail"); } else { // GameSnd.playMusic("success"); } this.pauseGame(); Main.m_fadeBlock.fade(0.12, 200); Main.m_lyrResult.open(this.m_nFinishNum, ScoreCrypt.getIntScore(), this.m_nBestScore); GC(); this.m_state = 99; break; } }, */ onEnter:function() { this._super(); // this.setTouchEnabled(true); // cc.registerTargetedDelegate(-Main.getLocalZOrder()-this.getLocalZOrder()-1, false, this); }, onExit:function() { // cc.unregisterTouchDelegate(this); this._super(); // message("xxx"); }, }); var CMain = cc.Class.extend({ m_gameDB:null, m_lyrGame:null, m_lyrResult:null, m_lyrCollection:null, m_lyrOption:null, m_lyrHelp:null, m_lyrGoldShop:null, m_lyrLoading:null, m_lyrBlockBox:null, m_lyrBlockSelect:null, m_sprBG:null, m_fadeBlock:null, m_fadeBlockBlack:null, m_fadeBlockWhite:null, m_scene:null, ctor:function(scene) { this.m_scene = scene; }, addChild:function(lyr, zIndex) { this.m_scene.addChild(lyr, zIndex); }, newChild:function(lyr, zIndex) { this.addChild(lyr, zIndex || 110); return lyr; }, newSprite:function(name, x, y) { return this.m_gameDB.newSprite(name, x, y); }, getSprite:function(name) { return this.m_gameDB.getSprite(name); }, createButton:function(x, y, id, name, rec, func) { var btn = new zg.JellyButton(id, name); btn.onTouchEvent(rec, func); btn.setPosition(x, y); return btn; }, createTextButton:function(x, y, id, name, rec, func) { var btn = new zg.JellyButton(id, name); btn.onTouchEvent(rec, func); btn.setPosition(x, y); // txt btn.txt = BFont.create(0, 0, TEXT_CENTER, "", 18); btn.addChild(btn.txt); btn.txt.setColor(cc.WHITE); // btn.txt.setBold(1); return btn; }, refreshGame:function() { this.m_lyrGame.clearGame(); Game.openInterstitial(0); this.m_lyrGame.readyGame(this.m_nLv); }, resumeGame:function() { this.m_fadeBlock.fade(0.12, FADE_IN); this.m_lyrGame.resumeGame(); }, continueGame:function() { this.m_fadeBlock.fade(0.12, FADE_IN); this.m_lyrGame.continueGame(); }, checkNetwork:function() { return true; }, newSpine:function(file, name, x, y, loop) { var spineBoy = new sp.SkeletonAnimation(Game.imageDir + '/'+ file +'.json', Game.imageDir + '/'+ file +'.atlas'); spineBoy.setPosition(x, y); // spineBoy.setAnchorPoint(0.5, 0.5); // spineBoy.setAnimation(0, name, loop || false); return spineBoy; }, log:function() { }, // 자체배너 확률 데이타 만들기 getInAD:function() { if(GameBoost.arrInAD == null) { GameBoost.arrInAD = []; for(i in GameBoost.inad) { GameBoost.inad[i].id = i; GameBoost.arrInAD.push({"ad": i, "rate":GameBoost.inad[i].adrate}) } } var ad = RandNo(GameBoost.arrInAD); if(ad == null) return null; return GameBoost.inad[ad.ad]; }, dnload:function(id, url) { // this.m_dnload.load(id, url); }, onMain:function () { G.init(480, 800, cc.ResolutionPolicy.SHOW_ALL); TRACE_COLOR = cc.color(cc.color.WHITE); cLayer = this; this.m_scene.y += 80; BackKey.push(this); COLLECTION_FINISH = LnkCfg.ival("COLLECTION_FINISH"); G.setJellyTouchScale(0.99999); // 최초 1회 접속시에만 아이템 지급하기 if(LocalDB.ival("START") < 1) { // 골드 및 시작아이템 지급하기 LocalDB.uadd("gold", LnkCfg.ival("START_GOLD")); LocalDB.update("START", 1); LocalDB.update("DAYREWARD_DATE", Now.date()); } // 데이타 읽어들이기 (한꺼번에) LocalDB.ival(MyInfo, "gold, star"); this.m_gameDB = new zg.SpriteDB(); this.m_gameDB.load("image/game.slist"); GameBoost = JSON.loadFromRes(GAMEBOOST_CFG); this.m_lyrGame = this.newChild(new CGame(this.m_mapDB), 20); // 게임 this.m_lyrResult = this.newChild(new CResult()); // 결과 this.m_lyrCollection = this.newChild(new CCollection()); // 콜랙션 this.m_lyrOption = this.newChild(new COption()); // 옵션 this.m_lyrHelp = this.newChild(new CHelp(), 120); // 도움말 this.m_lyrContinue = this.newChild(new CContinue()); // 이어하기 this.m_lyrRestart = this.newChild(new CRestart()); // 다시시작 this.m_lyrBlockBox = this.newChild(new CBlockBox()); // 블록 뽑기 상자 this.m_lyrBlockSelect = this.newChild(new CBlockSelect()); // 블록 콜렉션 this.m_lyrGoldShop = this.newChild(new CGoldShop(), 150); // 골드상점 this.m_lyrLoading = this.newChild(new CLoading(), 199); // 로딩중 this.m_sprBG = this.newSprite("game_bg", G.CX, G.CY); this.addChild(this.m_sprBG, 98); this.m_sprBG.hide(); // 페이드 this.m_fadeBlock = new zg.Fade(G.RX, G.RY, G.RW, G.RH, 0x000000); this.addChild(this.m_fadeBlock, 99); this.m_fadeBlockBlack = new zg.Fade(G.RX, G.RY, G.RW, G.RH, 0x000000); this.addChild(this.m_fadeBlockBlack, 99); this.m_fadeBlockWhite = new zg.Fade(G.RX, G.RY, G.RW, G.RH, 0xff0000); this.addChild(this.m_fadeBlockWhite, 99); this.m_lyrGame.readyGame(); } });