gameScene.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. fishingLayerNode: cc.Node,
  5. gameBg: cc.Node,
  6. pondLayer: cc.Node,
  7. hook: cc.Node,
  8. topMoenyLabel: cc.Label,
  9. spineMao: cc.Node,
  10. btnNode: [cc.Node],
  11. sellLayer: cc.Node, //卖鱼弹窗
  12. fameLayer: cc.Node,//捕捉传说鱼界面
  13. tujian: cc.Node,//图鉴
  14. xuli: cc.Node, // 蓄力
  15. sellingFishAction: cc.Node, //卖鱼特效
  16. guide: cc.Node, //新手引导
  17. tishi: cc.Node, //提示弹窗
  18. offlineLayer: cc.Node,//离线奖励
  19. everydayGift: cc.Node,//每日礼包
  20. },
  21. /**
  22. * 加载配置表,再初始化场景
  23. */
  24. onLoad () {
  25. // this.initWxData();
  26. this.initStorageData();
  27. this.loadSpriteFrame();
  28. this.loadConfig(function(){
  29. this.initScene();
  30. }.bind(this));
  31. window.Utils.playSound('sound/bgm' , 1, true);
  32. },
  33. start(){
  34. this.initWxData();
  35. },
  36. initStorageData: function() {
  37. for (var i = 0; i < 24; i++) {
  38. if (i == 0) {
  39. Module.tujianFishing.push(true);
  40. continue;
  41. }
  42. Module.tujianFishing.push(false);
  43. }
  44. Module.offlineTime = window.Utils.getStringForKey("offlineTime" , Module.offlineTime);
  45. Module.money = window.Utils.getIntegerForKey("diaoyu_money" , Module.money);
  46. Module.gravitation = window.Utils.getIntegerForKey("diaoyu_gravitation" , Module.gravitation);
  47. Module.fishingNumLimit = window.Utils.getIntegerForKey("diaoyu_fishingNumLimit" , Module.fishingNumLimit);
  48. Module.getGiftNum = window.Utils.getIntegerForKey("diaoyu_getGiftNum" , Module.getGiftNum);
  49. var tujianFishing = window.Utils.getStringForKey("diaoyu_tujianFishing" , Module.tujianFishing);
  50. Module.tujianFishing = [];
  51. tujianFishing = tujianFishing.split(",");
  52. if (Module.offlineTime == "") {
  53. var today = Date.parse(new Date());
  54. Module.offlineTime = today;
  55. window.Utils.setStringForKey("offlineTime" , Module.offlineTime);
  56. }
  57. for (var i = 0; i < tujianFishing.length; i++) {
  58. if (tujianFishing[i] == "true") {
  59. Module.tujianFishing.push(true);
  60. } else {
  61. Module.tujianFishing.push(false);
  62. }
  63. }
  64. var day = new Date();
  65. var today = day.toLocaleDateString();
  66. var lastSignDay = window.Utils.getStringForKey("lastLoginDay","");
  67. console.log("--lastSignDay---: " , lastSignDay);
  68. //新的一天
  69. if (today != lastSignDay) {
  70. window.Utils.setStringForKey("lastLoginDay",today);
  71. Module.getGiftNum = 0;
  72. }
  73. },
  74. initWxData: function() {
  75. },
  76. loadSpriteFrame: function() {
  77. cc.loader.loadRes('tujian/ui_ptk', cc.SpriteFrame, function(err, spFrame) {
  78. if (err) {
  79. cc.log(err.message || err);
  80. return;
  81. }
  82. }.bind(this));
  83. cc.loader.loadRes('tujian/ui_ssk', cc.SpriteFrame, function(err, spFrame) {
  84. if (err) {
  85. cc.log(err.message || err);
  86. return;
  87. }
  88. }.bind(this));
  89. cc.loader.loadRes('prefab/discoverLayer', function (err, res) {
  90. if (err) {
  91. cc.log(err.message || err);
  92. fun();
  93. return;
  94. }
  95. this.discoverLayer = res;
  96. }.bind(this));
  97. },
  98. /**
  99. * 加载配置表
  100. * @param {*} func 加载好后回调
  101. */
  102. loadConfig: function(func) {
  103. window.Config.fishingBait.price = [];
  104. window.Config.fishingBait.gravitation = [];
  105. window.Config.fishRod.price = [];
  106. window.Config.fishRod.weight = [];
  107. window.Config.fishing.price = [];
  108. window.Config.fishing.weight = [];
  109. window.Config.fishing.catch = [];
  110. window.Config.fishing.name = [];
  111. window.Config.fishing.des = [];
  112. CSVParse.parseConfig("config/config.csv", function (data) {
  113. if (data && data.length > 1) {
  114. for (var i = 1; i < data.length; i++) {
  115. if (data[i].length > 0) {
  116. for (var j = 0; j < data[i].length; j++) {
  117. if (data[i][j] === "") data[i][j] = 0;
  118. if (j > 0) {
  119. if (j == 1) {
  120. //鱼饵
  121. window.Config.fishingBait.price.push(parseInt(data[i][j]));
  122. } else if (j == 2) {
  123. //吸引力
  124. window.Config.fishingBait.gravitation.push(parseInt(data[i][j]));
  125. } else if (j == 3) {
  126. //鱼竿价格
  127. window.Config.fishRod.price.push(parseInt(data[i][j]));
  128. } else if (j == 4) {
  129. //重量
  130. window.Config.fishRod.weight.push(parseInt(data[i][j]));
  131. } else if (i > 1 && j == 6) {
  132. //鱼价格
  133. window.Config.fishing.price.push(parseInt(data[i][j]));
  134. } else if (i > 1 && j == 7) {
  135. //鱼重量
  136. window.Config.fishing.weight.push(parseInt(data[i][j]));
  137. } else if (i > 1 && j == 8) {
  138. //鱼捕捉度
  139. window.Config.fishing.catch.push(parseInt(data[i][j]));
  140. } else if (i > 1 && j == 9 && data[i][j] != 0) {
  141. //鱼名
  142. console.log("---data[i][j]---: " , data[i][j]);
  143. window.Config.fishing.name.push(data[i][j]);
  144. } else if (i > 1 && j == 10 && data[i][j] != 0) {
  145. //鱼描述
  146. window.Config.fishing.des.push(data[i][j]);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. for (var k = 0; k < window.Config.fishing.des.length; k++) {
  154. if (window.Config.fishing.des[k].length > 15) window.Config.fishing.des[k] = window.Config.fishing.des[k].replace(/(.{15})/, "$1\n");
  155. }
  156. //succecc
  157. if (func) func();
  158. }.bind(this));
  159. },
  160. /**
  161. * 鱼的预制体
  162. * @param {*} index 鱼的tag值
  163. * @param {*} fun 加载完毕回调
  164. */
  165. loadPrefab: function(index, fun) {
  166. var name = 'prefab/fishing' + index;
  167. cc.loader.loadRes(name, function (err, res) {
  168. ++index;
  169. Module.prefabArr.push(res);
  170. if (err) {
  171. cc.log(err.message || err);
  172. fun();
  173. return;
  174. }
  175. this.loadPrefab(index, fun);
  176. }.bind(this));
  177. },
  178. /**
  179. * 初始化当前场景
  180. */
  181. initScene: function() {
  182. wb.ADManager.openAd("banner");
  183. Module.gameState = false;
  184. Module.gameObj = this;
  185. Module.prefabArr = [];
  186. this.prefabLength = 4;
  187. this.pondNodeY = this.pondLayer.y;
  188. this.touchCount = 0;
  189. this.giftFlag = true;
  190. this.offLine();
  191. this.xuli.active = false;
  192. this.pondLayerPos = this.pondLayer.getPosition();
  193. this.depth = 0; //当前水深
  194. this.touchStart = false;
  195. this.initVigorData();
  196. this.gameBg.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
  197. this.gameBg.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoving.bind(this), this );
  198. this.gameBg.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this), this );
  199. this.gameBg.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancel.bind(this), this );
  200. cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, this.onEnterForeground.bind(this));
  201. cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, this.onEnterBackground.bind(this));
  202. this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
  203. this.pondLayer.getChildByName('fishingNode').zIndex = 10;
  204. this.loadPrefab(1,function(){
  205. }.bind(this));
  206. cc.loader.loadRes('prefab/addFishingBg', function (err, res) {
  207. Module.addMoneyLabel = res;
  208. }.bind(this));
  209. this.goFishingLayer = this.fishingLayerNode;
  210. this.goFishingLayer.active = false;
  211. this.setWeightLabel();
  212. //主页按钮
  213. for (var i = 0; i < this.btnNode.length; i++) {
  214. var btn = this.btnNode[i].getComponent(cc.Button);
  215. btn.node.on('click', this.callback, this);
  216. btn.node.on(cc.Node.EventType.TOUCH_START, window.btnState.touchBegin.bind(this), this );
  217. btn.node.on(cc.Node.EventType.TOUCH_MOVE, window.btnState.touchMoving.bind(this), this );
  218. btn.node.on(cc.Node.EventType.TOUCH_END, window.btnState.touchEnd.bind(this), this );
  219. btn.node.on(cc.Node.EventType.TOUCH_CANCEL, window.btnState.touchCancel.bind(this), this );
  220. }
  221. //鱼饵
  222. this.btnNode[7].getChildByName('gravitation').getComponent(cc.Label).string = window.Utils.getfishingBaitGravitation();
  223. this.btnNode[7].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishingBaitPrice();
  224. //鱼杆
  225. this.btnNode[8].getChildByName('weight').getComponent(cc.Label).string = window.Utils.getfishRodWeight();
  226. this.btnNode[8].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishRodPrice();
  227. //卖鱼界面
  228. this.sellLayer.getChildByName('bg').getChildByName('sellMoney').on('click', this.callback, this);
  229. this.sellLayer.getChildByName('bg').getChildByName('sellVideo').on('click', this.callback, this);
  230. this.sellLayer.on(cc.Node.EventType.TOUCH_START, this.touchBegin.bind(this), this );
  231. //提示(有机会碰到传说鱼)
  232. this.tishiTip1 = this.createTishiLayer("There's a chance to encounter a legendary fish in the red area!~");
  233. this.tishiTip1.active = false;
  234. //提示(传说鱼出没!!)
  235. this.tishiTip2 = this.createTishiLayer("The legendary fish is appearing.!!");
  236. this.tishiTip2.active = false;
  237. console.log("--window.Config.fishing.name--: " , window.Config.fishing.des);
  238. },
  239. /**
  240. * 离线奖励
  241. * 离线超过1小时给与奖励,根据鱼竿重量来给
  242. */
  243. offLine: function() {
  244. var today = Date.parse(new Date());
  245. var time =parseInt((today-Module.offlineTime) / 1000 /60) ;
  246. console.log("---time--: " , time);
  247. if (time >= 60) {
  248. this.offlineLayer.active = true;
  249. this.offlineLayer.getComponent("offline").init(window.Utils.getfishRodPrice() * 2);
  250. }
  251. },
  252. /*进入后台*/
  253. onEnterBackground: function () {
  254. cc.log("-----进入后台-------");
  255. var today = Date.parse(new Date());
  256. console.log("--onShow==============-today--: " , today);
  257. Module.offlineTime = today;
  258. window.Utils.setStringForKey("offlineTime" , today);
  259. },
  260. /*返回游戏*/
  261. onEnterForeground: function () {
  262. var today = Date.parse(new Date());
  263. var time = parseInt((today-Module.offlineTime) / 1000 /60);
  264. console.log("--onShow==============-time--: " , time);
  265. if (time >= 60) {
  266. this.offlineLayer.active = true;
  267. this.offlineLayer.getComponent("offline").init(window.Utils.getfishRodPrice() * 2);
  268. }
  269. var today = Date.parse(new Date());
  270. Module.offlineTime = today;
  271. window.Utils.setStringForKey("offlineTime" , today);
  272. },
  273. /**
  274. * 初始化蓄力数据
  275. */
  276. initVigorData: function() {
  277. this.vigorSum = 16;
  278. this.vigorRandomVal = window.Utils.random(1,16);
  279. var call = cc.callFunc(function(){
  280. this.vigorNum = 1;
  281. this.vigorTime = 1;
  282. this.vigorFlag = false;
  283. }.bind(this));
  284. for (var i = 1; i < this.vigorSum +1; i++) {
  285. this.xuli.getChildByName("ui_tiao"+i).active = false;
  286. if (this.vigorRandomVal == i) {
  287. this.xuli.getChildByName("tiao"+i).active = true;
  288. } else {
  289. this.xuli.getChildByName("tiao"+i).active = false;
  290. }
  291. }
  292. this.node.runAction(cc.sequence(cc.delayTime(0.5) , call));
  293. },
  294. /**
  295. * 主界面按钮回调
  296. * @param {*} target 按钮对象
  297. */
  298. callback: function(target){
  299. var name = target.node.name;
  300. window.Utils.playSound('sound/button' , 2, false);
  301. if (name == "fishingRod") {
  302. //鱼杠
  303. this.fishingRod(target);
  304. } else if (name == "fishingBait") {
  305. //鱼饵
  306. this.fishingBait(target);
  307. } else if (name == "sellMoney") {
  308. //卖鱼按钮
  309. this.buyFishing();
  310. } else if (name == "sellVideo") {
  311. //看视频,卖鱼按钮
  312. this.buyFishingVideo();
  313. } else if (name == "sound") {
  314. //声音
  315. this.soundOnOff(target);
  316. } else if (name == "tujian") {
  317. //图鉴
  318. wb.ADManager.openAd("banner");
  319. this.tujian.active = true;
  320. Module.tujianObj.refresh();
  321. } else if (name == "scene") {
  322. //场景
  323. this.popupTishiLayer("Not open yet~");
  324. } else if (name == "gift") {
  325. Module.getGiftNum == 0 ? this.everydayGift.active = true : this.popupTishiLayer("Today's number has been exhausted~");
  326. }
  327. },
  328. buyFishingVideo: function() {
  329. wb.ADManager.openAdC("video", function (a, result) {
  330. if(result == 0){
  331. this.OverInit();
  332. window.Utils.playSound('sound/sell' , 2, false);
  333. window.Utils.playEffectSpine('effect/effect5/jb.json', 'action', this.node, 0.8);
  334. }else{
  335. this.popupTishiLayer("视频未播放完~");
  336. }
  337. }.bind(this));
  338. },
  339. //卖鱼按钮
  340. buyFishing: function() {
  341. Module.nonceMoney /= this.beishu;
  342. this.OverInit();
  343. window.Utils.playSound('sound/sell' , 2, false);
  344. window.Utils.playEffectSpine('effect/effect5/jb.json', 'action', this.node, 0.8);
  345. },
  346. /**
  347. * 声音开关
  348. * @param {*} target 声音按钮对象
  349. */
  350. soundOnOff: function(target) {
  351. if (target.node.getChildByName('on').active) {
  352. Module.isPlaySound = false;
  353. cc.audioEngine.pauseAll();
  354. target.node.getChildByName('on').active = false;
  355. target.node.getChildByName('off').active = true;
  356. } else {
  357. Module.isPlaySound = true;
  358. cc.audioEngine.resumeAll();
  359. target.node.getChildByName('on').active = true;
  360. target.node.getChildByName('off').active = false;
  361. }
  362. },
  363. /**
  364. * 鱼竿
  365. */
  366. fishingRod: function(target) {
  367. if (Module.money > window.Utils.getfishRodPrice()) {
  368. Module.money -= window.Utils.getfishRodPrice();
  369. window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
  370. var num = window.Utils.getfishRodWeight() - Module.fishingNumLimit;
  371. Module.fishingNumLimit = window.Utils.getfishRodWeight();
  372. window.Utils.setIntegerForKey("diaoyu_fishingNumLimit" , Module.fishingNumLimit);
  373. //刷新金币 重量
  374. this.setMoney();
  375. this.setWeightLabel();
  376. this.btnNode[8].getChildByName('weight').getComponent(cc.Label).string = window.Utils.getfishRodWeight();
  377. this.btnNode[8].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishRodPrice();
  378. //飘字
  379. var node =new cc.Node("node");
  380. var label = node.addComponent(cc.Label);
  381. label.string= "+" + num;
  382. label.fontSize= 24;
  383. var color=new cc.Color(40,98, 143);
  384. node.position=cc.v2(target.node.x,target.node.y);
  385. node.color=color;
  386. node.parent = this.node;
  387. node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.8, cc.v2(0,120)), cc.delayTime(0.2),cc.removeSelf()));
  388. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', target.node, 0.9 , cc.v2(0,27));
  389. } else {
  390. console.log("--------金币不足----------");
  391. this.popupTishiLayer("Meow is too poor to afford it~");
  392. }
  393. },
  394. /**
  395. * 鱼饵
  396. */
  397. fishingBait: function(target) {
  398. if (Module.money > window.Utils.getfishingBaitPrice()) {
  399. Module.money -= window.Utils.getfishingBaitPrice();
  400. window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
  401. var num = window.Utils.getfishingBaitGravitation() - Module.gravitation;
  402. Module.gravitation = window.Utils.getfishingBaitGravitation();
  403. window.Utils.setIntegerForKey("diaoyu_gravitation", Module.gravitation);
  404. this.setMoney();
  405. //刷新价格 吸引力
  406. this.btnNode[7].getChildByName('gravitation').getComponent(cc.Label).string = window.Utils.getfishingBaitGravitation();
  407. this.btnNode[7].getChildByName('price').getComponent(cc.Label).string = window.Utils.getfishingBaitPrice();
  408. //飘字
  409. var node =new cc.Node("node");
  410. var label = node.addComponent(cc.Label);
  411. label.string= "+" + num;
  412. label.fontSize= 24;
  413. var color=new cc.Color(40,98, 143);
  414. node.position=cc.v2(target.node.x,target.node.y);
  415. node.color=color;
  416. node.parent = this.node;
  417. node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.8, cc.v2(0,120)), cc.delayTime(0.2),cc.removeSelf()));
  418. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', target.node, 0.9 , cc.v2(0,27));
  419. } else {
  420. console.log("--------金币不足----------");
  421. this.popupTishiLayer("Meow is too poor to afford it~");
  422. }
  423. },
  424. /**
  425. * 开始钓鱼
  426. */
  427. gameStart: function(){
  428. wb.ADManager.closeAd("banner");
  429. this.spineMao.getComponent(sp.Skeleton).animation = "action01";
  430. for (var i = 1; i < this.vigorSum +1; i++) {
  431. if (this.xuli.getChildByName("ui_tiao"+i).active) this.vigorNum = i;
  432. }
  433. if (this.vigorNum == this.vigorRandomVal) {
  434. this.tishiTip1.active = false;
  435. this.tishiTip2.active = true;
  436. }
  437. var call = cc.callFunc(function(){
  438. // this.gameBg.active = false;
  439. }.bind(this));
  440. var count = parseInt(Module.depth / 10);
  441. Module.isCollision = true;
  442. this.xuli.active = false;
  443. this.loadPondLyaer();
  444. Module.gameState = true;
  445. this.goFishingLayer.active = false;
  446. this.tishiTip1.active = false;
  447. Module.isShowHook = false;
  448. Module.nonceFishingArr = [];
  449. this.hook.removeAllChildren();
  450. this.getBeishu();
  451. //鱼钩到底后回拉
  452. var call2 = cc.callFunc(function(){
  453. var call3 = cc.callFunc(function(){
  454. // this.OverInit();
  455. this.sellingFish();
  456. this.goFishingLayer.active = false;
  457. }.bind(this));
  458. Module.isCollision = false;
  459. Module.isShouGou = true;
  460. Module.isShouGou = true;
  461. this.tishiTip2.active = false;
  462. this.gameBg.getChildByName("buttonLayer").active = true;
  463. this.gameBg.getChildByName("moneyBg").active = true;
  464. this.pondLayer.runAction(cc.sequence(cc.delayTime(0) , cc.moveTo(0.3 * count , cc.v2(-320 , this.pondLayerPos.y))));
  465. 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(){
  466. this.spineMao.getComponent(sp.Skeleton).animation = "stand";
  467. }.bind(this))));
  468. }.bind(this));
  469. 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));
  470. 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));
  471. this.node.runAction(cc.sequence(cc.delayTime(1.1) , cc.callFunc(function(){
  472. this.goFishingLayer.active = true;
  473. }.bind(this))));
  474. window.Utils.playSound('sound/line' , 2, false);
  475. this.node.runAction(cc.sequence(cc.delayTime(1.0) , cc.callFunc(function(){
  476. this.spineMao.getComponent(sp.Skeleton).animation = "stand";
  477. }.bind(this))));
  478. },
  479. /**
  480. * 获取卖鱼倍数
  481. */
  482. getBeishu: function() {
  483. //根据概率卖出倍数
  484. var num = 2;
  485. var gl = window.Utils.random(1,100);
  486. if (gl <= 50) {
  487. num = 2;
  488. } else if (gl <= 80) {
  489. num = 3;
  490. } else{
  491. num = 4;
  492. }
  493. this.beishu = num;
  494. },
  495. /**
  496. * 钓鱼结束
  497. */
  498. gameOver: function() {
  499. Module.isShouGou = true;
  500. this.tishiTip2.active = false;
  501. this.gameBg.getChildByName("buttonLayer").active = true;
  502. this.gameBg.getChildByName("moneyBg").active = true;
  503. if (!Module.isCollision) {
  504. this.pondLayer.stopAllActions();
  505. this.gameBg.stopAllActions();
  506. var count = Math.abs(parseInt((parseInt(this.pondNodeY) - parseInt(this.pondLayer.y)) /113)) / 10;
  507. if (count == 0) count = 1;
  508. var call2 = cc.callFunc(function(){
  509. this.spineMao.getComponent(sp.Skeleton).animation = "action02";
  510. }.bind(this));
  511. var call3 = cc.callFunc(function(){
  512. window.Utils.playSound('sound/line' , 2, false);
  513. this.goFishingLayer.active = false;
  514. }.bind(this));
  515. var call4 = cc.callFunc(function(){
  516. this.sellingFish();
  517. }.bind(this));
  518. this.pondLayer.runAction(cc.sequence(cc.delayTime(0.5) , cc.moveTo(0.3 * count , cc.v2(-320 , this.pondLayerPos.y))));
  519. 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 ));
  520. this.node.runAction(cc.sequence(cc.delayTime(0.9) , call2 , cc.delayTime(1.5), cc.callFunc(function(){
  521. this.spineMao.getComponent(sp.Skeleton).animation = "stand";
  522. }.bind(this))));
  523. } else {
  524. this.OverInit();
  525. }
  526. },
  527. //新发现鱼
  528. openDiscoverLayer: function() {
  529. for (var i = 0; i < Module.nonceFishingArr.length; i++) {
  530. if (!Module.tujianFishing[Module.nonceFishingArr[i]]) {
  531. Module.tujianFishing[Module.nonceFishingArr[i]] = true;
  532. var node = cc.instantiate(this.discoverLayer);
  533. this.node.addChild(node);
  534. node.getComponent("discover").refresh(Module.nonceFishingArr[i]);
  535. }
  536. }
  537. window.Utils.setStringForKey("diaoyu_tujianFishing" , Module.tujianFishing);
  538. },
  539. /**
  540. * 结束后初始数据状态
  541. */
  542. OverInit: function() {
  543. this.sellLayer.active = false;
  544. var call = cc.callFunc(function() {
  545. if (Module.getGiftNum == 0 && this.giftFlag){
  546. this.giftFlag = false
  547. this.everydayGift.active = true;
  548. }
  549. this.openDiscoverLayer();
  550. this.initVigorData();
  551. this.guide.active = true;
  552. this.sellingFishAction.active = false;
  553. this.xuli.active = false;
  554. this.setMoney();
  555. Module.fishingNum = 0;
  556. Module.nonceMoney = 0;
  557. Module.isCollision = false;
  558. this.pondLayer.y = this.pondLayerPos.y;
  559. Module.gameState = false;
  560. Module.isShouGou = false;
  561. this.restoreHookPos();
  562. var fishingNodes = this.pondLayer.getChildByName('fishingNode');
  563. fishingNodes.removeAllChildren();
  564. if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("fishingNum").getComponent(cc.Label).string = Module.fishingNum;
  565. }.bind(this))
  566. this.node.runAction(cc.sequence(cc.delayTime(0.5), call));
  567. },
  568. /**
  569. * 鱼钩拉起时候,加载鱼精灵
  570. */
  571. sellingFish: function() {
  572. if (Module.nonceFishingArr.length == 0) {
  573. this.OverInit();
  574. return;
  575. }
  576. var sp = [];
  577. var flag = false;
  578. for (var i = 0; i < Module.nonceFishingArr.length; i++) {
  579. if (parseInt(Module.nonceFishingArr[i]) == 21 || parseInt(Module.nonceFishingArr[i]) == 22 || parseInt(Module.nonceFishingArr[i]) == 23) flag = true;
  580. }
  581. for (var i = 0; i < Module.nonceFishingArr.length; i++) {
  582. cc.loader.loadRes('fishing/fishing' + (Module.nonceFishingArr[i]+1), cc.SpriteFrame, function(err, spFrame) {
  583. if (err) {
  584. cc.log(err.message || err);
  585. return;
  586. }
  587. let node = new cc.Node('fishing');
  588. var sprite = node.addComponent(cc.Sprite);
  589. sprite.spriteFrame = spFrame;
  590. node.x = window.Utils.random(350,380);
  591. node.y = -window.Utils.random(200,300);
  592. node.rotation = -90;
  593. this.node.addChild(node);
  594. // node.runAction(cc.repeatForever(cc.sequence(cc.rotateBy(0.5 , 30), cc.rotateBy(0.5 , -30))));
  595. sp.push(node);
  596. if (sp.length == Module.nonceFishingArr.length) this.sellingFishEffect(sp, flag);
  597. }.bind(this));
  598. }
  599. },
  600. /**
  601. * 鱼钩拉起,鱼抛在空中动画,金币动画
  602. * @param {*} sp 鱼精灵
  603. * @param {*} flag 是否有传说鱼
  604. */
  605. sellingFishEffect: function(sp , flag) {
  606. if (sp.length == 0 ) {
  607. return;
  608. }
  609. var dl = 0.04;
  610. var dl2 = 0.2;
  611. var moneySum = 0;
  612. this.sellingFishAction.active = true;
  613. this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ moneySum;
  614. var self = this;
  615. this.sellingFishAction.getChildByName("node2").active = true;
  616. for (var i = 0; i < sp.length; i++) {
  617. var call3 = cc.callFunc(function(t, i){
  618. var sp2 = cc.instantiate(sp[i]);
  619. sp2.x = -100;
  620. sp2.y = 156;
  621. sp2.rotation = 0;
  622. sp2.scale = 0.7;
  623. var node = cc.instantiate(self.sellingFishAction.getChildByName("node"));
  624. node.active = true;
  625. var money = window.Utils.getFishingPrice(Module.nonceFishingArr[i]);
  626. moneySum += money;
  627. this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ moneySum;
  628. node.getChildByName("num").getComponent(cc.Label).string = ';' + money;
  629. node.addChild(sp2);
  630. self.node.addChild(node);
  631. var call4 = cc.callFunc(function() {
  632. node.destroy();
  633. })
  634. node.runAction(cc.sequence(cc.delayTime(0), cc.moveBy(0.7, cc.v2(0 ,60)),cc.delayTime(0.2),call4));
  635. this.sellingFishAction.getChildByName("node2").runAction(cc.sequence(cc.delayTime(0), cc.scaleTo(0.08, 0.8), cc.scaleTo(0.08, 1.2)));
  636. }, this ,i);
  637. this.sellingFishAction.runAction(cc.sequence(cc.delayTime(dl2 * i), call3));
  638. }
  639. this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('text').getComponent(cc.Label).string = this.beishu + '倍卖出';
  640. var tempnonceMoney = Module.nonceMoney;
  641. Module.nonceMoney = Module.nonceMoney * this.beishu;
  642. for (var i = 0; i < sp.length; i++) {
  643. var bezire = [cc.v2(0,0), cc.v2(-250,window.Utils.random(900,1500)),cc.v2(-600,window.Utils.random(200,300))];
  644. var bezierBy = cc.bezierBy(1.5, bezire);
  645. var rotation = cc.rotateBy(1.5 , 360*2);
  646. var call = cc.callFunc(function(){
  647. this.sellingFishAction.getChildByName("node2").active = false;
  648. if (flag) {
  649. this.fameLayer.active = true;
  650. Module.famLayerObj.fishingAction();
  651. } else {
  652. this.sellLayer.getChildByName('bg').getChildByName('sellMoney').getChildByName('num').getComponent(cc.Label).string = tempnonceMoney;
  653. this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('num').getComponent(cc.Label).string = ';' + Module.nonceMoney;
  654. this.sellLayer.active = true;
  655. wb.ADManager.openAd("banner");
  656. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(-150 , 152));
  657. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(0 , 152));
  658. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(150 , 152));
  659. }
  660. }.bind(this));
  661. sp[i].runAction(cc.sequence(cc.delayTime(dl * i) ,cc.spawn(bezierBy, rotation),(i == sp.length-1) ? call: cc.delayTime(0) , cc.removeSelf()));
  662. }
  663. window.Utils.playSound('sound/get' , 2, false);
  664. },
  665. /**
  666. * 出售鱼界面
  667. * @param {*} flag 是否钓成功传说鱼
  668. */
  669. openSellLayer: function(flag) {
  670. this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('text').getComponent(cc.Label).string = this.beishu + '倍卖出';
  671. wb.ADManager.openAd("banner");
  672. if (!flag) {
  673. for (var i = 0; i < Module.nonceFishingArr.length; i++) {
  674. var index = parseInt(Module.nonceFishingArr[i]);
  675. if (index == 21 || index == 22 || index == 23) {
  676. Module.nonceMoney -= window.Utils.getFishingPrice(index);
  677. }
  678. }
  679. }
  680. this.sellLayer.getChildByName('bg').getChildByName('sellMoney').getChildByName('num').getComponent(cc.Label).string = Module.nonceMoney;
  681. this.sellingFishAction.getChildByName("node2").getChildByName("num6").getComponent(cc.Label).string = ";"+ Module.nonceMoney;
  682. Module.nonceMoney *=this.beishu;
  683. this.sellLayer.getChildByName('bg').getChildByName('sellVideo').getChildByName('num').getComponent(cc.Label).string = ';' + Module.nonceMoney;
  684. this.sellLayer.active = true;
  685. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(-150 , 152));
  686. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(0 , 152));
  687. window.Utils.playEffectSpine('effect/effect5/caidai.json', 'action', this.sellLayer, 0.9,cc.v2(150 , 152));
  688. },
  689. /**
  690. * 还原鱼钩
  691. */
  692. restoreHookPos: function(){
  693. Module.goFishingObj.restore();
  694. },
  695. /**
  696. * 加载水底界面
  697. */
  698. loadPondLyaer:function(){
  699. var fishingNodes = this.pondLayer.getChildByName('fishingNode');
  700. var count = parseInt(Module.depth / 10);
  701. for (var i = 1; i < count*3; i ++) {
  702. var y = 1136 - (1136 * i);
  703. for (var k = 1; k < 6; k++) {
  704. var posY = y - (1136 / 5 * k);
  705. var num = window.Utils.probability(20) ? 2 : 1;
  706. for (var j =0; j < num; j++) {
  707. var index = 0;
  708. if (this.vigorNum >= 0 && this.vigorNum < 8) {
  709. index = window.Utils.random(0 ,3);
  710. } else if (this.vigorNum >= 8 && this.vigorNum < 12) {
  711. index = window.Utils.random(7 ,10);
  712. } else if (this.vigorNum >= 12 && this.vigorNum < 17) {
  713. index = window.Utils.random(14 ,16);
  714. }
  715. if (i > 3) {
  716. if (i == 4 && this.vigorNum == this.vigorRandomVal && window.Utils.probability(80)) {
  717. index = window.Utils.random(21 ,23);
  718. } else {
  719. if (this.vigorNum >= 0 && this.vigorNum < 8) {
  720. index = window.Utils.random(4 ,6);
  721. } else if (this.vigorNum >= 8 && this.vigorNum < 12) {
  722. index = window.Utils.random(11 ,13);
  723. } else if (this.vigorNum >= 12 && this.vigorNum < 17) {
  724. index = window.Utils.random(17 ,19);
  725. }
  726. }
  727. }
  728. if (Module.prefabArr[index]) {
  729. var node = cc.instantiate(Module.prefabArr[index]);
  730. node.y = posY;
  731. fishingNodes.addChild(node);
  732. }
  733. }
  734. }
  735. }
  736. },
  737. /**
  738. * 弹出提示框
  739. * @param {*} str 传入字符串文本,必须传
  740. * @param {*} pos 坐标 可不传
  741. * @param {*} fontSize 字体大小 可不传
  742. */
  743. popupTishiLayer: function(str , pos , fontSize) {
  744. if (str == undefined) {
  745. console.log("----debug---请传入正确的字符串");
  746. return;
  747. }
  748. if (pos == undefined) {
  749. pos = cc.v2(0,0);
  750. }
  751. if (fontSize == fontSize) {
  752. fontSize = 35;
  753. }
  754. var node = cc.instantiate(this.tishi);
  755. node.x = pos.x;
  756. node.y = pos.y;
  757. node.active = true;
  758. var lable = node.getChildByName("bg").getChildByName("label").getComponent(cc.Label);
  759. lable.string = str;
  760. lable.fontSize = fontSize;
  761. this.node.addChild(node);
  762. node.runAction(cc.sequence(cc.delayTime(0) , cc.moveBy(0.5 , cc.v2(0 , 250)), cc.delayTime(0.2) , cc.removeSelf()));
  763. },
  764. createTishiLayer: function (str , pos , fontSize) {
  765. if (str == undefined) {
  766. console.log("----debug---请传入正确的字符串");
  767. return;
  768. }
  769. if (pos == undefined) {
  770. pos = cc.v2(0,420);
  771. }
  772. if (fontSize == fontSize) {
  773. fontSize = 35;
  774. }
  775. var node = cc.instantiate(this.tishi);
  776. node.x = pos.x;
  777. node.y = pos.y;
  778. node.active = true;
  779. var lable = node.getChildByName("bg").getChildByName("label").getComponent(cc.Label);
  780. lable.string = str;
  781. lable.fontSize = fontSize;
  782. this.node.addChild(node);
  783. return node;
  784. },
  785. /**
  786. * 定时器,蓄力功能,刷新水底深度
  787. * @param {*} dt 60桢每秒
  788. */
  789. update (dt) {
  790. //蓄力
  791. if (this.touchCount == 1 && !Module.gameState) {
  792. if (this.guide.active) this.guide.active = false;
  793. if (!this.xuli.active) {
  794. this.gameBg.getChildByName("buttonLayer").active = false;
  795. this.gameBg.getChildByName("moneyBg").active = false;
  796. this.xuli.active = true;
  797. this.tishiTip1.active = true;
  798. }
  799. ++this.vigorTime;
  800. if (this.vigorTime % 3 == 0) {
  801. if (this.vigorNum > this.vigorSum) {
  802. this.vigorNum = 16;
  803. this.vigorFlag = true;
  804. } else if (this.vigorNum <= 0) {
  805. this.vigorNum = 1;
  806. this.vigorFlag = false;
  807. }
  808. if (!this.vigorFlag) {
  809. for (var i = 1; i < this.vigorSum +1; i++) {
  810. if (i == this.vigorNum) {
  811. this.xuli.getChildByName("ui_tiao"+i).active = true;
  812. } else {
  813. this.xuli.getChildByName("ui_tiao"+i).active = false;
  814. }
  815. }
  816. ++this.vigorNum;
  817. } else {
  818. for (var i = this.vigorSum; i > 0; i--) {
  819. if (i == this.vigorNum) {
  820. this.xuli.getChildByName("ui_tiao"+i).active = true;
  821. } else {
  822. this.xuli.getChildByName("ui_tiao"+i).active = false;
  823. }
  824. }
  825. --this.vigorNum;
  826. }
  827. }
  828. }
  829. if (Module.gameState) {
  830. this.setDepthLabel(Math.abs(parseInt((parseInt(this.pondNodeY) - parseInt(this.pondLayer.y)) /113)));
  831. }
  832. },
  833. /**
  834. * 设置主界面左上角总金币
  835. */
  836. setMoney: function(){
  837. console.log("----------setMoney----------: " , Module.nonceMoney);
  838. Module.money+= Module.nonceMoney;
  839. window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
  840. this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
  841. },
  842. updateMoney: function () {
  843. window.Utils.setIntegerForKey("diaoyu_money" , Module.money);
  844. this.topMoenyLabel.string = window.Utils.moneySwitch(Module.money);
  845. },
  846. /**
  847. * 设置水底深度 Label
  848. * @param {*} depth 深度 单位m
  849. */
  850. setDepthLabel: function(depth){
  851. if (this.goFishingLayer) this.goFishingLayer.getChildByName("shuishen").getChildByName("depth").getComponent(cc.Label).string = depth;
  852. },
  853. /**
  854. * 设置当前钩到鱼重量上限
  855. */
  856. setWeightLabel: function(){
  857. if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("numSum").getComponent(cc.Label).string = Module.fishingNumLimit;
  858. },
  859. /**
  860. * 设置当前钩到鱼重量
  861. */
  862. setFishingLabel: function(){
  863. if (Module.fishingNum >= Module.fishingNumLimit) {
  864. Module.isCollision = false;
  865. this.gameOver();
  866. }
  867. if (this.goFishingLayer) this.goFishingLayer.getChildByName("zl").getChildByName("fishingNum").getComponent(cc.Label).string = Module.fishingNum;
  868. },
  869. touchBegin:function(touch,event){
  870. // this.touchStart = true;
  871. },
  872. touchMoving:function(touch,event){
  873. },
  874. touchEnd:function(touch, event){
  875. // this.touchStart = false;
  876. if (!Module.gameState) {
  877. ++this.touchCount;
  878. if (this.touchCount == 2) {
  879. this.touchCount = 0;
  880. Module.gameState = true;
  881. this.node.runAction(cc.sequence(cc.delayTime(0.2) , cc.callFunc(function(){this.gameStart();this.initVigorData();}.bind(this))));
  882. }
  883. }
  884. },
  885. touchCancel: function(touch, event){
  886. if (!Module.gameState) {
  887. ++this.touchCount;
  888. if (this.touchCount == 2) {
  889. this.touchCount = 0;
  890. Module.gameState = true;
  891. this.node.runAction(cc.sequence(cc.delayTime(0.2) , cc.callFunc(function(){this.gameStart();this.initVigorData();}.bind(this))));
  892. }
  893. }
  894. },
  895. });