role 也转为使用hero 预制体

This commit is contained in:
pan@work
2024-09-02 17:15:30 +08:00
parent 83bd06334f
commit 8b9c04eae3
15 changed files with 299 additions and 223 deletions

View File

@@ -15,12 +15,13 @@ export class BoxRangComp extends CCComp {
box_group:number = BoxSet.DEFAULT;
box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 0;
atk_range:number = 150;
/** 视图层逻辑代码分离演示 */
start() {
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
collider.offset = v2(this.offset_x,0);
// collider.offset = v2(this.offset_x,40);
this.Hero_node = this.node.parent;
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
// console.log("range box",this.MonsterViewComp);
@@ -42,9 +43,11 @@ export class BoxRangComp extends CCComp {
// }
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.MonsterViewComp.is_atking = false;
this.MonsterViewComp.enemy = null;
}
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
@@ -53,9 +56,17 @@ export class BoxRangComp extends CCComp {
let other_pos = otherCollider.node.getWorldPosition() ;
let self_pos = this.node.getWorldPosition();
// console.log("onPreSolve:",self_pos,other_pos);
if(Math.abs(other_pos.x-self_pos.x) < BoxSet.ATK_RANGE_X){
if(this.MonsterViewComp.enemy==null){
this.MonsterViewComp.enemy = otherCollider.node;
}else{
if(this.MonsterViewComp.enemy.isValid==false){
this.MonsterViewComp.enemy = otherCollider.node;
}
}
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
this.MonsterViewComp.is_atking = true;
// this.MonsterViewComp.stop_cd = 0.1
this.MonsterViewComp.stop_cd = 0.1
}
}

View File

@@ -37,7 +37,12 @@ export class CSkill extends ecs.Entity {
node.parent = scene.entityLayer!.node!;
node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
// let cskills = ecs.query(ecs.allOf(CSkillComp))
pos = this.add_buff()
if(SkillSet[uuid].type >= 90){
pos = this.add_buff()
}else{
pos = this.add_skill()
}
// console.log("load skill",pos,smc.player_buffs)
node.setPosition(pos.x*scale,pos.y,pos.z)
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
@@ -52,7 +57,7 @@ export class CSkill extends ecs.Entity {
}
add_buff(){
let pos = v3(0,0,0)
for (let index = 0; index < 8; index++) {
for (let index = 0; index < 4; index++) {
if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y
@@ -63,6 +68,18 @@ export class CSkill extends ecs.Entity {
}
return pos
}
add_skill(){
let pos = v3(0,0,0)
for (let index = 4; index < 8; index++) {
if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y
smc.player_buffs[index].eid=this.eid
break
}
}
return pos
}
skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(CSkillComp)
mv.scale = 1;

View File

@@ -98,7 +98,7 @@ export class CSkillComp extends CCComp {
// 94role 临时buff
// 95role 永久buff
let uuid= this.skill_uuid;
let atk:number=smc.Role.RoleView.atk
let atk:number=smc.Role.MonsterView.atk
let args:any = {
atk:atk*GameSet.ATK_TO_ATK_RATIO,
hp:atk*GameSet.ATK_TO_HP_RATIO,

View File

@@ -38,16 +38,12 @@ export class Hero extends ecs.Entity {
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001) {
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
// var path = "game/monster/"+prefab_path;
var path = "game/heros/hero";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!;
// var as = node.getComponent(MonsterSpine);
node.parent=layer
let ratio=this.set_ratio(uuid);
node.setScale(ratio*node.scale.x, ratio*node.scale.y, node.scale.z);
@@ -76,8 +72,8 @@ export class Hero extends ecs.Entity {
ratio=1.3
break;
case 5:
ratio=1.4
break;
ratio=1.4
break;
default:
ratio=1
}

View File

@@ -37,7 +37,9 @@ export class MonsterViewComp extends CCComp {
BoxRang:Node =null!
buff:MonsterBuffComp =null!
is_role:boolean = false;
enemy_pos:Vec3=null!;
enemy:any=null!;
/** 角色动画 */
as: MonsterSpine = null!;
hero_uuid:number = 1001;
@@ -74,7 +76,7 @@ export class MonsterViewComp extends CCComp {
shield_time:number = 0; //护盾持续时间
box_group:number = 2;
atk_range:number = 150;
private timer:Timer = new Timer(0.1); //计时器
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
@@ -87,11 +89,16 @@ export class MonsterViewComp extends CCComp {
} /** 视图层逻辑代码分离演示 */
start () {
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
this.node.getChildByName("top").setScale(this.scale,1);
this.node.getChildByName("top").setScale(this.scale,1);
this.node.getChildByName("atk").setScale(this.scale,1);
this.node.getChildByName("hp_max").setScale(this.scale,1);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis;
this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
// this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis/3;
// console.log("monseter ",this.BoxRang);
this.buff.group=this.box_group
@@ -139,7 +146,6 @@ export class MonsterViewComp extends CCComp {
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){
@@ -188,12 +194,23 @@ export class MonsterViewComp extends CCComp {
// console.log("monster shoot");
let skill = ecs.getEntity<Skill>(Skill);
let x=32
let pos = v3(35*this.scale,40)
let pos = v3(35*this.scale,50)
let scale = this.scale
let speed =smc.skills[skill_uuid].speed;
let dis = smc.skills[skill_uuid].dis;
let atk = smc.skills[skill_uuid].atk+this.atk;
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk);
let angle=0
let t_pos:Vec3 = v3(0,0)
if(this.enemy){
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){
angle = angle +180
}
}else{
t_pos=null
}
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk,angle,t_pos);
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
}
//使用max_skill