RoosterAliens.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/AliensAudioMgr';
  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(1), 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. EventDispatcher.instance.on(GameEvent.EVENT_GAME_BACK_HOME,this.backHome,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. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(3), 1.0);
  65. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  66. const aimNode = AliensGlobalInstance.instance.aimNode;
  67. aimTarget.active = true;
  68. aimNode.active = false
  69. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  70. }
  71. private onClickResetAim(): void {
  72. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  73. const aimNode = AliensGlobalInstance.instance.aimNode;
  74. aimTarget.active = false;
  75. aimNode.active = true;
  76. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  77. }
  78. private onShoot(): void {
  79. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(4), 1.0);
  80. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  81. }
  82. private async onStart(): Promise<void> {
  83. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  84. const power = UserManager.instance.reducePower(1);
  85. if (!power) {
  86. const match = tgxUIMgr.inst.isShowing(UI_PowerUp);
  87. if (!match) {
  88. tgxUIMgr.inst.showUI(UI_PowerUp);
  89. }
  90. return;
  91. }
  92. await this.startGame();
  93. AliensGlobalInstance.instance.homeUI.active = false;
  94. AliensGlobalInstance.instance.battleUI.active = true;
  95. UserManager.instance.reducePower(1);
  96. }
  97. private backHome(): void {
  98. AliensGlobalInstance.instance.homeUI.active = true;
  99. AliensGlobalInstance.instance.battleUI.active = false;
  100. }
  101. }