fba44b50-3964-462b-9191-fa8cf50ed675.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. "use strict";
  2. cc._RF.push(module, 'fba44tQOWRGK5GR+oz1DtZ1', 'ZY_HomeScene');
  3. // Script/ZY_HomeScene.js
  4. "use strict";
  5. var _KurumiAD = _interopRequireDefault(require("./common/KurumiAD"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. var ZYGameTool = require('GameTool');
  8. cc.Class({
  9. "extends": cc.Component,
  10. properties: {
  11. clickFlag: true,
  12. homeButtons: {
  13. type: cc.Button,
  14. "default": []
  15. },
  16. buttonsName: null,
  17. coinLabel: cc.Label,
  18. bgmClip: {
  19. type: cc.AudioClip,
  20. "default": null
  21. },
  22. //背景音乐
  23. logoNode: cc.Node,
  24. cactursNode: cc.Node,
  25. maskLayer: cc.Prefab,
  26. settingLayer: cc.Prefab,
  27. helpLayer: cc.Prefab,
  28. coinNode: cc.Node
  29. },
  30. // LIFE-CYCLE CALLBACKS:
  31. onLoad: function onLoad() {
  32. // this.node.active = false;
  33. // ZYGameTool.getInstance().startDrawGame(function () {
  34. _KurumiAD["default"].instance.Init("4571759", //视频广告id
  35. "Rewarded_Android", //插评广告id
  36. "Interstitial_Android", function (data) {
  37. //初始化成功
  38. console.log('init the unity ad success');
  39. }, function (data) {
  40. //初始化失败
  41. console.log('init the unity ad fail');
  42. });
  43. this.node.active = true;
  44. this.setLocalDataItem();
  45. this.buttonsName = {
  46. redBagBtn: 0,
  47. giftBtn: 1,
  48. redBtn: 2,
  49. startBtn: 3,
  50. settingBtn: 4,
  51. helpBtn: 5,
  52. signBtn: 6
  53. };
  54. cc.debug.setDisplayStats(false); //首页按钮注册监听
  55. for (var i in this.homeButtons) {
  56. this.homeButtons[i].node.scale = 0;
  57. this.homeButtons[i].node.on("click", this.gameClickCall, this);
  58. }
  59. this.homeEffect(); // }.bind(this))
  60. },
  61. start: function start() {
  62. // ZYGameTool.getInstance().startDrawGame(function () {
  63. //是否已预加载资源
  64. if (isFirstInGame) {
  65. ZYGameTool.getInstance().loadSpriteFrame(function () {
  66. cc.director.preloadScene("mainScene");
  67. isFirstInGame = false;
  68. this.init();
  69. }.bind(this));
  70. } else {
  71. this.init();
  72. } // }.bind(this))
  73. // var hd = Math.PI / 180 * 30 ;
  74. // var jd = 180/Math.PI * hd;
  75. // console.log("--hd--: " , Math.sin(hd));
  76. // console.log("--jd--: " , Math.sin(jd));
  77. // this.privacyBtn.on('click',this.privacyEvent,this)
  78. // this.teamBtn.on('click',this.teamEvent,this)
  79. cc.find('Toggle/privacy', this.node).on('click', this.privacyEvent, this);
  80. cc.find('Toggle/team', this.node).on('click', this.teamEvent, this);
  81. },
  82. privacyEvent: function privacyEvent() {
  83. cc.sys.openURL('https://jetsbegin.today/privacy.html');
  84. },
  85. teamEvent: function teamEvent() {
  86. cc.sys.openURL('https://jetsbegin.today');
  87. },
  88. init: function init() {
  89. this.setCoinLabel(); //播放背景声音
  90. zy.playBgMusic(this.bgmClip, true);
  91. },
  92. /**
  93. * 初始化设置游戏所需本地化数据
  94. */
  95. setLocalDataItem: function setLocalDataItem() {
  96. coinNum = ZYGameTool.getInstance().getIntegerForKey(localDataItem.coinNum, 100); //默认金币
  97. playeSound = ZYGameTool.getInstance().getIntegerForKey(localDataItem.playeSound, 1); //音效开关
  98. playeMusic = ZYGameTool.getInstance().getIntegerForKey(localDataItem.playeMusic, 1); //背景音乐开关
  99. },
  100. /**
  101. *设置金币
  102. */
  103. setCoinLabel: function setCoinLabel() {
  104. if (coinNum === undefined || coinNum === 'NAN') coinNum = 0;
  105. this.coinLabel.string = coinNum;
  106. },
  107. /**
  108. * 首页的动画
  109. */
  110. homeEffect: function homeEffect() {
  111. var logoHeight = 1000;
  112. var initLogoHeight = this.logoNode.parent.y;
  113. {
  114. this.logoNode.y += logoHeight;
  115. this.cactursNode.y += logoHeight;
  116. } //logo
  117. {
  118. var actions = [];
  119. var ac1 = cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50));
  120. var ac2 = cc.moveBy(0.1, cc.v2(0, 50));
  121. var ac3 = cc.scaleTo(0.1, 1, 0.6);
  122. var ac4 = cc.scaleTo(0.1, 1, 1);
  123. actions.push(ac1);
  124. actions.push(ac2);
  125. actions.push(ac3);
  126. actions.push(ac4); // actions2.concat(0,actions.length-1);
  127. var actions2 = [].concat(actions);
  128. console.log("actions2", actions2);
  129. this.logoNode.runAction(cc.sequence(cc.delayTime(0.2), cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50)), cc.moveBy(0.1, cc.v2(0, 50)), cc.scaleTo(0.1, 1, 0.6), cc.scaleTo(0.1, 1, 1), cc.delayTime(1.5), cc.callFunc(function (node) {
  130. node.runAction(cc.repeatForever(cc.sequence(cc.rotateTo(1.5, 1), cc.rotateTo(1.5, -1))));
  131. }.bind(this), this.constructor)));
  132. this.cactursNode.runAction(cc.sequence(cc.delayTime(0.35 + 0.2), cc.moveBy(0.2, cc.v2(0, logoHeight * -1 - 50)), cc.moveBy(0.1, cc.v2(0, 50)), cc.scaleTo(0.1, 1, 0.6), cc.scaleTo(0.1, 1, 1), cc.delayTime(0.5), cc.callFunc(function (node) {
  133. node.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1.5, 1, 0.85), cc.scaleTo(1.5, 1, 1))));
  134. }.bind(this), this.constructor)));
  135. } //按钮统一动画
  136. {
  137. this.node.runAction(cc.sequence(cc.delayTime(0.6 + 0.2), cc.callFunc(function () {
  138. var dl = 0.05;
  139. for (var i in this.homeButtons) {
  140. this.homeButtons[i].node.runAction(cc.sequence(cc.delayTime(dl * i), cc.scaleTo(0.5, 1, 1)));
  141. }
  142. }.bind(this))));
  143. this.homeButtons[this.buttonsName.startBtn].node.runAction(cc.sequence(cc.delayTime(1.8), cc.callFunc(function (node) {
  144. node.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(2.5, 0.85), cc.scaleTo(2.5, 1))));
  145. }.bind(this), this.homeButtons[this.buttonsName.startBtn])));
  146. }
  147. {
  148. this.homeButtons[this.buttonsName.redBtn].node.runAction(cc.sequence(cc.delayTime(1.8), cc.callFunc(function (node) {
  149. node.runAction(cc.repeatForever(cc.sequence(cc.spawn(cc.rotateTo(0.8, 7), cc.scaleTo(0.8, 0.9)), cc.spawn(cc.rotateTo(0.8, -7), cc.scaleTo(0.8, 1.0)))));
  150. }.bind(this), this.homeButtons[this.buttonsName.redBtn])));
  151. var finger = this.homeButtons[this.buttonsName.redBtn].node.parent.getChildByName("finger");
  152. finger.runAction(cc.sequence(cc.delayTime(1.8), cc.scaleTo(0.5, 0.6), cc.callFunc(function (node) {
  153. this.openBanner();
  154. node.runAction(cc.repeatForever(cc.sequence(cc.show(), cc.blink(2, 5), cc.delayTime(2), cc.hide(), cc.delayTime(5))));
  155. }.bind(this), finger)));
  156. }
  157. },
  158. openBanner: function openBanner() {// ZYGameTool.getInstance().OpenAd("banner", "banner");
  159. },
  160. gameClickCall: function gameClickCall(target) {
  161. var name = target.node.name;
  162. console.log("--name--: ", name);
  163. if (name === "startBtn") {
  164. this.gameStartClick();
  165. } else if (name === "helpBtn") {
  166. this.gameHelpClick(10);
  167. } else if (name === "redBtn") {
  168. this.gameRedClick();
  169. } else if (name === "settingBtn") {
  170. this.gameSettingClick();
  171. }
  172. },
  173. gameHelpClick: function gameHelpClick() {
  174. var helpLayer = cc.instantiate(this.helpLayer);
  175. helpLayer.parent = this.node;
  176. helpLayer.zIndex = 1000;
  177. },
  178. gameSettingClick: function gameSettingClick() {
  179. var settingNode = cc.instantiate(this.settingLayer);
  180. settingNode.parent = this.node;
  181. settingNode.zIndex = 1000;
  182. },
  183. gameRedClick: function gameRedClick(pos) {
  184. ZYGameTool.getInstance().OpenAd("home_lqjb", "video", function () {
  185. this.coinAction(10);
  186. coinNum += 10;
  187. this.setCoinLabel();
  188. ZYGameTool.getInstance().setIntegerForKey(localDataItem.coinNum, coinNum);
  189. console.log("---debug---成功---");
  190. }.bind(this), function () {
  191. console.log("---debug---失败---");
  192. }.bind(this));
  193. },
  194. coinAction: function coinAction(num) {
  195. var dl = 0.15;
  196. var bezier = [cc.v2(0, 0), cc.v2(-300, 100), cc.v2(this.coinNode.x - 60, this.coinNode.y)];
  197. for (var i = 0; i < num; i++) {
  198. var node = zy.getSprite("common/coin");
  199. node.setPosition(cc.v2(0, 0));
  200. node.scale = 0;
  201. node.zIndex = 100 - i;
  202. this.node.addChild(node);
  203. node.runAction(cc.speed(cc.sequence(cc.delayTime(dl * i), cc.scaleTo(0.2, 1, 1), cc.delayTime(0.1), cc.bezierTo(0.2, bezier), cc.fadeOut(0.05), cc.callFunc(function (node) {
  204. node.removeFromParent();
  205. }.bind(this), node)), num / 10));
  206. }
  207. },
  208. gameStartClick: function gameStartClick() {
  209. if (!this.clickFlag) return;
  210. zy.stopBgMusic();
  211. this.clickFlag = false;
  212. cc.director.loadScene("mainScene"); // this.node.runAction(cc.fadeOut(0.8));
  213. // this.node.runAction(cc.sequence(cc.delayTime(0.5), cc.callFunc(function () {
  214. // cc.director.loadScene("mainScene");
  215. // })));
  216. },
  217. // update (dt) {},
  218. onDestroy: function onDestroy() {
  219. //关闭所有音乐、音效
  220. cc.audioEngine.stopAll(); //移除所有事件监听
  221. cc.game.targetOff(this);
  222. }
  223. });
  224. cc._RF.pop();