import mainView from "../view/mainView"; import Main from "./Main"; import Monster1 from "./Monster1"; import { MonsterAnima, MonsterFace, MonsterState } from "./MonsterBase"; import Weapon from "./Weapon"; const {ccclass, property} = cc._decorator; @ccclass export default class Monster2 extends Monster1 { // hero状态 @property(cc.Node) weaponAtkPosNode: cc.Node = null; // hero状态 @property(cc.Prefab) weaponPrefab: cc.Prefab = null; /**武器扔出初始位置 */ private weaponAtkLPos = cc.v2(100, 250); private timerId_move; private _walkAnim; protected get walkAnim() { return this._walkAnim; } /**准备扔武器了,不要动 */ private prethrowWeapon:boolean = true; protected init(): void { super.init(); let me = this; this._walkAnim = "walk2"; this.speed = Util.random(100,140); } protected enemyAction(): void { super.enemyAction(); let me = this; // if ( me.prethrowWeapon) { // this.state = MonsterState.none; // } if (me.prethrowWeapon && this.heroDisAbsolut { me._walkAnim = MonsterAnima.walk; me.speed = me.initSpeed; this.state = MonsterState.move; }, 150); } } private throwWeapon(){ this.setAnima("throwWeapon"); let weapon = cc.instantiate(this.weaponPrefab).getComponent(Weapon); let wPos =this.node.convertToWorldSpaceAR(cc.v2(130,120));// this.weaponAtkPosNode.convertToWorldSpaceAR(cc.Vec2.ZERO); weapon.node.parent= this.node.parent; let lPos = weapon.node.parent.convertToNodeSpaceAR(wPos); weapon.node.group = "monsterWeapon"; weapon.node.active = false; weapon.node.active = true; // console.error(lPos); weapon.node.position = cc.v3(lPos.x,lPos.y,0); // return; weapon.MonstThrow(this.monsteFace == MonsterFace.left,this.id); } // /** // * 掉落武器 // */ // private dropWeapon() { // if (Math.random() < 0.3) { // let wPos = this.node.convertToWorldSpaceAR(cc.v2(100, 150)); // // this("掉落武器:" + this.monsteFace + " wPos:" + wPos); // // this.tmp.parent = this.node.parent; // // let lPos = this.tmp.parent.convertToNodeSpaceAR(wPos); // // this.tmp.position = cc.v3(lPos.x,lPos.y,0); // // this.tmp.active = true; // let weapon = cc.instantiate(this.weaponPrefab).getComponent(Weapon); // weapon.node.parent = this.node.parent; // weapon.SetWPos(wPos); // weapon.Drop(); // } // } protected dropWeapon(): void { if (Math.random() < 0.3) { let wPos = this.node.convertToWorldSpaceAR(this.weaponAtkLPos); let weapon = cc.instantiate(this.weaponPrefab).getComponent(Weapon); weapon.node.parent = this.node.parent; // weapon.SetWPos(wPos); weapon.Drop(wPos); } } protected moveInScreen(): void { super.moveInScreen(); if (this.state == MonsterState.dead || this.state == MonsterState.win) { return; } // console.error("出现在屏幕中了"); let me = this; Ticker.registerDelay(() => { // me.startThrowWeapon(); // this.state = MonsterState.none; // me.prethrowWeapon = true; // me.dirX = 0; // me.setSpeed(); // me.throwWeapon(); // this.timerId_move = Ticker.registerDelay(() => { // me._walkAnim = MonsterAnima.walk; // me.prethrowWeapon = false; // me.speed = me.initSpeed; // this.state = MonsterState.move; // }, 100); }, 800); } // protected onHurtDie(): void { // super.onHurtDie(); // Ticker.unregisterDelay(this.timerId_move); // } protected onHurt(hurtLeft:boolean, isHeavy:boolean, weaponHurt:boolean,mustKill:boolean) { Ticker.unregisterDelay(this.timerId_move); super.onHurt(hurtLeft,isHeavy,weaponHurt,mustKill); if (!this.prethrowWeapon) { this.speed = this.initSpeed; } // if (this.hp>0) { // this.state = MonsterState.move; // } } }