GameOverAction.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. initAdForPage(){
  27. console.log('zh:initAdForPage for GameOverAction.ts')
  28. if(sys.os===sys.OS.ANDROID){
  29. console.log('zh:initAdForPage 1')
  30. let deviceId = AAJS2.getDeviceUserId();
  31. console.log("zh:checkstatus:",ATRewardedVideoSDK.checkAdStatus(AAJS2.getPlacementId()));
  32. var setting = {};
  33. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  34. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementId(), setting);
  35. }
  36. console.log('zh:GameOverAction 2')
  37. }
  38. update(deltaTime: number) {
  39. }
  40. //show menu panel
  41. open() {
  42. if(this.node.position.x == 0 && this.node.position.y == 0){
  43. //console.log("打开中,跳过");
  44. return;
  45. }
  46. super.open();
  47. this.fail_img.scale = new Vec3(2, 2, 0);
  48. tween(this.fail_img)
  49. .to(0.3, { scale: new Vec3(1, 1, 0) },Global.our_easing)
  50. .call(() => {
  51. })
  52. .start();
  53. this.fail_dou.scale = new Vec3(0.1, 0.1, 0);
  54. tween(this.fail_dou)
  55. .to(0.3, { scale: new Vec3(1, 1, 0) },Global.our_easing)
  56. .call(() => {
  57. }).start();
  58. AudioMgr.ins.playSound(Clips.fail);
  59. }
  60. btn_go_home() {
  61. this.close();
  62. director.loadScene("home");
  63. AdManger.show_interstial();
  64. }
  65. btn_restart_game() {
  66. this.close();
  67. Global.main_action.restart_game();
  68. AdManger.show_interstial();
  69. }
  70. clear_pins_videos(){
  71. console.log('zh:失败了,我要复活。。。')
  72. AudioMgr.ins.playSound(Clips.btn_1);
  73. let pin_arr = Global.layer_empty_action.get_pin_arr();
  74. if (pin_arr.length == 0) {
  75. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  76. return;
  77. }
  78. if (!DjManger.use_dj(DJ.Btn_5,DJ_TYPE.Type_video)) {
  79. Global.tips_action.show("Current Level: Props Exhausted");//当前关卡次数已经用完
  80. return;
  81. }
  82. // Global.log_dj();
  83. // this.close();
  84. // Global.log_dj();
  85. if(sys.os == sys.OS.ANDROID){
  86. if(ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementId())){
  87. console.log('zh:继续 ad ok')
  88. sys.localStorage.setItem('yxAdMark', 'fuHuo');//看广告用于 继续 标记
  89. ATRewardedVideoSDK.showAd(AAJS2.getPlacementId());
  90. }else{
  91. console.log('zh:继续 ad no ok')
  92. Global.tips_action.show("No reward video for now");//没有奖励视频
  93. //this.useCoinsForAdPlayEnd();
  94. }
  95. }
  96. //下面是原始的
  97. // AdManger.show_video((data) => {
  98. // if (data == 1) {
  99. // console.log("clear_pins_videos 获取奖励成功");
  100. // this.close();
  101. // //解锁
  102. // Global.bucket_action.put_pins(pin_arr);
  103. // } else {
  104. // Global.tips_action.show("Gain reward failure");//获取奖励失败
  105. // //退款
  106. // DjManger.return_used_dj(DJ.Btn_5,DJ_TYPE.Type_video);
  107. // }
  108. // })
  109. }
  110. /**
  111. * 消耗钻石 ad 播放完毕 消耗钻石
  112. */
  113. useCoinsForAdPlayEnd() {
  114. console.log("zh:yxContinue 继续 奖励start");
  115. this.close();
  116. let pin_arr = Global.layer_empty_action.get_pin_arr();
  117. if (pin_arr.length == 0) {
  118. Global.tips_action.show("No Screws to Clear");//没有可清理的钉子
  119. return;
  120. }
  121. //解锁
  122. Global.bucket_action.put_pins(pin_arr);
  123. console.log("zh:yxContinue 继续 奖励end");
  124. //清理AD奖励标记
  125. sys.localStorage.removeItem('yxAdMark')
  126. }
  127. }