1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { EventMgr } from "../Script/Core/Base/EventMgr";
- import Start from "../Script/Start";
- import { LQCollide } from "../lq_collide_system/lq_collide";
- import bullet from "./bullet";
- import { Roker_End, Roker_Move } from "./eventDef";
- import move from "./move";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class player extends cc.Component {
- /*===========================自动绑定组件开始===========================*/
- /*自动生成*/
- @property({type:cc.Node, displayName:""})
- private $role_node:cc.Node = null;
-
- /*===========================自动绑定组件结束===========================*/
- /*===========================自动生成按钮事件开始==========================*/
- /*===========================自动生成按钮事件结束==========================*/
- moveCpt: move = null;
- dirction: cc.Vec2 = cc.v2(0,1);
- bulletCD:number = 4;
- bulletCDTime: number = 0;
- protected onLoad(): void {
- this.moveCpt = this.node.getComponent(move);
- if(!this.moveCpt) {
- this.moveCpt = this.node.addComponent(move);
- }
-
- }
- protected onEnable(): void {
- EventMgr.inst.on(Roker_Move, this.onRokerMove, this);
- EventMgr.inst.on(Roker_End, this.onRokerEnd, this);
- }
-
- protected onDisable(): void {
- EventMgr.inst.off(Roker_Move, this.onRokerMove, this);
- EventMgr.inst.off(Roker_End, this.onRokerEnd, this);
-
- }
- protected update(dt: number): void {
- this.bulletCDTime -= dt;
- if(this.bulletCDTime <= 0){
- this.bulletCDTime = this.bulletCD;
- Start.inst.createPlayerBullet(this.node.getPosition());
- }
- }
- onRokerMove(dirction: cc.Vec2){
- this.moveCpt.dirction = dirction;
- this.dirction = dirction;
- }
- onRokerEnd(){
- this.moveCpt.dirction = cc.v2(0,0);
- }
- }
|