RoosterAliens.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { _decorator, Component, ERaycast2DType, find, Label, Node, NodeEventType, PhysicsSystem2D, Tween, tween, v2, v3, Vec2, Vec3 } from 'cc';
  2. import { GameEvent } from './Script/Enum/GameEvent';
  3. import { LevelManager } from './Script/Manager/LevelMgr';
  4. import { GameUtil } from './Script/GameUtil';
  5. import { LevelAction } from './Script/LevelAction';
  6. import { GlobalConfig } from '../start/Config/GlobalConfig';
  7. import { AdvertMgr } from '../core_tgx/base/ad/AdvertMgr';
  8. import { AliensAudioMgr } from './Script/Manager/CarUnscrewAudioMgr';
  9. import { AliensGlobalInstance } from './Script/AliensGlobalInstance';
  10. import { UI_PowerUp, UI_Setting } from '../scripts/UIDef';
  11. import { tgxUIMgr } from '../core_tgx/tgx';
  12. import { EventDispatcher } from '../core_tgx/easy_ui_framework/EventDispatcher';
  13. import { UserManager } from './Script/Manager/UserMgr';
  14. const { ccclass, property } = _decorator;
  15. const duration = 0.3;
  16. @ccclass('RoosterAliens')
  17. export class RoosterAliens extends Component {
  18. onLoad() {
  19. AliensAudioMgr.initilize();
  20. // AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(2), 1.0);
  21. UserManager.instance.initilizeModel();
  22. LevelManager.instance.initilizeModel();
  23. AliensGlobalInstance.instance.initUI(); //初始化u
  24. this.registerListener();
  25. }
  26. protected start(): void {
  27. AliensGlobalInstance.instance.homeUI.active = true;
  28. AliensGlobalInstance.instance.battleUI.active = false;
  29. }
  30. async startGame() {
  31. await LevelManager.instance.gameStart();
  32. }
  33. registerListener() {
  34. //UI监听
  35. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  36. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  37. const btnPoint = find('Canvas/GameUI/BattleUI/Aim/BtPoint')!;
  38. const btnPointFrame = find('Canvas/GameUI/BattleUI/AimTarget/Mask/frame')!;
  39. const btnShoot = find('Canvas/GameUI/BattleUI/AimTarget/BtnShoot')!;
  40. const btnStart = find('Canvas/GameUI/HomeUI/BtnStart')!;
  41. const btnRender = find('Canvas/GameUI/BattleUI/BottomBtns/BtnRender')!;
  42. const btnProbe = find('Canvas/GameUI/BattleUI/BottomBtns/BtnProbe')!;
  43. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  44. btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
  45. btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
  46. btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
  47. btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
  48. btnRender.on(NodeEventType.TOUCH_END, () => this.onScreenShot(), this);
  49. btnProbe.on(NodeEventType.TOUCH_END, () => this.onRadar(), this);
  50. //TEST
  51. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT_TEXT,this.testShoot,this);
  52. EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,this);
  53. }
  54. private onClickSet(): void {
  55. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  56. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  57. if (!show) {
  58. tgxUIMgr.inst.showUI(UI_Setting);
  59. }
  60. }
  61. private onClickAim(): void {
  62. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  63. aimTarget.active = true;
  64. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  65. }
  66. private onClickResetAim(): void {
  67. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  68. aimTarget.active = false;
  69. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  70. }
  71. private onShoot(): void {
  72. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  73. this.onClickResetAim();
  74. }
  75. private onScreenShot(){
  76. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SCREENSHOT);
  77. }
  78. private onRadar(){
  79. console.log('侦擦');
  80. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR);
  81. }
  82. private async onStart(): Promise<void> {
  83. const power = UserManager.instance.reducePower(1);
  84. if (!power) {
  85. const match = tgxUIMgr.inst.isShowing(UI_PowerUp);
  86. if (!match) {
  87. tgxUIMgr.inst.showUI(UI_PowerUp);
  88. }
  89. return;
  90. }
  91. await this.startGame();
  92. AliensGlobalInstance.instance.homeUI.active = false;
  93. AliensGlobalInstance.instance.battleUI.active = true;
  94. UserManager.instance.reducePower(1);
  95. }
  96. private testShoot(): void {
  97. const lbTestShoot = AliensGlobalInstance.instance.lbTestShoot;
  98. lbTestShoot.string = '击中了';
  99. this.scheduleOnce(() => {
  100. lbTestShoot.string = '';
  101. }, 1.0);
  102. }
  103. }