RoosterAliens.ts 4.1 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_Setting } from '../scripts/UIDef';
  11. import { tgxUIMgr } from '../core_tgx/tgx';
  12. import { EventDispatcher } from '../core_tgx/easy_ui_framework/EventDispatcher';
  13. const { ccclass, property } = _decorator;
  14. const duration = 0.3;
  15. @ccclass('RoosterAliens')
  16. export class RoosterAliens extends Component {
  17. onLoad() {
  18. AliensAudioMgr.initilize();
  19. // AliensAudioMgr.play(AliensAudioMgr.getMusicIdName(2), 1.0);
  20. LevelManager.instance.initilizeModel();
  21. AliensGlobalInstance.instance.initUI(); //初始化u
  22. this.registerListener();
  23. }
  24. protected start(): void {
  25. AliensGlobalInstance.instance.homeUI.active = true;
  26. AliensGlobalInstance.instance.battleUI.active = false;
  27. }
  28. async startGame() {
  29. await LevelManager.instance.gameStart();
  30. }
  31. registerListener() {
  32. //UI监听
  33. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  34. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  35. const btnPoint = find('Canvas/GameUI/BattleUI/Aim/BtPoint')!;
  36. const btnPointFrame = find('Canvas/GameUI/BattleUI/AimTarget/Mask/frame')!;
  37. const btnShoot = find('Canvas/GameUI/BattleUI/AimTarget/BtnShoot')!;
  38. const btnStart = find('Canvas/GameUI/HomeUI/BtnStart')!;
  39. const btnRender = find('Canvas/GameUI/BattleUI/BottomBtns/BtnRender')!;
  40. const btnProbe = find('Canvas/GameUI/BattleUI/BottomBtns/BtnProbe')!;
  41. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  42. btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
  43. btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
  44. btnShoot.on(NodeEventType.TOUCH_END, () => this.onShoot(), this);
  45. btnStart.on(NodeEventType.TOUCH_END, () => this.onStart(), this);
  46. btnRender.on(NodeEventType.TOUCH_END, () => this.onScreenShot(), this);
  47. btnProbe.on(NodeEventType.TOUCH_END, () => this.onRadar(), this);
  48. //TEST
  49. EventDispatcher.instance.on(GameEvent.EVENT_CAMERA_SHOOT_TEXT,this.testShoot,this);
  50. }
  51. private onClickSet(): void {
  52. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  53. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  54. if (!show) {
  55. tgxUIMgr.inst.showUI(UI_Setting);
  56. }
  57. }
  58. private onClickAim(): void {
  59. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  60. aimTarget.active = true;
  61. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  62. }
  63. private onClickResetAim(): void {
  64. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  65. aimTarget.active = false;
  66. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  67. }
  68. private onShoot(): void {
  69. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SHOOT);
  70. this.onClickResetAim();
  71. }
  72. private onScreenShot(){
  73. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SCREENSHOT);
  74. }
  75. private onRadar(){
  76. console.log('侦擦');
  77. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_SCREENSHOT_RADAR);
  78. }
  79. private async onStart(): Promise<void> {
  80. await this.startGame();
  81. AliensGlobalInstance.instance.homeUI.active = false;
  82. AliensGlobalInstance.instance.battleUI.active = true;
  83. }
  84. private testShoot(): void {
  85. const lbTestShoot = AliensGlobalInstance.instance.lbTestShoot;
  86. lbTestShoot.string = '击中了';
  87. this.scheduleOnce(() => {
  88. lbTestShoot.string = '';
  89. }, 1.0);
  90. }
  91. }