RoosterAliens.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import { TimerMgr } from './Script/Manager/TimerMgr';
  15. const { ccclass, property } = _decorator;
  16. const duration = 0.3;
  17. @ccclass('RoosterAliens')
  18. export class RoosterAliens extends Component {
  19. onLoad() {
  20. AliensAudioMgr.initilize();
  21. // AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(2), 1.0);
  22. UserManager.instance.initilizeModel();
  23. LevelManager.instance.initilizeModel();
  24. AliensGlobalInstance.instance.initUI(); //初始化u
  25. this.registerListener();
  26. this.resetMgr();
  27. }
  28. private resetMgr() {
  29. UserManager.instance.reset();
  30. TimerMgr.inst.reset();
  31. }
  32. protected start(): void {
  33. AliensGlobalInstance.instance.homeUI.active = true;
  34. AliensGlobalInstance.instance.battleUI.active = false;
  35. }
  36. async startGame() {
  37. await LevelManager.instance.gameStart();
  38. }
  39. registerListener() {
  40. //UI监听
  41. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  42. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  43. const btnPoint = find('Canvas/GameUI/BattleUI/Aim/BtPoint')!;
  44. const btnPointFrame = find('Canvas/GameUI/BattleUI/AimTarget/Mask/frame')!;
  45. const btnShoot = find('Canvas/GameUI/BattleUI/AimTarget/BtnShoot')!;
  46. const btnStart = find('Canvas/GameUI/HomeUI/BtnStart')!;
  47. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  48. btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
  49. btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
  50. btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
  51. btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
  52. EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,this);
  53. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_HIDE_AIM,this.onClickResetAim,this);
  54. }
  55. private onClickSet(): void {
  56. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  57. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  58. if (!show) {
  59. tgxUIMgr.inst.showUI(UI_Setting);
  60. }
  61. }
  62. private onClickAim(): void {
  63. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  64. const aimNode = AliensGlobalInstance.instance.aimNode;
  65. aimTarget.active = true;
  66. aimNode.active = false
  67. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  68. }
  69. private onClickResetAim(): void {
  70. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  71. const aimNode = AliensGlobalInstance.instance.aimNode;
  72. aimTarget.active = false;
  73. aimNode.active = true;
  74. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  75. }
  76. private onShoot(): void {
  77. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  78. }
  79. private async onStart(): Promise<void> {
  80. const power = UserManager.instance.reducePower(1);
  81. if (!power) {
  82. const match = tgxUIMgr.inst.isShowing(UI_PowerUp);
  83. if (!match) {
  84. tgxUIMgr.inst.showUI(UI_PowerUp);
  85. }
  86. return;
  87. }
  88. await this.startGame();
  89. AliensGlobalInstance.instance.homeUI.active = false;
  90. AliensGlobalInstance.instance.battleUI.active = true;
  91. UserManager.instance.reducePower(1);
  92. }
  93. }