GameController.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { _decorator, Component, Node, SkeletalAnimationComponent, AnimationComponent, Vec3, director, find, instantiate } from 'cc';
  2. import { WeaponBase } from './weapons/WeaponBase';
  3. import { GameModel } from '../../models/GameModel';
  4. import { EventDispatcher } from '../../../engines/events/EventDispatcher';
  5. const { ccclass, property } = _decorator;
  6. export class GameController extends EventDispatcher{
  7. public weapon:WeaponBase;
  8. constructor()
  9. {
  10. super();
  11. }
  12. /**
  13. * 初始化
  14. * @param leftHand
  15. * @param rightHand
  16. */
  17. Init(leftHand:AnimationComponent,rightHand:AnimationComponent):void{
  18. this.weapon=new WeaponBase(leftHand,rightHand);
  19. this.StartGame();
  20. }
  21. /**
  22. * 开始游戏
  23. */
  24. StartGame():void{
  25. //直接重置子弹数量
  26. this.weapon.bulletCount=GameModel.single.currentWeaponConfig.clip;
  27. }
  28. TryFire(fireKey:number):void{
  29. if(fireKey==0){
  30. this.weapon.StopFire();
  31. }else{
  32. this.weapon.StartFire(fireKey);
  33. }
  34. }
  35. Update(dt:number):void{
  36. this.weapon.Update(dt);
  37. }
  38. private static instance:GameController;
  39. public static get single(){
  40. if(this.instance==null){
  41. this.instance=new GameController();
  42. }
  43. return this.instance;
  44. }
  45. }