123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- import EventMgr from "./EventMgr";
- import { GameEvent } from "./GameEvent";
- import { GameState } from "./GameState";
- import { GameInput } from "./Hero";
- 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 WolfRush extends Monster1 {
- // hero状态
- @property(cc.Node)
- weaponAtkPosNode: cc.Node = null;
-
- // hero状态
- @property(cc.Prefab)
- weaponPrefab: cc.Prefab = null;
- private rushSpeed: number = 400;
- /**漫游 速度 */
- private wanderSpeed: number = 100;
- private isRushState: boolean = true;
- private timer_itv_wander: string;
- private timer_to_rush: string;
- private _walkAnim;
- protected get walkAnim() {
- return this._walkAnim;
- }
- protected init(): void {
- super.init();
- let me = this;
- this._walkAnim = MonsterAnima.walk;
- // this.speed = Util.random(100,140);
- // Ticker.registerDelay(() => {
- me._walkAnim = "rush";// MonsterAnima.walk;
- me.speed = me.rushSpeed;// me.initSpeed;
- this.state = MonsterState.move;
- // me.rushCheck();
-
- Main.Ins.guideLog("rush-init");
- // if (Main.Ins.IsGuide) {
- // EventMgr.Instance.add_event_listenner(GameEvent.GuideStepEnd, this, this.OnGuideStepEnd);
- // }
- // }, 800);
- }
- protected start(): void {
- this.initColor();
- }
- // OnGuideStepEnd(GuideStepEnd: GameEvent, guide) {
- // if (guide == 4) {
- // this.repuseMove();
- // }
- // }
- protected updateAction(dt):void{
- if (this.isRushState) //冲锋状态
- {
- if ( Main.Ins.TryGuideStep(4) && Main.Ins.GuideSteping!=4) {
- if (this.heroDisAbsolut <240) {
- Main.Ins.BallonGuide.showTop(true,"跳跃躲避攻击");
- Main.Ins.SetGuideIptPermit(GameInput.up);
- EventMgr.Instance.dispatch_event(GameEvent.GuideStepWolfStop,true);
- // this.stopMove();
- // Main.Ins.pauseGame();
- // Main.Ins.guideView.show("跳跃或蹲下躲避攻击");
- }
- }
- }else{//普通状态
- super.updateAction(dt);
- }
- }
- protected onHurtSpeed(): void {
- if (!this.isRushState) {
-
- super.onHurtSpeed();
- }
- }
- protected onHurtStillLive(isHeavy: any, weaponHurt: any): void {
- if (this.isRushState) {
- if (weaponHurt) {
- this.changeToNormal();
- super.onHurtStillLive(true, weaponHurt);
- }
- } else {
- super.onHurtStillLive(isHeavy, weaponHurt);
- }
- }
- changeToNormal(){
- this.isRushState = false;
- this.speed = this.initSpeed;
- // /**击退*/
- this._walkAnim = MonsterAnima.walk;
-
- this.setBlink(false);
- }
- protected dropWeapon(): void {
- // if (Math.random() < 0.3) {
- if (this.isRushState) {
- let wPos = this.DropWPos;// this.node.convertToWorldSpaceAR(cc.v2(100, 150));
- let weapon = cc.instantiate(this.weaponPrefab).getComponent(Weapon);
- weapon.node.parent = this.node.parent;
- weapon.Drop(wPos);
- }
- }
- private get DropWPos(){
- return this.node.convertToWorldSpaceAR(cc.v2(100, 150));
- }
- onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider) {
- super.onBeginContact(contact, selfCollider, otherCollider);
- if (this.isRushState) {
- if (otherCollider.node.group == 'board') {
- Main.Ins.guideLog("rush-board");
- if (this.rushRound >= 1) {
- if (Main.Ins.IsGuide) {
- Main.Ins.SetGuideIptPermit();
- Main.Ins.GuideStepEnd(4);
- Main.Ins.Guide5();
- this.node.destroy();
- } else {
- this.changeToNormal();
- }
- } else {
- this.rushCheck();
- }
- }
- }
- }
- private rushRound: number = 0;
- rushCheck() {
- let me = this;
- if (Main.Ins.State == GameState.win || Main.Ins.State == GameState.fail) { return; }
- // if (me.dirX == 0) { return; }
- let monsteFace = this.heroDist > 0 ? MonsterFace.right : MonsterFace.left;
- me.monsteFace = monsteFace;
- me.faceHero();
- me.dirX = 0;
- me.setSpeed();
- Ticker.unregisterDelay(me.timer_to_rush);
- me.timer_to_rush = Ticker.registerDelay(() => {
- if (me.monsteFace == MonsterFace.left) {
- // <--
- me.dirX = -1;
- } else {
- me.dirX = 1;
- }
- me.rushRound++;
- me.setSpeed(me.rushSpeed);
- }, 500);
- }
- OnHeroDie() {
- // super.OnHeroDie();
- //开始漫步
- let me = this;
- // this.faceHero
- this.setAnima(MonsterAnima.walk);
- Ticker.unregisterDelay(me.timer_to_rush);
- let wanderFun = function () {
- me.dirX = me.dirX < 0 ? 1 : -1;
- let scaleX = Math.abs(me.node.scaleX)
- if (me.dirX < 0) {
- me.node.scaleX = -scaleX
- } else {
- me.node.scaleX = scaleX
- }
- me.setSpeed(me.wanderSpeed);
- }
- wanderFun();
- me.timer_itv_wander = Ticker.registerDelay(() => {
- wanderFun();
- }, Util.random(1000,3000),0);
- }
- private _material;
- private realVal:number = 0;
- private maxVal:number = 5;
- private dir:number = 10;
- private isBlink:boolean = false;
- private initColor(){
- // 获取材质
- if (this.hitCom.node.getComponent(cc.Sprite)) {
- this._material = this.hitCom.node.getComponent(cc.Sprite).getMaterial(0);
- if (this._material) {
- // 设置材质对应的属性
- this._material.setProperty("uSize", this.realVal);
- this._material.setProperty("uGlowColor", cc.color(255,208,75));
- Ticker.register(this.blinkTickFun,this);
- this.setBlink(true);
- }
- }
- }
-
- blinkTickFun(dt) {
- if (!this.isBlink) {return;}
- this.realVal+=dt * this.dir;
- if (this.realVal >= this.maxVal || this.realVal <= 0) {
- this.dir = -this.dir;
- // if (this.blinkCount-- <= 0) {
- // this.realVal = 0;
- // this.isBlink = false;
- // }
- }
- this._material.setProperty("uSize", this.realVal);
- }
- private setBlink(isBlink:boolean){
- this.isBlink = isBlink;
- if (!this._material) {
- this.isBlink = false;
- }
- // console.error(this._material)
- if (!this.isBlink) {
- this._material.setProperty("uSize", 0);
- }
- // console.error("设置 setBlink "+isBlink+" "+ this.isBlink)
- }
- onDestroy(){
- super.onDestroy();
- Ticker.unregisterDelay(this.timer_itv_wander);
- Ticker.unregisterDelay(this.timer_to_rush);
-
- Ticker.unregister(this.blinkTickFun,this);
-
- // EventMgr.Instance.remove_event_listenner(GameEvent.GuideStepEnd, this, this.OnGuideStepEnd);
- super.onDestroy();
- }
- }
|