import { EventMgr } from "../Core/Base/EventMgr"; import Start from "../Start"; import { Touch_Start, Touch_Move, Touch_End } from "./eventDef"; import { Barrage } from "./nest/barrage"; import { GameLogic } from "./update/GameLogic"; import MoveDest from "./update/moveDest"; const {ccclass, property} = cc._decorator; export let PlayerAttack = true; @ccclass export default class Player extends GameLogic { /*===========================自动绑定组件开始===========================*/ /*自动生成*/ @property({type:cc.Node, displayName:""}) private $role_node:cc.Node = null; /*===========================自动绑定组件结束===========================*/ /*===========================自动生成按钮事件开始==========================*/ /*===========================自动生成按钮事件结束==========================*/ moveCpt: MoveDest = null; bulletCD:number = 0.2; bulletCDTime: number = 0; airStartPos: cc.Vec2; static PlayerAttack = true; atkRecord: Map = new Map(); protected onLoad(): void { this.moveCpt = this.node.getComponent(MoveDest); if(!this.moveCpt) { this.moveCpt = this.node.addComponent(MoveDest); } this.moveCpt.speed= 800; this.moveCpt.enabled = false; } protected onEnable(): void { // 跟随手指移动 EventMgr.inst.on(Touch_Start, this.onTouchStart, this); EventMgr.inst.on(Touch_Move, this.onTouchMove, this); EventMgr.inst.on(Touch_End, this.onTouchEnd, this); } protected onDisable(): void { EventMgr.inst.off(Touch_Start, this.onTouchStart, this); EventMgr.inst.off(Touch_Move, this.onTouchMove, this); EventMgr.inst.off(Touch_End, this.onTouchEnd, this); } gameUpdate(dt: number): void { this.bulletCDTime -= dt; if(this.bulletCDTime <= 0){ this.bulletCDTime = this.bulletCD; Player.PlayerAttack && Barrage.inst.createPlayerBullet(this.node.convertToWorldSpaceAR(cc.Vec2.ZERO)); } } onTouchStart(){ this.airStartPos = this.node.getPosition(); this.moveCpt.destination = this.airStartPos; this.moveCpt.enabled = true; } onTouchMove(offset: cc.Vec2){ this.moveCpt.destination = this.airStartPos.add(offset); } onTouchEnd(){ this.moveCpt.enabled = false; } canAtk(key: string){ if(!this.atkRecord.has(key)) return true; if(Date.now() - this.atkRecord.get(key) >= 500){ cc.log('@@ key', key, ' | ',this.atkRecord.get(key)); return true; } return false; } beAtked(key: string){ this.atkRecord.set(key, Date.now()) cc.log('@@ addkey', key, ' | ',this.atkRecord.get(key)); } }