MonsterHit.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import HeroHit from "./HeroHit";
  2. import MonsterBase from "./MonsterBase";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class MonsterHit extends cc.Component {
  6. private enemy: MonsterBase = null;
  7. public get monster(): MonsterBase
  8. {
  9. return this.enemy;
  10. }
  11. public get WPos(){
  12. return this.enemy.WPos;
  13. }
  14. // LIFE-CYCLE CALLBACKS:
  15. onLoad() {
  16. this.enemy = this.node.parent.getComponent(MonsterBase);
  17. // // 获取材质
  18. // if (this.node.getComponent(cc.Sprite)) {
  19. // this._material = this.node.getComponent(cc.Sprite).getMaterial(0);
  20. // if (this._material) {
  21. // // 设置材质对应的属性
  22. // this._material.setProperty("uSize", this.realVal);
  23. // this._material.setProperty("uGlowColor", cc.color(255,208,75));
  24. // Ticker.register(this.tickFun,this);
  25. // }
  26. // }
  27. }
  28. // 碰撞回调
  29. onCollisionEnter(other:cc.BoxCollider, self:cc.BoxCollider){
  30. if( self.tag == 2 ) {
  31. if (other.node.group == 'hero' && other.tag == 1) {//受击
  32. if (other.size.width ==0 || other.size.height ==0 ) { return;}
  33. let hero = other.node.getComponent(HeroHit).Hero;
  34. let enemyHit = other.node.getComponent(MonsterHit);
  35. let eWPosX = hero.WPos.x;
  36. let hWposX = this.WPos.x;
  37. this.monster.hurt( eWPosX < hWposX, hero.IsHeavy,false,hero.bigWeaponAtk());
  38. }
  39. }
  40. }
  41. // private _material;
  42. // private realVal:number = 0;
  43. // private maxVal:number = 5;
  44. // private dir:number = 10;
  45. // private blinkCount:number;
  46. // private isBlink:boolean = false;
  47. // public setBlink(isBlink:boolean){
  48. // this.isBlink = isBlink;
  49. // if (!this._material) {
  50. // this.isBlink = false;
  51. // }
  52. // if (!this.isBlink) {
  53. // this._material.setProperty("uSize", 0);
  54. // }
  55. // // console.error("设置 setBlink "+isBlink+" "+ this.isBlink)
  56. // }
  57. // tickFun(dt) {
  58. // if (!this.isBlink) {return;}
  59. // this.realVal+=dt * this.dir;
  60. // if (this.realVal >= this.maxVal || this.realVal <= 0) {
  61. // this.dir = -this.dir;
  62. // // if (this.blinkCount-- <= 0) {
  63. // // this.realVal = 0;
  64. // // this.isBlink = false;
  65. // // }
  66. // }
  67. // this._material.setProperty("uSize", this.realVal);
  68. // }
  69. protected onDestroy(): void {
  70. // Ticker.unregister(this.tickFun,this);
  71. }
  72. }