添加2个游戏层,敌方精灵随机出现在3个层内

This commit is contained in:
2024-08-22 22:59:43 +08:00
parent 6e9faca1a3
commit 2917c12f14
65 changed files with 394 additions and 2540 deletions

View File

@@ -26,13 +26,13 @@ const { ccclass, property } = _decorator;
@ccclass('MonsterViewComp') // 定义为 Cocos Creator 组件
@ecs.register('MonsterView', false) // 定义为 ECS 组件
export class MonsterViewComp extends CCComp {
@property(Material)
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
@property(BoxRangComp)
BoxRang:BoxRangComp = null!;
@property(Node)
BoxRang:Node =null!
/** 角色动画 */
as: MonsterSpine = null!;
hero_uuid:number = 1001;
@@ -76,21 +76,25 @@ export class MonsterViewComp extends CCComp {
onLoad() {
this.as = this.getComponent(MonsterSpine);
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
// EPhysics2DDrawFlags.Pair |
// EPhysics2DDrawFlags.CenterOfMass |
// EPhysics2DDrawFlags.Joint |
// EPhysics2DDrawFlags.Shape;
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
// | EPhysics2DDrawFlags.Pair
// |EPhysics2DDrawFlags.CenterOfMass
// |EPhysics2DDrawFlags.Joint
// |EPhysics2DDrawFlags.Shape;
} /** 视图层逻辑代码分离演示 */
start () {
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
this.BoxRang = this.node.getChildByName("range_box");
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*SkillSet[this.skill_uuid].dis-30;
// console.log("monseter ",this.BoxRang);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
this.BoxRang.box_group = this.box_group;
// console.log(collider);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
@@ -102,9 +106,10 @@ export class MonsterViewComp extends CCComp {
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
if(selfCollider.group != otherCollider.group){
let skill = otherCollider.node.getComponent(SkillCom)!;
@@ -135,17 +140,19 @@ export class MonsterViewComp extends CCComp {
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
if(selfCollider.group == BoxSet.HERO){
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
this.stop_cd=0.1
}
}
if(selfCollider.group == BoxSet.MONSTER){
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
this.stop_cd=0.1
}
}
}
}else{
// console.log('monster onPostSolve'+selfCollider.group+"|"+otherCollider.group);
}
@@ -172,15 +179,6 @@ export class MonsterViewComp extends CCComp {
this.in_destroy();
this.in_stop(dt);
this.in_act(dt);
switch (this.type) {
case 1:
this.as.walk();
break;
case 2:
this.as.idle();
break;
}
this.move(dt);
// this.update_pos();
@@ -213,7 +211,7 @@ export class MonsterViewComp extends CCComp {
this.node.getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
}
shoot(skill_uuid:number){
console.log("monster shoot");
// console.log("monster shoot");
let skill = ecs.getEntity<Skill>(Skill);
let x=0
let pos = v3(x,40)