player.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { EventMgr } from "../Script/Core/Base/EventMgr";
  2. import Start from "../Script/Start";
  3. import { LQCollide } from "../lq_collide_system/lq_collide";
  4. import bullet from "./bullet";
  5. import { Roker_End, Roker_Move } from "./eventDef";
  6. import move from "./move";
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class player extends cc.Component {
  10. /*===========================自动绑定组件开始===========================*/
  11. /*自动生成*/
  12. @property({type:cc.Node, displayName:""})
  13. private $role_node:cc.Node = null;
  14. /*===========================自动绑定组件结束===========================*/
  15. /*===========================自动生成按钮事件开始==========================*/
  16. /*===========================自动生成按钮事件结束==========================*/
  17. moveCpt: move = null;
  18. dirction: cc.Vec2 = cc.v2(0,1);
  19. bulletCD:number = 4;
  20. bulletCDTime: number = 0;
  21. protected onLoad(): void {
  22. this.moveCpt = this.node.getComponent(move);
  23. if(!this.moveCpt) {
  24. this.moveCpt = this.node.addComponent(move);
  25. }
  26. }
  27. protected onEnable(): void {
  28. EventMgr.inst.on(Roker_Move, this.onRokerMove, this);
  29. EventMgr.inst.on(Roker_End, this.onRokerEnd, this);
  30. }
  31. protected onDisable(): void {
  32. EventMgr.inst.off(Roker_Move, this.onRokerMove, this);
  33. EventMgr.inst.off(Roker_End, this.onRokerEnd, this);
  34. }
  35. protected update(dt: number): void {
  36. this.bulletCDTime -= dt;
  37. if(this.bulletCDTime <= 0){
  38. this.bulletCDTime = this.bulletCD;
  39. Start.inst.createPlayerBullet(this.node.getPosition());
  40. }
  41. }
  42. onRokerMove(dirction: cc.Vec2){
  43. this.moveCpt.dirction = dirction;
  44. this.dirction = dirction;
  45. }
  46. onRokerEnd(){
  47. this.moveCpt.dirction = cc.v2(0,0);
  48. }
  49. }