SingleShotWeapon.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { _decorator, Component, Node, AnimationComponent } from 'cc';
  2. import { SoundManager } from '../../../../engines/sounds/SoundManager';
  3. import { GameController } from '../GameController';
  4. import { WeaponBase } from './WeaponBase';
  5. const { ccclass, property } = _decorator;
  6. export class SingleShotWeapon extends WeaponBase {
  7. constructor(leftHand:AnimationComponent,rightHand:AnimationComponent){
  8. super(leftHand,rightHand);
  9. }
  10. Fire(bullet:boolean):void{
  11. super.Fire(bullet);
  12. if(this.fireKey==1){
  13. this.FireLeft();
  14. }else if(this.fireKey==3){
  15. this.FireRight();
  16. }else{
  17. this.isLeftFire=!this.isLeftFire;
  18. if(this.isLeftFire){
  19. this.FireLeft();
  20. }else{
  21. this.FireRight();
  22. }
  23. }
  24. if(bullet){
  25. this.bulletCount--;
  26. }
  27. }
  28. private FireLeft():void{
  29. GameController.single.WeaponAttack();
  30. this.isLeftFire=true;
  31. this.leftHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  32. this.leftHand.play(this.weaponConfig.handFireAnimation);
  33. this.rightHand.crossFade("Idle",0.5);
  34. this.leftGunFire.play(this.weaponConfig.gunFireAnimation);
  35. SoundManager.single.PlaySound("WeaponLeft",this.weaponConfig.fireSound,false,true);
  36. }
  37. private FireRight():void{
  38. GameController.single.WeaponAttack();
  39. this.isLeftFire=false;
  40. this.rightHand.on(AnimationComponent.EventType.FINISHED,this.FireCompleteHandler,this,true);
  41. this.rightHand.play(this.weaponConfig.handFireAnimation);
  42. this.leftHand.crossFade("Idle",0.5);
  43. this.rightGunFire.play(this.weaponConfig.gunFireAnimation);
  44. SoundManager.single.PlaySound("WeaponRight",this.weaponConfig.fireSound,false,true);
  45. }
  46. private FireCompleteHandler():void{
  47. this.isFire=false;
  48. if(this.isLeftFire){
  49. this.leftHand.crossFade("Idle",0.5);
  50. }else{
  51. this.rightHand.crossFade("Idle",0.5)
  52. }
  53. }
  54. }