ZY_HomeScene.js 10 KB

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