123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961 |
- cc.Class({
- extends: cc.Component,
- properties: {
- fishingLayerNode: cc.Node,
- gameBg: cc.Node,
- pondLayer: cc.Node,
- hook: cc.Node,
- topMoenyLabel: cc.Label,
- spineMao: cc.Node,
- btnNode: [cc.Node],
- sellLayer: cc.Node, //卖鱼弹窗
- fameLayer: cc.Node,//捕捉传说鱼界面
- tujian: cc.Node,//图鉴
- xuli: cc.Node, // 蓄力
- sellingFishAction: cc.Node, //卖鱼特效
- guide: cc.Node, //新手引导
- tishi: cc.Node, //提示弹窗
- offlineLayer: cc.Node,//离线奖励
- everydayGift: cc.Node,//每日礼包
- },
- /**
- * 加载配置表,再初始化场景
- */
- onLoad () {
- // this.initWxData();
- this.initStorageData();
- this.loadSpriteFrame();
- this.loadConfig(function(){
- this.initScene();
- }.bind(this));
- window.Utils.playSound('sound/bgm' , 1, true);
-
- },
- start(){
- this.initWxData();
- },
- initStorageData: function() {
- for (var i = 0; i < 24; i++) {
- if (i == 0) {
- Module.tujianFishing.push(true);
- continue;
- }
- Module.tujianFishing.push(false);
- }
- Module.offlineTime = window.Utils.getStringForKey("offlineTime" , Module.offlineTime);
- Module.money = window.Utils.getIntegerForKey("diaoyu_money" , Module.money);
- Module.gravitation = window.Utils.getIntegerForKey("diaoyu_gravitation" , Module.gravitation);
- Module.fishingNumLimit = window.Utils.getIntegerForKey("diaoyu_fishingNumLimit" , Module.fishingNumLimit);
- Module.getGiftNum = window.Utils.getIntegerForKey("diaoyu_getGiftNum" , Module.getGiftNum);
- var tujianFishing = window.Utils.getStringForKey("diaoyu_tujianFishing" , Module.tujianFishing);
- Module.tujianFishing = [];
- tujianFishing = tujianFishing.split(",");
-
- if (Module.offlineTime == "") {
- var today = Date.parse(new Date());
- Module.offlineTime = today;
- window.Utils.setStringForKey("offlineTime" , Module.offlineTime);
- }
- for (var i = 0; i < tujianFishing.length; i++) {
- if (tujianFishing[i] == "true") {
- Module.tujianFishing.push(true);
- } else {
- Module.tujianFishing.push(false);
- }
- }
- var day = new Date();
- var today = day.toLocaleDateString();
- var lastSignDay = window.Utils.getStringForKey("lastLoginDay","");
- console.log("--lastSignDay---: " , lastSignDay);
- //新的一天
- if (today != lastSignDay) {
- window.Utils.setStringForKey("lastLoginDay",today);
- Module.getGiftNum = 0;
- }
-
- },
- privacyEvent(){
- cc.sys.openURL('https://pricends.xyz/privacy.html');
- },
- teamEvent(){
- cc.sys.openURL('https://pricends.xyz');
- },
- initWxData: function() {
-
- },
- loadSpriteFrame: function() {
- cc.loader.loadRes('tujian/ui_ptk', cc.SpriteFrame, function(err, spFrame) {
- if (err) {
- cc.log(err.message || err);
- return;
- }
- }.bind(this));
- cc.loader.loadRes('tujian/ui_ssk', cc.SpriteFrame, function(err, spFrame) {
- if (err) {
- cc.log(err.message || err);
- return;
- }
- }.bind(this));
- cc.loader.loadRes('prefab/discoverLayer', function (err, res) {
- if (err) {
- cc.log(err.message || err);
- fun();
- return;
- }
- this.discoverLayer = res;
- }.bind(this));
- },
- /**
- * 加载配置表
- * @param {*} func 加载好后回调
- */
- loadConfig: function(func) {
- window.Config.fishingBait.price = [];
- window.Config.fishingBait.gravitation = [];
- window.Config.fishRod.price = [];
- window.Config.fishRod.weight = [];
- window.Config.fishing.price = [];
- window.Config.fishing.weight = [];
- window.Config.fishing.catch = [];
- window.Config.fishing.name = [];
- window.Config.fishing.des = [];
-
- CSVParse.parseConfig("config/config.csv", function (data) {
- if (data && data.length > 1) {
-
- for (var i = 1; i < data.length; i++) {
- if (data[i].length > 0) {
- for (var j = 0; j < data[i].length; j++) {
- if (data[i][j] === "") data[i][j] = 0;
- if (j > 0) {
- if (j == 1) {
- //鱼饵
- window.Config.fishingBait.price.push(parseInt(data[i][j]));
- } else if (j == 2) {
- //吸引力
- window.Config.fishingBait.gravitation.push(parseInt(data[i][j]));
- } else if (j == 3) {
- //鱼竿价格
- window.Config.fishRod.price.push(parseInt(data[i][j]));
- } else if (j == 4) {
- //重量
- window.Config.fishRod.weight.push(parseInt(data[i][j]));
- } else if (i > 1 && j == 6) {
- //鱼价格
- window.Config.fishing.price.push(parseInt(data[i][j]));
- } else if (i > 1 && j == 7) {
- //鱼重量
- window.Config.fishing.weight.push(parseInt(data[i][j]));
- } else if (i > 1 && j == 8) {
- //鱼捕捉度
- window.Config.fishing.catch.push(parseInt(data[i][j]));
- } else if (i > 1 && j == 9 && data[i][j] != 0) {
- //鱼名
- console.log("---data[i][j]---: " , data[i][j]);
- window.Config.fishing.name.push(data[i][j]);
- } else if (i > 1 && j == 10 && data[i][j] != 0) {
- //鱼描述
- window.Config.fishing.des.push(data[i][j]);
- }
- }
- }
- }
- }
- }
- for (var k = 0; k < window.Config.fishing.des.length; k++) {
- if (window.Config.fishing.des[k].length > 15) window.Config.fishing.des[k] = window.Config.fishing.des[k].replace(/(.{15})/, "$1\n");
- }
- //succecc
- if (func) func();
- }.bind(this));
- },
- /**
- * 鱼的预制体
- * @param {*} index 鱼的tag值
- * @param {*} fun 加载完毕回调
- */
- loadPrefab: function(index, fun) {
- var name = 'prefab/fishing' + index;
- cc.loader.loadRes(name, function (err, res) {
- ++index;
- Module.prefabArr.push(res);
- if (err) {
- cc.log(err.message || err);
- fun();
- return;
- }
- this.loadPrefab(index, fun);
- }.bind(this));
- },
- /**
- * 初始化当前场景
- */
- initScene: function() {
- wb.ADManager.openAd("banner");
- Module.gameState = false;
- Module.gameObj = this;
- Module.prefabArr = [];
- this.prefabLength = 4;
- this.pondNodeY = this.pondLayer.y;
- this.touchCount = 0;
- this.giftFlag = true;
- this.offLine();
- this.xuli.active = false;
- this.pondLayerPos = this.pondLayer.getPosition();
- this.depth = 0; //当前水深
- this.touchStart = false;
- this.initVigorData();
- this.gameBg.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
- this.gameBg.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoving.bind(this), this );
- this.gameBg.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this), this );
- this.gameBg.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel.bind(this), this );
-
- cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, this.onEnterForeground.bind(this));
- cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, this.onEnterBackground.bind(this));
-
- this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
- this.pondLayer.getChildByName('fishingNode').zIndex = 10;
- this.loadPrefab(1,function(){
- }.bind(this));
- cc.loader.loadRes('prefab/addFishingBg', function (err, res) {
- Module.addMoneyLabel = res;
- }.bind(this));
- this.goFishingLayer = this.fishingLayerNode;
- this.goFishingLayer.active = false;
- this.setWeightLabel();
- //主页按钮
- for (var i = 0; i < this.btnNode.length; i++) {
- var btn = this.btnNode[i].getComponent(cc.Button);
- btn.node.on('click', this.callback, this);
- btn.node.on(cc.Node.EventType.TOUCH_START, window.btnState.touchBegin.bind(this), this );
- btn.node.on(cc.Node.EventType.TOUCH_MOVE, window.btnState.touchMoving.bind(this), this );
- btn.node.on(cc.Node.EventType.TOUCH_END, window.btnState.touchEnd.bind(this), this );
- btn.node.on(cc.Node.EventType.TOUCH_CANCEL, window.btnState.touchCancel.bind(this), this );
- }
- //鱼饵
- this.btnNode[7].getChildByName('gravitation').getComponent(cc.Label).string = window.Utils.getfishingBaitGravitation();
- this.btnNode[7].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishingBaitPrice();
- //鱼杆
- this.btnNode[8].getChildByName('weight').getComponent(cc.Label).string = window.Utils.getfishRodWeight();
- this.btnNode[8].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishRodPrice();
- //卖鱼界面
- this.sellLayer.getChildByName('bg').getChildByName('sellMoney').on('click', this.callback, this);
- this.sellLayer.getChildByName('bg').getChildByName('sellVideo').on('click', this.callback, this);
- this.sellLayer.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
-
- //提示(有机会碰到传说鱼)
- this.tishiTip1 = this.createTishiLayer("There's a chance to encounter a legendary fish in the red area!~");
- this.tishiTip1.active = false;
- //提示(传说鱼出没!!)
- this.tishiTip2 = this.createTishiLayer("The legendary fish is appearing.!!");
- this.tishiTip2.active = false;
- console.log("--window.Config.fishing.name--: " , window.Config.fishing.des);
- },
- /**
- * 离线奖励
- * 离线超过1小时给与奖励,根据鱼竿重量来给
- */
- offLine: function() {
- var today = Date.parse(new Date());
- var time =parseInt((today-Module.offlineTime) / 1000 /60) ;
- console.log("---time--: " , time);
- if (time >= 60) {
- this.offlineLayer.active = true;
- this.offlineLayer.getComponent("offline").init(window.Utils.getfishRodPrice() * 2);
- }
- },
- /*进入后台*/
- onEnterBackground: function () {
- cc.log("-----进入后台-------");
- var today = Date.parse(new Date());
- console.log("--onShow==============-today--: " , today);
- Module.offlineTime = today;
- window.Utils.setStringForKey("offlineTime" , today);
- },
- /*返回游戏*/
- onEnterForeground: function () {
- var today = Date.parse(new Date());
- var time = parseInt((today-Module.offlineTime) / 1000 /60);
- console.log("--onShow==============-time--: " , time);
- if (time >= 60) {
- this.offlineLayer.active = true;
- this.offlineLayer.getComponent("offline").init(window.Utils.getfishRodPrice() * 2);
- }
- var today = Date.parse(new Date());
- Module.offlineTime = today;
- window.Utils.setStringForKey("offlineTime" , today);
- },
- /**
- * 初始化蓄力数据
- */
- initVigorData: function() {
- this.vigorSum = 16;
- this.vigorRandomVal = window.Utils.random(1,16);
- var call = cc.callFunc(function(){
- this.vigorNum = 1;
- this.vigorTime = 1;
- this.vigorFlag = false;
- }.bind(this));
- for (var i = 1; i < this.vigorSum +1; i++) {
- this.xuli.getChildByName("ui_tiao"+i).active = false;
- if (this.vigorRandomVal == i) {
- this.xuli.getChildByName("tiao"+i).active = true;
- } else {
- this.xuli.getChildByName("tiao"+i).active = false;
- }
- }
- this.node.runAction(cc.sequence(cc.delayTime(0.5) , call));
- },
-
- /**
- * 主界面按钮回调
- * @param {*} target 按钮对象
- */
- callback: function(target){
- var name = target.node.name;
- window.Utils.playSound('sound/button' , 2, false);
- if (name == "fishingRod") {
- //鱼杠
- this.fishingRod(target);
- } else if (name == "fishingBait") {
- //鱼饵
- this.fishingBait(target);
- } else if (name == "sellMoney") {
- //卖鱼按钮
- this.buyFishing();
- } else if (name == "sellVideo") {
- //看视频,卖鱼按钮
- this.buyFishingVideo();
- } else if (name == "sound") {
- //声音
- this.soundOnOff(target);
- } else if (name == "tujian") {
- //图鉴
- wb.ADManager.openAd("banner");
- this.tujian.active = true;
- Module.tujianObj.refresh();
- } else if (name == "scene") {
- //场景
- this.popupTishiLayer("Not open yet~");
- } else if (name == "gift") {
- Module.getGiftNum == 0 ? this.everydayGift.active = true : this.popupTishiLayer("Today's number has been exhausted~");
- }
- },
- buyFishingVideo: function() {
- wb.ADManager.openAdC("video", function (a, result) {
- if(result == 0){
- this.OverInit();
- window.Utils.playSound('sound/sell' , 2, false);
- window.Utils.playEffectSpine('effect/effect5/jb.json', 'action', this.node, 0.8);
-
- }else{
- this.popupTishiLayer("视频未播放完~");
- }
- }.bind(this));
-
- },
- //卖鱼按钮
- buyFishing: function() {
- Module.nonceMoney /= this.beishu;
- this.OverInit();
- window.Utils.playSound('sound/sell' , 2, false);
- window.Utils.playEffectSpine('effect/effect5/jb.json', 'action', this.node, 0.8);
- },
- /**
- * 声音开关
- * @param {*} target 声音按钮对象
- */
- soundOnOff: function(target) {
- if (target.node.getChildByName('on').active) {
- Module.isPlaySound = false;
- cc.audioEngine.pauseAll();
- target.node.getChildByName('on').active = false;
- target.node.getChildByName('off').active = true;
- } else {
- Module.isPlaySound = true;
- cc.audioEngine.resumeAll();
- target.node.getChildByName('on').active = true;
- target.node.getChildByName('off').active = false;
- }
- },
- /**
- * 鱼竿
- */
- fishingRod: function(target) {
- if (Module.money > window.Utils.getfishRodPrice()) {
- Module.money -= window.Utils.getfishRodPrice();
- window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
- var num = window.Utils.getfishRodWeight() - Module.fishingNumLimit;
- Module.fishingNumLimit = window.Utils.getfishRodWeight();
- window.Utils.setIntegerForKey("diaoyu_fishingNumLimit" , Module.fishingNumLimit);
- //刷新金币 重量
- this.setMoney();
- this.setWeightLabel();
- this.btnNode[8].getChildByName('weight').getComponent(cc.Label).string = window.Utils.getfishRodWeight();
- this.btnNode[8].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishRodPrice();
-
- //飘字
- var node =new cc.Node("node");
- var label = node.addComponent(cc.Label);
- label.string= "+" + num;
- label.fontSize= 24;
- var color=new cc.Color(40,98, 143);
- node.position=cc.v2(target.node.x,target.node.y);
- node.color=color;
- node.parent = this.node;
- node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.8, cc.v2(0,120)), cc.delayTime(0.2),cc.removeSelf()));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', target.node, 0.9 , cc.v2(0,27));
- } else {
- console.log("--------金币不足----------");
- this.popupTishiLayer("Meow is too poor to afford it~");
- }
- },
- /**
- * 鱼饵
- */
- fishingBait: function(target) {
- if (Module.money > window.Utils.getfishingBaitPrice()) {
- Module.money -= window.Utils.getfishingBaitPrice();
- window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
- var num = window.Utils.getfishingBaitGravitation() - Module.gravitation;
- Module.gravitation = window.Utils.getfishingBaitGravitation();
- window.Utils.setIntegerForKey("diaoyu_gravitation", Module.gravitation);
- this.setMoney();
- //刷新价格 吸引力
- this.btnNode[7].getChildByName('gravitation').getComponent(cc.Label).string = window.Utils.getfishingBaitGravitation();
- this.btnNode[7].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishingBaitPrice();
- //飘字
- var node =new cc.Node("node");
- var label = node.addComponent(cc.Label);
- label.string= "+" + num;
- label.fontSize= 24;
- var color=new cc.Color(40,98, 143);
- node.position=cc.v2(target.node.x,target.node.y);
- node.color=color;
- node.parent = this.node;
- node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.8, cc.v2(0,120)), cc.delayTime(0.2),cc.removeSelf()));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', target.node, 0.9 , cc.v2(0,27));
-
- } else {
- console.log("--------金币不足----------");
- this.popupTishiLayer("Meow is too poor to afford it~");
- }
- },
- /**
- * 开始钓鱼
- */
- gameStart: function(){
- wb.ADManager.closeAd("banner");
- this.spineMao.getComponent(sp.Skeleton).animation = "action01";
- for (var i = 1; i < this.vigorSum +1; i++) {
- if (this.xuli.getChildByName("ui_tiao"+i).active) this.vigorNum = i;
- }
- if (this.vigorNum == this.vigorRandomVal) {
- this.tishiTip1.active = false;
- this.tishiTip2.active = true;
- }
-
- var call = cc.callFunc(function(){
- // this.gameBg.active = false;
- }.bind(this));
- var count = parseInt(Module.depth / 10);
-
- Module.isCollision = true;
- this.xuli.active = false;
- this.loadPondLyaer();
- Module.gameState = true;
- this.goFishingLayer.active = false;
- this.tishiTip1.active = false;
- Module.isShowHook = false;
- Module.nonceFishingArr = [];
- this.hook.removeAllChildren();
- this.getBeishu();
- //鱼钩到底后回拉
- var call2 = cc.callFunc(function(){
- var call3 = cc.callFunc(function(){
- // this.OverInit();
- this.sellingFish();
- this.goFishingLayer.active = false;
- }.bind(this));
- Module.isCollision = false;
- Module.isShouGou = true;
- Module.isShouGou = true;
- this.tishiTip2.active = false;
- this.gameBg.getChildByName("buttonLayer").active = true;
- this.gameBg.getChildByName("moneyBg").active = true;
- this.pondLayer.runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(0.3 * count , cc.v2(-320 , this.pondLayerPos.y))));
- this.gameBg.runAction(cc.sequence(cc.delayTime(0.3 * (count - 1)) ,cc.moveTo(0.3, cc.v2(0 , 0)), cc.callFunc(function(){this.spineMao.getComponent(sp.Skeleton).animation = "action02";window.Utils.playSound('sound/line' , 2, false);}.bind(this)),call3, cc.delayTime(1.5), cc.callFunc(function(){
- this.spineMao.getComponent(sp.Skeleton).animation = "stand";
- }.bind(this))));
-
- }.bind(this));
- this.gameBg.runAction(cc.sequence(cc.delayTime(0.3) ,cc.moveBy(0.2, cc.v2(-640 , 0)) ,cc.delayTime(0.28) ,cc.moveBy(0.4, cc.v2(0 , 1136)) , call));
- this.pondLayer.runAction(cc.sequence(cc.delayTime(0.78) , cc.moveBy(0.4, cc.v2(0 , 1136)), cc.moveBy(3.5 * (count-1) , cc.v2(0 , 1136 * (count-1))),cc.delayTime(0.5), call2));
- this.node.runAction(cc.sequence(cc.delayTime(1.1) , cc.callFunc(function(){
- this.goFishingLayer.active = true;
- }.bind(this))));
- window.Utils.playSound('sound/line' , 2, false);
- this.node.runAction(cc.sequence(cc.delayTime(1.0) , cc.callFunc(function(){
- this.spineMao.getComponent(sp.Skeleton).animation = "stand";
- }.bind(this))));
- },
- /**
- * 获取卖鱼倍数
- */
- getBeishu: function() {
- //根据概率卖出倍数
- var num = 2;
- var gl = window.Utils.random(1,100);
- if (gl <= 50) {
- num = 2;
- } else if (gl <= 80) {
- num = 3;
- } else{
- num = 4;
- }
- this.beishu = num;
- },
- /**
- * 钓鱼结束
- */
- gameOver: function() {
- Module.isShouGou = true;
- this.tishiTip2.active = false;
- this.gameBg.getChildByName("buttonLayer").active = true;
- this.gameBg.getChildByName("moneyBg").active = true;
- if (!Module.isCollision) {
- this.pondLayer.stopAllActions();
- this.gameBg.stopAllActions();
- var count = Math.abs(parseInt((parseInt(this.pondNodeY) - parseInt(this.pondLayer.y)) /113)) / 10;
- if (count == 0) count = 1;
- var call2 = cc.callFunc(function(){
- this.spineMao.getComponent(sp.Skeleton).animation = "action02";
- }.bind(this));
- var call3 = cc.callFunc(function(){
- window.Utils.playSound('sound/line' , 2, false);
- this.goFishingLayer.active = false;
- }.bind(this));
-
- var call4 = cc.callFunc(function(){
- this.sellingFish();
- }.bind(this));
- this.pondLayer.runAction(cc.sequence(cc.delayTime(0.5) , cc.moveTo(0.3 * count , cc.v2(-320 , this.pondLayerPos.y))));
-
- this.gameBg.runAction(cc.sequence(cc.delayTime(0.5) ,cc.delayTime(0.3 * (count - 1)) ,call4, cc.moveTo(0.3, cc.v2(0 , 0)), call3 ));
-
- this.node.runAction(cc.sequence(cc.delayTime(0.9) , call2 , cc.delayTime(1.5), cc.callFunc(function(){
- this.spineMao.getComponent(sp.Skeleton).animation = "stand";
- }.bind(this))));
- } else {
- this.OverInit();
- }
- },
- //新发现鱼
- openDiscoverLayer: function() {
- for (var i = 0; i < Module.nonceFishingArr.length; i++) {
- if (!Module.tujianFishing[Module.nonceFishingArr[i]]) {
- Module.tujianFishing[Module.nonceFishingArr[i]] = true;
- var node = cc.instantiate(this.discoverLayer);
- this.node.addChild(node);
- node.getComponent("discover").refresh(Module.nonceFishingArr[i]);
- }
- }
- window.Utils.setStringForKey("diaoyu_tujianFishing" , Module.tujianFishing);
- },
- /**
- * 结束后初始数据状态
- */
- OverInit: function() {
- this.sellLayer.active = false;
- var call = cc.callFunc(function() {
- if (Module.getGiftNum == 0 && this.giftFlag){
- this.giftFlag = false
- this.everydayGift.active = true;
- }
- this.openDiscoverLayer();
- this.initVigorData();
- this.guide.active = true;
- this.sellingFishAction.active = false;
- this.xuli.active = false;
- this.setMoney();
- Module.fishingNum = 0;
- Module.nonceMoney = 0;
- Module.isCollision = false;
- this.pondLayer.y = this.pondLayerPos.y;
- Module.gameState = false;
- Module.isShouGou = false;
- this.restoreHookPos();
- var fishingNodes = this.pondLayer.getChildByName('fishingNode');
- fishingNodes.removeAllChildren();
- if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("fishingNum").getComponent(cc.Label).string = Module.fishingNum;
- }.bind(this))
- this.node.runAction(cc.sequence(cc.delayTime(0.5), call));
- },
- /**
- * 鱼钩拉起时候,加载鱼精灵
- */
- sellingFish: function() {
- if (Module.nonceFishingArr.length == 0) {
- this.OverInit();
- return;
- }
- var sp = [];
- var flag = false;
- for (var i = 0; i < Module.nonceFishingArr.length; i++) {
- if (parseInt(Module.nonceFishingArr[i]) == 21 || parseInt(Module.nonceFishingArr[i]) == 22 || parseInt(Module.nonceFishingArr[i]) == 23) flag = true;
- }
- for (var i = 0; i < Module.nonceFishingArr.length; i++) {
- cc.loader.loadRes('fishing/fishing' + (Module.nonceFishingArr[i]+1), cc.SpriteFrame, function(err, spFrame) {
- if (err) {
- cc.log(err.message || err);
- return;
- }
- let node = new cc.Node('fishing');
- var sprite = node.addComponent(cc.Sprite);
- sprite.spriteFrame = spFrame;
-
- node.x = window.Utils.random(350,380);
-
- node.y = -window.Utils.random(200,300);
- node.rotation = -90;
- this.node.addChild(node);
- // node.runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 30), cc.rotateBy(0.5 , -30))));
- sp.push(node);
- if (sp.length == Module.nonceFishingArr.length) this.sellingFishEffect(sp, flag);
- }.bind(this));
- }
- },
- /**
- * 鱼钩拉起,鱼抛在空中动画,金币动画
- * @param {*} sp 鱼精灵
- * @param {*} flag 是否有传说鱼
- */
- sellingFishEffect: function(sp , flag) {
- if (sp.length == 0 ) {
- return;
- }
- var dl = 0.04;
- var dl2 = 0.2;
- var moneySum = 0;
- this.sellingFishAction.active = true;
- this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ moneySum;
- var self = this;
- this.sellingFishAction.getChildByName("node2").active = true;
- for (var i = 0; i < sp.length; i++) {
- var call3 = cc.callFunc(function(t, i){
- var sp2 = cc.instantiate(sp[i]);
- sp2.x = -100;
- sp2.y = 156;
- sp2.rotation = 0;
- sp2.scale = 0.7;
- var node = cc.instantiate(self.sellingFishAction.getChildByName("node"));
- node.active = true;
- var money = window.Utils.getFishingPrice(Module.nonceFishingArr[i]);
- moneySum += money;
- this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ moneySum;
- node.getChildByName("num").getComponent(cc.Label).string = ';' + money;
- node.addChild(sp2);
- self.node.addChild(node);
-
- var call4 = cc.callFunc(function() {
- node.destroy();
- })
- node.runAction(cc.sequence(cc.delayTime(0), cc.moveBy(0.7, cc.v2(0 ,60)),cc.delayTime(0.2),call4));
- this.sellingFishAction.getChildByName("node2").runAction(cc.sequence(cc.delayTime(0), cc.scaleTo(0.08, 0.8), cc.scaleTo(0.08, 1.2)));
- }, this ,i);
- this.sellingFishAction.runAction(cc.sequence(cc.delayTime(dl2 * i), call3));
- }
- this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('text').getComponent(cc.Label).string = this.beishu + '倍卖出';
- var tempnonceMoney = Module.nonceMoney;
- Module.nonceMoney = Module.nonceMoney * this.beishu;
- for (var i = 0; i < sp.length; i++) {
- var bezire = [cc.v2(0,0), cc.v2(-250,window.Utils.random(900,1500)),cc.v2(-600,window.Utils.random(200,300))];
- var bezierBy = cc.bezierBy(1.5, bezire);
- var rotation = cc.rotateBy(1.5 , 360*2);
- var call = cc.callFunc(function(){
- this.sellingFishAction.getChildByName("node2").active = false;
- if (flag) {
- this.fameLayer.active = true;
- Module.famLayerObj.fishingAction();
- } else {
- this.sellLayer.getChildByName('bg').getChildByName('sellMoney').getChildByName('num').getComponent(cc.Label).string = tempnonceMoney;
- this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('num').getComponent(cc.Label).string = ';' + Module.nonceMoney;
- this.sellLayer.active = true;
- wb.ADManager.openAd("banner");
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(-150 , 152));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(0 , 152));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(150 , 152));
- }
- }.bind(this));
- sp[i].runAction(cc.sequence(cc.delayTime(dl * i) ,cc.spawn(bezierBy, rotation),(i == sp.length-1) ? call: cc.delayTime(0) , cc.removeSelf()));
- }
- window.Utils.playSound('sound/get' , 2, false);
- },
- /**
- * 出售鱼界面
- * @param {*} flag 是否钓成功传说鱼
- */
- openSellLayer: function(flag) {
- this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('text').getComponent(cc.Label).string = this.beishu + '倍卖出';
- wb.ADManager.openAd("banner");
- if (!flag) {
- for (var i = 0; i < Module.nonceFishingArr.length; i++) {
- var index = parseInt(Module.nonceFishingArr[i]);
- if (index == 21 || index == 22 || index == 23) {
- Module.nonceMoney -= window.Utils.getFishingPrice(index);
- }
- }
- }
-
- this.sellLayer.getChildByName('bg').getChildByName('sellMoney').getChildByName('num').getComponent(cc.Label).string = Module.nonceMoney;
- this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ Module.nonceMoney;
- Module.nonceMoney *=this.beishu;
- this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('num').getComponent(cc.Label).string = ';' + Module.nonceMoney;
- this.sellLayer.active = true;
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(-150 , 152));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(0 , 152));
- window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(150 , 152));
- },
- /**
- * 还原鱼钩
- */
- restoreHookPos: function(){
- Module.goFishingObj.restore();
- },
- /**
- * 加载水底界面
- */
- loadPondLyaer:function(){
- var fishingNodes = this.pondLayer.getChildByName('fishingNode');
- var count = parseInt(Module.depth / 10);
- for (var i = 1; i < count*3; i ++) {
- var y = 1136 - (1136 * i);
- for (var k = 1; k < 6; k++) {
- var posY = y - (1136 / 5 * k);
- var num = window.Utils.probability(20) ? 2 : 1;
- for (var j =0; j < num; j++) {
- var index = 0;
- if (this.vigorNum >= 0 && this.vigorNum < 8) {
- index = window.Utils.random(0 ,3);
- } else if (this.vigorNum >= 8 && this.vigorNum < 12) {
- index = window.Utils.random(7 ,10);
- } else if (this.vigorNum >= 12 && this.vigorNum < 17) {
- index = window.Utils.random(14 ,16);
- }
- if (i > 3) {
- if (i == 4 && this.vigorNum == this.vigorRandomVal && window.Utils.probability(80)) {
- index = window.Utils.random(21 ,23);
- } else {
- if (this.vigorNum >= 0 && this.vigorNum < 8) {
- index = window.Utils.random(4 ,6);
- } else if (this.vigorNum >= 8 && this.vigorNum < 12) {
- index = window.Utils.random(11 ,13);
- } else if (this.vigorNum >= 12 && this.vigorNum < 17) {
- index = window.Utils.random(17 ,19);
- }
- }
- }
- if (Module.prefabArr[index]) {
- var node = cc.instantiate(Module.prefabArr[index]);
- node.y = posY;
- fishingNodes.addChild(node);
- }
- }
- }
- }
- },
- /**
- * 弹出提示框
- * @param {*} str 传入字符串文本,必须传
- * @param {*} pos 坐标 可不传
- * @param {*} fontSize 字体大小 可不传
- */
- popupTishiLayer: function(str , pos , fontSize) {
- if (str == undefined) {
- console.log("----debug---请传入正确的字符串");
- return;
- }
- if (pos == undefined) {
- pos = cc.v2(0,0);
- }
- if (fontSize == fontSize) {
- fontSize = 35;
- }
- var node = cc.instantiate(this.tishi);
- node.x = pos.x;
- node.y = pos.y;
- node.active = true;
- var lable = node.getChildByName("bg").getChildByName("label").getComponent(cc.Label);
-
- lable.string = str;
- lable.fontSize = fontSize;
-
- this.node.addChild(node);
- node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.5 , cc.v2(0 , 250)), cc.delayTime(0.2) , cc.removeSelf()));
- },
- createTishiLayer: function (str , pos , fontSize) {
- if (str == undefined) {
- console.log("----debug---请传入正确的字符串");
- return;
- }
- if (pos == undefined) {
- pos = cc.v2(0,420);
- }
- if (fontSize == fontSize) {
- fontSize = 35;
- }
- var node = cc.instantiate(this.tishi);
- node.x = pos.x;
- node.y = pos.y;
- node.active = true;
- var lable = node.getChildByName("bg").getChildByName("label").getComponent(cc.Label);
-
- lable.string = str;
- lable.fontSize = fontSize;
-
- this.node.addChild(node);
- return node;
- },
- /**
- * 定时器,蓄力功能,刷新水底深度
- * @param {*} dt 60桢每秒
- */
- update (dt) {
- //蓄力
- if (this.touchCount == 1 && !Module.gameState) {
- if (this.guide.active) this.guide.active = false;
- if (!this.xuli.active) {
- this.gameBg.getChildByName("buttonLayer").active = false;
- this.gameBg.getChildByName("moneyBg").active = false;
- this.xuli.active = true;
- this.tishiTip1.active = true;
- }
- ++this.vigorTime;
- if (this.vigorTime % 3 == 0) {
- if (this.vigorNum > this.vigorSum) {
- this.vigorNum = 16;
- this.vigorFlag = true;
- } else if (this.vigorNum <= 0) {
- this.vigorNum = 1;
- this.vigorFlag = false;
- }
-
- if (!this.vigorFlag) {
- for (var i = 1; i < this.vigorSum +1; i++) {
- if (i == this.vigorNum) {
- this.xuli.getChildByName("ui_tiao"+i).active = true;
- } else {
- this.xuli.getChildByName("ui_tiao"+i).active = false;
- }
- }
- ++this.vigorNum;
- } else {
- for (var i = this.vigorSum; i > 0; i--) {
- if (i == this.vigorNum) {
- this.xuli.getChildByName("ui_tiao"+i).active = true;
- } else {
- this.xuli.getChildByName("ui_tiao"+i).active = false;
- }
- }
- --this.vigorNum;
- }
- }
- }
-
- if (Module.gameState) {
- this.setDepthLabel(Math.abs(parseInt((parseInt(this.pondNodeY) - parseInt(this.pondLayer.y)) /113)));
- }
- },
- /**
- * 设置主界面左上角总金币
- */
- setMoney: function(){
- console.log("----------setMoney----------: " , Module.nonceMoney);
- Module.money+= Module.nonceMoney;
- window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
- this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
- },
- updateMoney: function () {
- window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
- this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
- },
- /**
- * 设置水底深度 Label
- * @param {*} depth 深度 单位m
- */
- setDepthLabel: function(depth){
- if (this.goFishingLayer) this.goFishingLayer.getChildByName("shuishen").getChildByName("depth").getComponent(cc.Label).string = depth;
- },
- /**
- * 设置当前钩到鱼重量上限
- */
- setWeightLabel: function(){
- if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("numSum").getComponent(cc.Label).string = Module.fishingNumLimit;
- },
- /**
- * 设置当前钩到鱼重量
- */
- setFishingLabel: function(){
- if (Module.fishingNum >= Module.fishingNumLimit) {
- Module.isCollision = false;
- this.gameOver();
- }
- if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("fishingNum").getComponent(cc.Label).string = Module.fishingNum;
- },
- touchBegin:function(touch,event){
- // this.touchStart = true;
- },
- touchMoving:function(touch,event){
- },
- touchEnd:function(touch, event){
- // this.touchStart = false;
- if (!Module.gameState) {
- ++this.touchCount;
- if (this.touchCount == 2) {
- this.touchCount = 0;
- Module.gameState = true;
- this.node.runAction(cc.sequence(cc.delayTime(0.2) , cc.callFunc(function(){this.gameStart();this.initVigorData();}.bind(this))));
- }
- }
- },
- touchCancel: function(touch, event){
- if (!Module.gameState) {
- ++this.touchCount;
- if (this.touchCount == 2) {
- this.touchCount = 0;
- Module.gameState = true;
- this.node.runAction(cc.sequence(cc.delayTime(0.2) , cc.callFunc(function(){this.gameStart();this.initVigorData();}.bind(this))));
- }
- }
- },
- });
|