123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import HeroHit from "./HeroHit";
- import MonsterBase from "./MonsterBase";
- const {ccclass, property} = cc._decorator;
- @ccclass
- export default class MonsterHit extends cc.Component {
- private enemy: MonsterBase = null;
- public get monster(): MonsterBase
- {
- return this.enemy;
- }
- public get WPos(){
- return this.enemy.WPos;
- }
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.enemy = this.node.parent.getComponent(MonsterBase);
- // // 获取材质
- // if (this.node.getComponent(cc.Sprite)) {
- // this._material = this.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.tickFun,this);
- // }
- // }
- }
- // 碰撞回调
- onCollisionEnter(other:cc.BoxCollider, self:cc.BoxCollider){
- if( self.tag == 2 ) {
-
- if (other.node.group == 'hero' && other.tag == 1) {//受击
- if (other.size.width ==0 || other.size.height ==0 ) { return;}
-
-
- let hero = other.node.getComponent(HeroHit).Hero;
- let enemyHit = other.node.getComponent(MonsterHit);
- let eWPosX = hero.WPos.x;
- let hWposX = this.WPos.x;
-
- this.monster.hurt( eWPosX < hWposX, hero.IsHeavy,false,hero.bigWeaponAtk());
-
-
- }
- }
- }
-
-
- // private _material;
- // private realVal:number = 0;
- // private maxVal:number = 5;
- // private dir:number = 10;
- // private blinkCount:number;
- // private isBlink:boolean = false;
- // public setBlink(isBlink:boolean){
- // this.isBlink = isBlink;
- // if (!this._material) {
- // this.isBlink = false;
- // }
- // if (!this.isBlink) {
- // this._material.setProperty("uSize", 0);
- // }
- // // console.error("设置 setBlink "+isBlink+" "+ this.isBlink)
- // }
- // tickFun(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);
- // }
- protected onDestroy(): void {
- // Ticker.unregister(this.tickFun,this);
- }
- }
|