1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 = false;
- 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;
- }
- }
|