RoosterAliens.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/CarColorsGlobalInstance';
  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. this.startGame();
  26. }
  27. async startGame() {
  28. await LevelManager.instance.gameStart();
  29. }
  30. registerListener() {
  31. //UI监听
  32. const btnRefresh = find('Canvas/GameUI/TopLeft/BtnRefresh')!;
  33. const btnSet = find('Canvas/GameUI/TopLeft/BtnSet')!;
  34. const btnPoint = find('Canvas/GameUI/Aim/BtPoint')!;
  35. const btnPointFrame = find('Canvas/GameUI/AimTarget/Mask/frame')!;
  36. btnSet.on(NodeEventType.TOUCH_END, () => this.onClickSet(), this);
  37. btnPoint.on(NodeEventType.TOUCH_END, () => this.onClickAim(), this);
  38. btnPointFrame.on(NodeEventType.TOUCH_END, () => this.onClickResetAim(), this);
  39. }
  40. private onClickSet(): void {
  41. AliensAudioMgr.playOneShot(AliensAudioMgr.getMusicIdName(2), 1.0);
  42. const show = tgxUIMgr.inst.isShowing(UI_Setting);
  43. if (!show) {
  44. tgxUIMgr.inst.showUI(UI_Setting);
  45. }
  46. }
  47. private onClickAim(): void {
  48. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  49. aimTarget.active = true;
  50. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_AIM);
  51. }
  52. private onClickResetAim(): void {
  53. const aimTarget = AliensGlobalInstance.instance.aimTarget;
  54. aimTarget.active = false;
  55. EventDispatcher.instance.emit(GameEvent.EVENT_CAMERA_RESET_AIM);
  56. }
  57. }