123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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<string, number> = 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));
- }
- }
|