game.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import "./js/weapp-adapter"
  2. import { GD, gc } from "./js/human"
  3. import * as PIXI from "./js/pixi.min"
  4. import DwSdk from "./duowansdk/DwSdk";
  5. const debug = false;
  6. const objSdk = GD.objSdk = new DwSdk("厨房消消消", debug);
  7. /*Image server*/
  8. var IMG_SERVER = '';
  9. var GAME_IMG_PATH = 'https://pub.dwstatic.com/wxgame/momobakery/';
  10. var COMMON_IMG_PATH = '';
  11. /*JS Server*/
  12. var JS_SERVER = '';
  13. var GAME_JS_PATH = '';
  14. var COMMON_JS_PATH = 'js/common/';
  15. var JS_PATH = '';
  16. var CACHE_VER = 0.2;
  17. var RES_DIR_IMG = GAME_IMG_PATH + 'image/';
  18. var RES_DIR_JSON = RES_DIR_IMG + 'json/';
  19. var RES_DIR_PNG = RES_DIR_IMG + 'png/';
  20. var RES_DIR_SPINE = RES_DIR_IMG + 'spine/';
  21. var RES_DIR_SOUND = GAME_IMG_PATH + 'sound/';
  22. // source code version
  23. var IMG_VERSION = CACHE_VER;
  24. var SOUND_VERSION = CACHE_VER;
  25. const { pixelRatio, windowWidth, windowHeight } = wx.getSystemInfoSync()
  26. // language settings
  27. GD.leng = 'cn';
  28. GD.isDebug = false;
  29. // Canvas screen settings
  30. GD.init(windowWidth, windowHeight, 0, 0, 0xFFFFFF);
  31. // var app = new PIXI.Application({
  32. // width: windowWidth * pixelRatio,
  33. // height: windowHeight * pixelRatio,
  34. // view: canvas
  35. // })
  36. //PNG==========================================================================================
  37. //game
  38. GD.loader.add('game_bg', RES_DIR_PNG + "game/" + "game_bg_0001.png");
  39. GD.loader.add('game_bg_fever', RES_DIR_PNG + "game/" + "game_bg_fever_0001.png");
  40. GD.loader.add('game_table', RES_DIR_PNG + "game/" + "game_table_0001.png");
  41. GD.loader.add('ready_bg', RES_DIR_PNG + "game/" + "ready_bg_0001.png");
  42. GD.loader.add('shadow_bg', RES_DIR_PNG + "game/" + "shadow_bg.png");
  43. //Medal achievement image
  44. GD.loader.add('game_medal_1', RES_DIR_IMG + "game_medal_0001.png");
  45. GD.loader.add('game_medal_2', RES_DIR_IMG + "game_medal_0002.png");
  46. GD.loader.add('game_medal_3', RES_DIR_IMG + "game_medal_0003.png");
  47. GD.loader.add('game_medal_4', RES_DIR_IMG + "game_medal_0004.png");
  48. //JSON====================================================================================
  49. //number
  50. GD.loader.add(RES_DIR_JSON + "number/" + "number.json");
  51. //game
  52. GD.loader.add(RES_DIR_JSON + "game/" + "game_icon.json");
  53. GD.loader.add(RES_DIR_JSON + "game/" + "game_text.json");
  54. //animation
  55. GD.loader.add(RES_DIR_JSON + "ani/" + "bomb_item_effect.json");
  56. GD.loader.add(RES_DIR_JSON + "ani/" + "clear_effect.json");
  57. GD.loader.add(RES_DIR_JSON + "ani/" + "cookie.json");
  58. GD.loader.add(RES_DIR_JSON + "ani/" + "eraser_item_effect.json");
  59. GD.loader.add(RES_DIR_JSON + "ani/" + "fever_effect1.json");
  60. GD.loader.add(RES_DIR_JSON + "ani/" + "fever_effect2_1.json");
  61. GD.loader.add(RES_DIR_JSON + "ani/" + "fever_effect2_2.json");
  62. GD.loader.add(RES_DIR_JSON + "ani/" + "fever_effect2_3.json");
  63. GD.loader.add(RES_DIR_JSON + "ani/" + "fever_effect2_4.json");
  64. GD.loader.add(RES_DIR_JSON + "ani/" + "item_effect.json");
  65. GD.loader.add(RES_DIR_JSON + "ani/" + "momo_fever.json");
  66. GD.loader.add(RES_DIR_JSON + "ani/" + "momo_normal.json");
  67. GD.loader.add(RES_DIR_JSON + "ani/" + "shushu_fever.json");
  68. GD.loader.add(RES_DIR_JSON + "ani/" + "shushu_normal.json");
  69. //intro
  70. GD.loader.add(RES_DIR_JSON + "intro/" + "intro.json");
  71. //tutorial
  72. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorialUI.json");
  73. if (GD.leng == 'ko') {
  74. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial1.json");
  75. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial2.json");
  76. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial3.json");
  77. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial4.json");
  78. } else {
  79. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial1_" + GD.leng + ".json");
  80. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial2_" + GD.leng + ".json");
  81. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial3_" + GD.leng + ".json");
  82. GD.loader.add(RES_DIR_JSON + "tutorial/" + "tutorial4_" + GD.leng + ".json");
  83. }
  84. GD.loader.load(loadSound);
  85. GD.showProgress();
  86. function loadSound(loader, resource) {
  87. //Sound list settings
  88. var soundList = ['sound_bgm'];
  89. var effectList = [
  90. 'sound_fever',
  91. 'sound_match_1',
  92. 'sound_match_2',
  93. 'sound_match_3',
  94. 'sound_match_fever',
  95. 'sound_ready',
  96. 'sound_start',
  97. 'sound_gameover',
  98. 'sound_momotime',
  99. 'sound_use'
  100. ];
  101. if (GD.soundType == 1) soundList = soundList.concat(effectList);
  102. GD.loadSound(soundList, onAssetsLoaded);
  103. }
  104. function onAssetsLoaded() {
  105. console.log(1);
  106. // Remove loading screen
  107. GD.hideProgress();
  108. onIntro();
  109. gc.IS_MOBILE = true;
  110. GD.app.ticker.add(objSdk.update, null, PIXI.UPDATE_PRIORITY.UTILITY);
  111. // mobileChcck();
  112. }
  113. // Intro
  114. function onIntro() {
  115. GD.stage.removeChildren();
  116. objSdk.showAdIcon(10, 880);
  117. // Common Tutorials
  118. GD.tutorial = GD.Tutorial.getInstance();
  119. GD.tutorial.init(7, 'tutorial_', 'help_prev', 'help_next');
  120. GD.tutorial.setPrevButtonPos(60, GD.height / 2);
  121. GD.tutorial.setNextButtonPos(GD.width - 60, GD.height / 2);
  122. //GD.tutorial.setCloseButtonPos(x, y);
  123. // Intro
  124. var space = 270, posY = 1070;
  125. gc.intro = GD.CommonIntro.getInstance('w', 'intro_bg');
  126. gc.intro.initHelp('intro_help_btn', GD.width / 2 - space, posY);
  127. gc.intro.initSound('intro_option_btn', GD.width / 2 + space, posY);
  128. gc.intro.initStart('intro_start_btn', GD.width / 2, posY, function () {
  129. GD.fullScreen();
  130. onGame();
  131. }, this);
  132. gc.intro.init();
  133. GD.stage.addChild(gc.intro);
  134. }
  135. // game
  136. function onGame() {
  137. GD.stage.removeChildren();
  138. GD.objSdk.hideAdIcon();
  139. // game
  140. gc.game = gc.GameScene.getInstance();
  141. gc.game.init();
  142. GD.stage.addChild(gc.game);
  143. // Common option button
  144. GD.commonOption = GD.CommonOption.getInstance('w');
  145. GD.commonOption.on('OPTION_OPEN_EVENT', onOptionOpen);
  146. GD.commonOption.on('OPTION_CLOSE_EVENT', onOptionClose);
  147. GD.commonOption.on('GAME_RESTART', gameRestart);
  148. GD.commonOption.init();
  149. GD.stage.addChild(GD.commonOption);
  150. GD.bgmPlay(0.8);
  151. }
  152. function onOptionOpen() {
  153. gc.game.pause();
  154. }
  155. function onOptionClose() {
  156. gc.game.resume();
  157. }
  158. //Check whether you are mobile
  159. function mobileChcck() {
  160. var mobileKeyWords = ['iphone', 'ipod', 'blackberry', 'android', 'windows ce', 'lg', 'mot', 'samsung', 'sonyericsson', 'meego', 'nokia', 'webos', 'opera mini', 'opera mobi', 'iemobile'];
  161. gc.IS_MOBILE = false;
  162. var browerAgent = navigator.userAgent.toLowerCase();
  163. for (var i = 0; i < mobileKeyWords.length; ++i) {
  164. if (browerAgent.indexOf(mobileKeyWords[i]) != -1) {
  165. gc.IS_MOBILE = true;
  166. break;
  167. }
  168. }
  169. }
  170. // Restart game
  171. function gameRestart() {
  172. onIntro();
  173. }
  174. wx.onShareAppMessage(function () {
  175. return {
  176. title: "不许动,把平底锅交出来!",
  177. imageUrl: "https://pub.dwstatic.com/wxgame/momobakery/image/share.jpg",
  178. query: ""
  179. }
  180. })
  181. wx.showShareMenu({
  182. withShareTicket: false
  183. })