dd
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
import { MonsterSpine } from "./MonsterSpine";
|
||||
@@ -19,9 +19,10 @@ import { Skill } from "../skills/Skill";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { SkillCom } from "../skills/SkillCom";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { BoxRangComp } from "./BoxRangComp";
|
||||
import { Tooltip } from "../skills/Tooltip";
|
||||
import { MonsterBuffComp } from "./MonsterBuffComp";
|
||||
import { MoveToComp } from "../common/ecs/position/MoveTo";
|
||||
import { BoxRangComp } from "./BoxRangComp";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -78,6 +79,7 @@ export class MonsterViewComp extends CCComp {
|
||||
box_group:number = 2;
|
||||
atk_range:number = 150;
|
||||
private timer:Timer = new Timer(1); //计时器
|
||||
private m_timer:Timer = new Timer(0.1);
|
||||
is_dead:boolean = false; //是否摧毁
|
||||
is_stop:boolean = false;
|
||||
is_atking:boolean = false;
|
||||
@@ -85,24 +87,26 @@ export class MonsterViewComp extends CCComp {
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
this.buff=this.node.getComponent(MonsterBuffComp);
|
||||
this.BoxRang = this.node.getChildByName("range_box");
|
||||
// this.BoxRang = this.node.getChildByName("range_box");
|
||||
// this.BoxRang = this.node.getChildByName("range_box");
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
this.node.getChildByName("top").setScale(this.scale,1);
|
||||
this.node.getChildByName("atk").setScale(this.scale,1);
|
||||
this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
|
||||
this.node.getChildByName("hp_max").setScale(this.scale,1);
|
||||
this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
|
||||
|
||||
this.node.getChildByName("top").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
|
||||
// this.node.getChildByName("hp_max").setScale(this.scale,1);
|
||||
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
|
||||
// this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis/3;
|
||||
// this.BoxRang.getComponent(BoxRangComp).offset_x = 300;
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
// if(this.box_group == BoxSet.MONSTER){
|
||||
// this.enemy=smc.Role.RoleView.node
|
||||
// // console.log("monster enemy ",this.enemy);
|
||||
// }
|
||||
this.buff.group=this.box_group
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
@@ -118,6 +122,7 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
@@ -132,11 +137,11 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
|
||||
this.is_atking = true;
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
|
||||
@@ -146,12 +151,12 @@ export class MonsterViewComp extends CCComp {
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.HERO:
|
||||
if(self_pos.x < other_pos.x){
|
||||
this.stop_cd=0.1
|
||||
// this.stop_cd=0.1
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER:
|
||||
if(self_pos.x > other_pos.x){
|
||||
this.stop_cd=0.1
|
||||
// this.stop_cd=0.1
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -168,7 +173,9 @@ export class MonsterViewComp extends CCComp {
|
||||
this.in_stop(dt);
|
||||
this.in_act(dt);
|
||||
this.move(dt);
|
||||
|
||||
// if(this.m_timer.update(dt)){
|
||||
// this.move_to()
|
||||
// }
|
||||
}
|
||||
|
||||
move(dt: number){
|
||||
@@ -178,8 +185,52 @@ export class MonsterViewComp extends CCComp {
|
||||
if (this.scale === 1 && this.node.position.x >= 120) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.scale===-1&&this.node.position.x <= BoxSet.HERO_START){
|
||||
return;
|
||||
}
|
||||
// if(this.enemy){
|
||||
// return
|
||||
// }
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
move_to(){
|
||||
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
move.target = v3(smc.Role.RoleView.node.position.x+10,smc.Role.RoleView.node.position.y);
|
||||
move.node = this.node;
|
||||
move.speed = this.ospeed;
|
||||
|
||||
// if(this.box_group == BoxSet.MONSTER){
|
||||
// if(smc.t_hero.eid != 0){
|
||||
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
// if(smc.t_hero.pos.x < this.node.position.x){
|
||||
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
|
||||
// move.target = v3(smc.t_hero.pos.x+20,smc.t_hero.pos.y);
|
||||
// }else{
|
||||
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
|
||||
// move.target = v3(smc.t_hero.pos.x-20,smc.t_hero.pos.y);
|
||||
// }
|
||||
// move.node = this.node;
|
||||
// move.speed = this.ospeed;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(this.box_group == BoxSet.HERO){
|
||||
// if(smc.t_monster.eid != 0){
|
||||
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
|
||||
// if(smc.t_monster.pos.x < this.node.position.x){
|
||||
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
|
||||
// move.target = v3(smc.t_monster.pos.x+20,smc.t_monster.pos.y);
|
||||
// }else{
|
||||
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
|
||||
// move.target = v3(smc.t_monster.pos.x-20,smc.t_monster.pos.y);
|
||||
// }
|
||||
// move.node = this.node;
|
||||
// move.speed = this.ospeed;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max){
|
||||
@@ -204,6 +255,10 @@ export class MonsterViewComp extends CCComp {
|
||||
let angle=0
|
||||
let t_pos:Vec3 = v3(0,0)
|
||||
if(this.enemy){
|
||||
if(!this.enemy.isValid){
|
||||
console.log("move_to",this.enemy.isValid);
|
||||
return
|
||||
}
|
||||
t_pos = v3(this.enemy.position.x-this.node.position.x,this.enemy.position.y-this.node.position.y)
|
||||
angle = Math.atan2(t_pos.y,t_pos.x) * 180 / Math.PI;
|
||||
if(this.scale == -1){
|
||||
@@ -269,12 +324,21 @@ export class MonsterViewComp extends CCComp {
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp <= 0){
|
||||
this.dead();
|
||||
this.remove_smc_data()
|
||||
this.is_dead = true;
|
||||
setTimeout(() => {
|
||||
this.ent.destroy();
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
remove_smc_data(){
|
||||
if(smc.t_monster.eid == this.ent.eid){
|
||||
smc.t_monster = {eid:0,pos:v3(0,0,0)}
|
||||
}
|
||||
if(smc.t_hero.eid == this.ent.eid){
|
||||
smc.t_hero = {eid:0,pos:v3(0,0,0)}
|
||||
}
|
||||
}
|
||||
add_hp(hp: number=0){
|
||||
console.log("hero 加血动画");
|
||||
this.tooltip(2,hp.toString());
|
||||
@@ -335,7 +399,7 @@ export class MonsterViewComp extends CCComp {
|
||||
let pos = v3(0,60)
|
||||
node.setPosition(pos)
|
||||
node.parent = this.node;
|
||||
|
||||
|
||||
}else{
|
||||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
|
||||
Reference in New Issue
Block a user