RoosterAliens.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. TimerMgr.inst.reset();
  30. }
  31. protected start(): void {
  32. AliensGlobalInstance.instance.homeUI.active = true;
  33. AliensGlobalInstance.instance.battleUI.active = false;
  34. }
  35. async startGame() {
  36. await LevelManager.instance.gameStart();
  37. }
  38. registerListener() {
  39. //UI监听
  40. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  41. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  42. const btnPoint = find('Canvas/GameUI/BattleUI/Aim/BtPoint')!;
  43. const btnPointFrame = find('Canvas/GameUI/BattleUI/AimTarget/Mask/frame')!;
  44. const btnShoot = find('Canvas/GameUI/BattleUI/AimTarget/BtnShoot')!;
  45. const btnStart = find('Canvas/GameUI/HomeUI/BtnStart')!;
  46. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  47. btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
  48. btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
  49. btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
  50. btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
  51. //TEST
  52. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT_TEXT,this.testShoot,this);
  53. EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,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. aimTarget.active = true;
  65. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  66. }
  67. private onClickResetAim(): void {
  68. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  69. aimTarget.active = false;
  70. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  71. }
  72. private onShoot(): void {
  73. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  74. this.onClickResetAim();
  75. }
  76. private async onStart(): Promise<void> {
  77. const power = UserManager.instance.reducePower(1);
  78. if (!power) {
  79. const match = tgxUIMgr.inst.isShowing(UI_PowerUp);
  80. if (!match) {
  81. tgxUIMgr.inst.showUI(UI_PowerUp);
  82. }
  83. return;
  84. }
  85. await this.startGame();
  86. AliensGlobalInstance.instance.homeUI.active = false;
  87. AliensGlobalInstance.instance.battleUI.active = true;
  88. UserManager.instance.reducePower(1);
  89. }
  90. private testShoot(): void {
  91. const lbTestShoot = AliensGlobalInstance.instance.lbTestShoot;
  92. lbTestShoot.string = '击中了';
  93. this.scheduleOnce(() => {
  94. lbTestShoot.string = '';
  95. }, 1.0);
  96. }
  97. }