Main.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. import { _decorator, BoxCollider2D, CircleCollider2D, Component, director, EventTouch, Input, instantiate, log, Node, PolygonCollider2D, Prefab, RigidBody2D, Sprite, sys } from 'cc';
  2. import { LayerRootAction } from './LayerRootAction';
  3. import { Screen } from "cc";
  4. import { Global } from './Global';
  5. import { LayerCatAction } from './LayerCatAction';
  6. import { LayerEmptyAction } from './LayerEmptyAction';
  7. import { Clips, events } from './Enums';
  8. import { PoolMgr } from './PoolMagr';
  9. import { LevelAction } from './LevelAction';
  10. import { AudioMgr } from './AudioMgr';
  11. import { CatAction } from './CatAction';
  12. import { MenuAction } from './MenuAction';
  13. import { ShowLevelAction } from './ShowLevelAction';
  14. import { GameOverAction } from './GameOverAction';
  15. import { CoinsAction } from './CoinsAction';
  16. import { SuccessAction } from './SuccessAction';
  17. import { LayerBtnAction } from './LayerBtnAction';
  18. import { TipsAction } from './TipsAction';
  19. import { BucketAction } from './BucketAction';
  20. import { PropsAction } from './PropsAction';
  21. import { DjManger } from './DjManger';
  22. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoTSSDK"
  23. import AAJS2 from "./utils/ATAndroidJS2";
  24. import ATJSSDK from "./AnyThinkAds/ATJSSDK";
  25. import { EncryptUtil } from './utils/EncryptUtil';
  26. const { ccclass, property } = _decorator;
  27. @ccclass('Main')
  28. export class Main extends Component {
  29. private state = false;
  30. @property({ type: LayerRootAction })
  31. layer_root: LayerRootAction
  32. @property({ type: LayerCatAction })
  33. layer_cat: LayerCatAction
  34. @property({ type: LayerEmptyAction })
  35. layer_empty: LayerEmptyAction
  36. @property({ type: ShowLevelAction })
  37. Show_level_action: ShowLevelAction
  38. @property({ type: MenuAction })
  39. menu: MenuAction
  40. @property({ type: GameOverAction })
  41. game_over_action: GameOverAction
  42. @property({ type: CoinsAction })
  43. coins_action: CoinsAction
  44. @property({ type: SuccessAction })
  45. success_action: SuccessAction
  46. @property({ type: LayerBtnAction })
  47. layer_btn_action: LayerBtnAction
  48. @property({ type: TipsAction })
  49. tips_action: TipsAction;
  50. @property({ type: BucketAction })
  51. bucket_action: BucketAction;
  52. @property({ type: PropsAction })
  53. props_action: PropsAction;
  54. protected onLoad(): void {
  55. console.log("zh:main.ts onLoad");
  56. director.on(events.check_completed, this.next_lvlcheck_completed, this);
  57. this.initAd();
  58. }
  59. initAd() {
  60. // // 初始化SDK
  61. ATJSSDK.initSDK("h67122e47607cd", "a4fd9a23bdd71c2314cf41140a77abb1e");//这是cccc线上的
  62. //ATJSSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");
  63. ATJSSDK.setLogDebug(true);
  64. // // 针对欧盟地区初始化时做的处理,按需求打开,不在欧盟地区发布的不用使用。
  65. ATJSSDK.getUserLocation(function (userLocation) {
  66. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  67. if (userLocation === ATJSSDK.kATUserLocationInEU) {
  68. if (ATJSSDK.getGDPRLevel() === ATJSSDK.UNKNOWN) {
  69. ATJSSDK.showGDPRAuth();
  70. }
  71. }
  72. });
  73. //var state = false;
  74. ATRewardedVideoSDK.setAdListener(this);
  75. if (sys.os === sys.OS.ANDROID) {
  76. let deviceId = AAJS2.getDeviceUserId();
  77. //console.log("checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  78. var setting = {};
  79. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  80. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  81. }
  82. if (sys.platform == sys.Platform.ANDROID) {
  83. setTimeout(() => {
  84. var allInfo = AAJS2.allInfo();
  85. console.log('zh:allInfo=' + allInfo)
  86. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  87. let iv = "Jn0.aWsOu$y-Dbqb";
  88. let data = { data: EncryptUtil.aesEncrypt(allInfo, key, iv) };
  89. console.log("zh:allInfo jm=" + JSON.stringify(data));
  90. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  91. }, 1000);
  92. }
  93. }
  94. start() {
  95. Global.layer_root_action = this.layer_root;
  96. Global.layer_cat_action = this.layer_cat;
  97. Global.layer_empty_action = this.layer_empty;
  98. Global.main_action = this;
  99. Global.Show_level_action = this.Show_level_action;
  100. Global.game_over_action = this.game_over_action;
  101. Global.coins_action = this.coins_action;
  102. Global.success_action = this.success_action;
  103. Global.layer_btn_action = this.layer_btn_action;
  104. Global.tips_action = this.tips_action;
  105. Global.bucket_action = this.bucket_action;
  106. Global.props_action = this.props_action;
  107. this.restart_game();
  108. }
  109. //从头开始游戏,1..max
  110. restart_game() {
  111. Global.restart_default(); // 3
  112. this.next_lvl();
  113. }
  114. next_lvl() {
  115. //重置 钉子,金币
  116. Global.every_level_default();
  117. DjManger.reset_dj_cur_();
  118. let cur_lvl = Global.next_level();
  119. console.log("current level >>>>", cur_lvl);
  120. this.layer_root.init_root(cur_lvl);
  121. Global.Show_level_action.show_level();
  122. Global.coins_action.refrush_coins();
  123. // Global.layer_root_action.random_pin();
  124. }
  125. next_lvlcheck_completed(catAction: CatAction) {
  126. // Global.success_action.open();return;
  127. if (Global.cur_lvl_pin_move_num >= Global.cur_lvl_pin_total) {
  128. // console.log(" check is completed success");
  129. Global.success_action.open();
  130. } else {
  131. catAction.into_scence();
  132. }
  133. }
  134. btn_open_menu() {
  135. AudioMgr.ins.playSound(Clips.btn_1);
  136. this.menu.open();
  137. }
  138. update(deltaTime: number) {
  139. }
  140. //#region 'ad'
  141. onRewardedVideoAdLoaded(placementId) {
  142. console.log("zh:onRewardedVideoAdLoaded", placementId, "", "")
  143. }
  144. onRewardedVideoAdFailed(placementId, errorInfo) {
  145. console.log("zh:onRewardedVideoAdFailed", placementId, "", errorInfo)
  146. }
  147. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  148. console.log("zh:onRewardedVideoAdPlayStart", placementId, callbackInfo, "")
  149. let deviceId = AAJS2.getDeviceUserId();
  150. var setting = {};
  151. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  152. ATRewardedVideoSDK.loadRewardedVideo("n66f7c61b71d4c", setting);
  153. }
  154. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  155. console.log("zh:onRewardedVideoAdPlayEnd", placementId, callbackInfo, "")
  156. }
  157. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  158. console.log("zh:onRewardedVideoAdPlayFailed", placementId, callbackInfo, errorInfo)
  159. }
  160. onRewardedVideoAdClosed(placementId, callbackInfo) {
  161. console.log("zh:onRewardedVideoAdClosed", placementId, callbackInfo, "")
  162. }
  163. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  164. console.log("zh:onRewardedVideoAdPlayClicked", placementId, callbackInfo, "")
  165. }
  166. onReward(placementId, callbackInfo) {
  167. this.state = true;
  168. }
  169. //Callbacks added v5.8.10
  170. onAdSourceBiddingAttempt(placementId, callbackInfo) {
  171. console.log("zh:onAdSourceBiddingAttempt", placementId, callbackInfo, "")
  172. }
  173. onAdSourceBiddingFilled(placementId, callbackInfo) {
  174. console.log("zh:onAdSourceBiddingFilled", placementId, "", "")
  175. }
  176. onAdSourceBiddingFail(placementId, errorInfo, callbackInfo) {
  177. console.log("zh:onAdSourceBiddingFail", placementId, callbackInfo, errorInfo)
  178. }
  179. onAdSourceAttempt(placementId, callbackInfo) {
  180. console.log("zh:onAdSourceAttempt", placementId, callbackInfo, "")
  181. }
  182. onAdSourceLoadFilled(placementId, callbackInfo) {
  183. console.log("zh:onAdSourceLoadFilled", placementId, callbackInfo, "")
  184. }
  185. onAdSourceLoadFail(placementId, errorInfo, callbackInfo) {
  186. console.log("zh:onAdSourceLoadFail", placementId, callbackInfo, errorInfo)
  187. }
  188. onRewardedVideoAdAgainPlayStart(placementId, callbackInfo) {
  189. console.log("zh:onRewardedVideoAdAgainPlayStart", placementId, callbackInfo, "")
  190. }
  191. onRewardedVideoAdAgainPlayEnd(placementId, callbackInfo) {
  192. console.log("zh:onRewardedVideoAdAgainPlayEnd", placementId, callbackInfo, "")
  193. }
  194. onRewardedVideoAdAgainPlayFailed(placementId, errorInfo, callbackInfo) {
  195. console.log("zh:onRewardedVideoAdAgainPlayFailed", placementId, callbackInfo, errorInfo)
  196. }
  197. onRewardedVideoAdAgainPlayClicked(placementId, callbackInfo) {
  198. console.log("zh:onRewardedVideoAdAgainPlayClicked", placementId, callbackInfo, "")
  199. }
  200. onAgainReward(placementId, callbackInfo) {
  201. console.log("zh:onAgainReward", placementId, callbackInfo, "")
  202. this.state = true;
  203. }
  204. //#endregion
  205. }
  206. window["Main"] = ATRewardedVideoSDK;
  207. let printLog = function (methodName, placementId, callbackInfo, errorInfo) {
  208. ATJSSDK.printLogWithParams("AnyThinkRewardedVideoDemo", methodName, placementId, callbackInfo, errorInfo)
  209. }