GameOverAction.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { _decorator, Component, director, Node, Sprite, tween, Vec3, Widget, sys } from 'cc';
  2. import { AudioMgr } from './AudioMgr';
  3. import { Clips, DJ, DJ_TYPE } from './Enums';
  4. import { Global } from './Global';
  5. import { BasePage } from './BasePage';
  6. import { AdManger } from './ad/AdManger';
  7. import { DjManger } from './DjManger';
  8. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoTSSDK"
  9. import AAJS2 from "./utils/ATAndroidJS2";
  10. import ATJSSDK from "./AnyThinkAds/ATJSSDK";
  11. import { CoinsAction } from './CoinsAction';
  12. //import { EncryptUtil } from './utils/EncryptUtil';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('GameOverAction')
  15. export class GameOverAction extends BasePage {
  16. @property({ type: Node })
  17. fail_img: Node
  18. @property({ type: Node })
  19. fail_dou: Node
  20. @property({ type: Node })
  21. btn_continue: Node
  22. start() {
  23. super.start();
  24. this.initAdForPage();
  25. }
  26. /**
  27. *
  28. */
  29. initAdForPage() {
  30. console.log('zh:initAdForPage for GameOverAction.ts')
  31. if (sys.os === sys.OS.ANDROID) {
  32. console.log('zh:initAdForPage 1')
  33. let deviceId = AAJS2.getDeviceUserId();
  34. console.log("zh:checkstatus:", ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  35. var setting = {};
  36. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  37. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  38. }
  39. console.log('zh:GameOverAction 2')
  40. }
  41. update(deltaTime: number) {
  42. }
  43. /**
  44. * show menu panel
  45. * @returns
  46. */
  47. open() {
  48. if (this.node.position.x == 0 && this.node.position.y == 0) {
  49. //console.log("打开中,跳过");
  50. return;
  51. }
  52. super.open();
  53. this.fail_img.scale = new Vec3(2, 2, 0);
  54. tween(this.fail_img)
  55. .to(0.3, { scale: new Vec3(1, 1, 0) }, Global.our_easing)
  56. .call(() => {
  57. })
  58. .start();
  59. this.fail_dou.scale = new Vec3(0.1, 0.1, 0);
  60. tween(this.fail_dou)
  61. .to(0.3, { scale: new Vec3(1, 1, 0) }, Global.our_easing)
  62. .call(() => {
  63. }).start();
  64. AudioMgr.ins.playSound(Clips.fail);
  65. }
  66. /**
  67. * go to home page
  68. */
  69. btn_go_home() {
  70. this.close();
  71. director.loadScene("home");
  72. AdManger.show_interstial();
  73. }
  74. /**
  75. * restart game
  76. */
  77. btn_restart_game() {
  78. this.close();
  79. Global.main_action.restart_game();
  80. AdManger.show_interstial();
  81. }
  82. /**
  83. *
  84. * @returns
  85. */
  86. clear_pins_videos() {
  87. console.log('zh:失败了,我要复活。。。')
  88. AudioMgr.ins.playSound(Clips.btn_1);
  89. let pin_arr = Global.layer_empty_action.get_pin_arr();
  90. if (pin_arr.length == 0) {
  91. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  92. return;
  93. }
  94. if (!DjManger.use_dj(DJ.Btn_5, DJ_TYPE.Type_video)) {
  95. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  96. return;
  97. }
  98. // Global.log_dj();
  99. // this.close();
  100. // Global.log_dj();
  101. if (sys.os == sys.OS.ANDROID) {
  102. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())) {
  103. console.log('zh:继续 ad ok')
  104. sys.localStorage.setItem('yxAdMark', 'fuHuo');//看广告用于 继续 标记
  105. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  106. } else {
  107. console.log('zh:继续 ad no ok')
  108. Global.tips_action.show("No reward video for now");//没有奖励视频
  109. //this.useCoinsForAdPlayEnd();
  110. }
  111. }
  112. //下面是原始的
  113. // AdManger.show_video((data) => {
  114. // if (data == 1) {
  115. // console.log("clear_pins_videos 获取奖励成功");
  116. // this.close();
  117. // //解锁
  118. // Global.bucket_action.put_pins(pin_arr);
  119. // } else {
  120. // Global.tips_action.show("Gain reward failure");//获取奖励失败
  121. // //退款
  122. // DjManger.return_used_dj(DJ.Btn_5,DJ_TYPE.Type_video);
  123. // }
  124. // })
  125. }
  126. /**
  127. * 消耗钻石 ad 播放完毕 消耗钻石
  128. */
  129. useCoinsForAdPlayEnd() {
  130. console.log("zh:yxContinue 继续 奖励start");
  131. this.close();
  132. let pin_arr = Global.layer_empty_action.get_pin_arr();
  133. if (pin_arr.length == 0) {
  134. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  135. return;
  136. }
  137. //解锁
  138. Global.bucket_action.put_pins(pin_arr);
  139. console.log("zh:yxContinue 继续 奖励end");
  140. //清理AD奖励标记
  141. sys.localStorage.removeItem('yxAdMark')
  142. }
  143. }