123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- 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<cc.view.getVisibleSize().width*0.5-150)//扔武器
- {
- me.prethrowWeapon = false;
- this.state = MonsterState.none;
- me.dirX = 0;
- me.setSpeed();
- me.throwWeapon();
- this.timerId_move = Ticker.registerDelay(() => {
- 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;
- // }
- }
- }
|