InsTower.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { _decorator, animation, Animation, AnimationClip, macro, Node, Sprite, tween } from 'cc';
  2. import { Tower } from '../Tower';
  3. import { GameMgr } from './GameMgr';
  4. import { BulletMgr } from './BulletMgr';
  5. import { Tools } from '../Tools/Tools';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('InsTower')
  8. //发射子弹类型的塔
  9. export class ShootTower extends Tower {
  10. protected _attack(): void {
  11. //发射子弹
  12. // this.schedule(() => {
  13. //this._ani.play();
  14. // this._ani.on(Animation.EventType.FINISHED,()=>{
  15. // GameMgr.Instance.getModuler(BulletMgr).createBullet(
  16. // this.node.position, this._targetAngle, this._bulletFrames);
  17. // })
  18. // }, 1, macro.REPEAT_FOREVER, 0)
  19. }
  20. protected stopAttack(): void {
  21. this.unscheduleAllCallbacks();
  22. }
  23. }
  24. //太阳
  25. export class ExpandTower extends Tower {
  26. private _weapon: Animation = null;
  27. protected _attack(): void {
  28. if (!this._weapon) {
  29. // 创建动画
  30. const node = Tools.createSprite(null, this.node);
  31. this._weapon = Tools.createAnimation(this._bulletFrames, 15, node);
  32. node.active = false;
  33. // const node = new Node();
  34. // node.addComponent(Sprite);
  35. // this._weapon = node.addComponent(Animation)
  36. // //添加动画剪辑
  37. // const clip = AnimationClip.createWithSpriteFrames(this._bulletFrames, 15);
  38. // this._weapon.addClip(clip);
  39. // this._weapon.defaultClip = clip;
  40. // node.active = false;
  41. // node.parent = this.node;
  42. }
  43. this.schedule(()=>{
  44. this._weapon.node.active = true;
  45. //tween(this._chassis).by(0.2,{angle: -20}).start();
  46. this._weapon.play();
  47. //动画组件注册事件
  48. this._weapon.on(Animation.EventType.FINISHED,()=>{
  49. this._weapon.node.active = false;
  50. if(!this._isFire){
  51. this.unscheduleAllCallbacks();
  52. }
  53. })
  54. }, 1)
  55. this._weapon.play();
  56. }
  57. }
  58. //
  59. export class LaserTower extends Tower {
  60. }
  61. export class MShootTower extends Tower {
  62. }
  63. export class StickTower extends Tower {
  64. }