gameScene.js 43 KB

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