index.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>StormSunder</title>
  6. <!--http://www.html5rocks.com/en/mobile/mobifying/-->
  7. <meta name="viewport"
  8. content="width=device-width,user-scalable=no,initial-scale=1,minimum-scale=1,maximum-scale=1,minimal-ui=true" />
  9. <!--https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html-->
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  12. <meta name="format-detection" content="telephone=no">
  13. <!-- force webkit on 360 -->
  14. <meta name="renderer" content="webkit" />
  15. <meta name="force-rendering" content="webkit" />
  16. <!-- force edge on IE -->
  17. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  18. <meta name="msapplication-tap-highlight" content="no">
  19. <!-- force full screen on some browser -->
  20. <meta name="full-screen" content="yes" />
  21. <meta name="x5-fullscreen" content="true" />
  22. <meta name="360-fullscreen" content="true" />
  23. <!--fix fireball/issues/3568 -->
  24. <!--<meta name="browsermode" content="application">-->
  25. <meta name="x5-page-mode" content="app">
  26. <!--<link rel="apple-touch-icon" href=".png" />-->
  27. <!--<link rel="apple-touch-icon-precomposed" href=".png" />-->
  28. <link rel="stylesheet" type="text/css" href="style.css" />
  29. </head>
  30. <body>
  31. <div id="GameDiv" cc_exact_fit_screen="true">
  32. <div id="Cocos3dGameContainer">
  33. <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="99"></canvas>
  34. </div>
  35. </div>
  36. <!-- Polyfills bundle. -->
  37. <script src="src/polyfills.bundle.js" charset="utf-8"> </script>
  38. <!-- SystemJS support. -->
  39. <script src="src/system.bundle.js" charset="utf-8"> </script>
  40. <!-- Import map -->
  41. <script src="src/import-map.json" type="systemjs-importmap" charset="utf-8"> </script>
  42. <script>
  43. // adInstance = null
  44. // 动态加载外部脚本的方法
  45. loadScript = function (url) {
  46. return new Promise((resolve, reject) => {
  47. const script = document.createElement('script');
  48. script.src = url;
  49. script.async = true;
  50. script.onload = () => resolve();
  51. script.onerror = () => reject(new Error(`Failed to load script: ${url}`));
  52. document.head.appendChild(script);
  53. });
  54. }
  55. // 加载 PRESDK3.0.1.js,然后启动项目
  56. loadScript('https://www.cpsense.com/public/PRESDK3.0.1.js')
  57. .then(() => {
  58. console.log('PRESDK3.0.1.js loaded successfully');
  59. // 初始化广告 SDK
  60. var adSdkConfig = {
  61. el: document.querySelector("GameDiv"),
  62. client: 'cpsense-cd',
  63. is_test: true
  64. };
  65. var adInstance = new adSdk(adSdkConfig);
  66. window.adInstance = adInstance;
  67. window.CPSenseShowAd = {
  68. showAd: function (type) {
  69. return new Promise((resolve, reject) => {
  70. if (type === 'interstitial') {
  71. adInstance.interstitialAd({
  72. beforeAd: function () {
  73. console.log("The ad starts playing")
  74. },
  75. afterAd: function () {
  76. console.log("The ad ends playing")
  77. resolve({
  78. result: 'success',
  79. message: 'Interstitial ad closed'
  80. });
  81. },
  82. error: function (n) {
  83. console.log("error", n);
  84. reject(new Error('Interstitial ad error'));
  85. }
  86. });
  87. } else if (type === 'rewarded') {
  88. adInstance.rewardAd({
  89. beforeAd: function () {
  90. console.log("The ad starts playing, and the game should pause."),
  91. window.youxi.SoundManager.pauseAll(),
  92. window.youxi.GameManager.pauseAll();
  93. },
  94. adDismissed: function () {
  95. console.log("Player dismissed the ad before completion."),
  96. window.youxi.SoundManager.resumeAll(),
  97. window.youxi.GameManager.resumeAll();
  98. reject(new Error('Interstitial ad error'));
  99. },
  100. adViewed: function () {
  101. console.log("Ad was viewed and closed."),
  102. window.youxi.SoundManager.resumeAll(),
  103. window.youxi.GameManager.resumeAll();
  104. resolve({
  105. result: 'success',
  106. message: 'Interstitial ad closed'
  107. });
  108. },
  109. error: function (n) {
  110. console.log("error", n);
  111. window.youxi.SoundManager.resumeAll();
  112. window.youxi.GameManager.resumeAll();
  113. reject(new Error('Interstitial ad error'));
  114. }
  115. })
  116. } else {
  117. reject(new Error('Invalid ad type'));
  118. }
  119. });
  120. }
  121. };
  122. console.log('AD initialized successfully');
  123. })
  124. .then(() => {
  125. // 加载项目主入口
  126. return System.import('./index.js');
  127. })
  128. .catch(err => {
  129. console.error('Error during initialization:', err);
  130. });
  131. // 外部广告调用
  132. window.showAd = function (type) {
  133. type = type.toLowerCase();
  134. return new Promise((resolve, reject) => {
  135. window.CPSenseShowAd.showAd(type)
  136. .then((res) => {
  137. // 为游戏返回广告结果
  138. console.log(res);
  139. resolve(res);
  140. })
  141. .catch((err) => {
  142. console.log(err);
  143. reject(err);
  144. });
  145. });
  146. };
  147. // 回调测试
  148. function TopCallback() {
  149. //sound
  150. if (window.__woso.SoundManager.isSound) {
  151. window.youxi.SoundManager.resumeAll();
  152. } else {
  153. window.youxi.SoundManager.pauseAll();
  154. }
  155. }
  156. </script>
  157. </body>
  158. </html>