RoosterAliens.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. //TEST
  53. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT_TEXT,this.testShoot,this);
  54. EventDispatcher.instance.on(GameEvent.EVENT_GAME_ENTER,this.onStart,this);
  55. }
  56. private onClickSet(): void {
  57. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  58. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  59. if (!show) {
  60. tgxUIMgr.inst.showUI(UI_Setting);
  61. }
  62. }
  63. private onClickAim(): void {
  64. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  65. aimTarget.active = true;
  66. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  67. }
  68. private onClickResetAim(): void {
  69. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  70. aimTarget.active = false;
  71. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  72. }
  73. private onShoot(): void {
  74. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  75. this.onClickResetAim();
  76. }
  77. private async onStart(): Promise<void> {
  78. const power = UserManager.instance.reducePower(1);
  79. if (!power) {
  80. const match = tgxUIMgr.inst.isShowing(UI_PowerUp);
  81. if (!match) {
  82. tgxUIMgr.inst.showUI(UI_PowerUp);
  83. }
  84. return;
  85. }
  86. await this.startGame();
  87. AliensGlobalInstance.instance.homeUI.active = false;
  88. AliensGlobalInstance.instance.battleUI.active = true;
  89. UserManager.instance.reducePower(1);
  90. }
  91. private testShoot(): void {
  92. const lbTestShoot = AliensGlobalInstance.instance.lbTestShoot;
  93. lbTestShoot.string = '击中了';
  94. this.scheduleOnce(() => {
  95. lbTestShoot.string = '';
  96. }, 1.0);
  97. }
  98. }