This commit is contained in:
2024-07-30 08:34:41 +08:00
parent fe09fb1f5f
commit 76b400885c
11 changed files with 43 additions and 28 deletions

View File

@@ -812,7 +812,7 @@
"bullet": true, "bullet": true,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 4, "_group": 4,
"_type": 2, "_type": 1,
"_allowSleep": false, "_allowSleep": false,
"_gravityScale": 0, "_gravityScale": 0,
"_linearDamping": 0, "_linearDamping": 0,

View File

@@ -812,7 +812,7 @@
"bullet": true, "bullet": true,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 4, "_group": 4,
"_type": 2, "_type": 1,
"_allowSleep": false, "_allowSleep": false,
"_gravityScale": 0, "_gravityScale": 0,
"_linearDamping": 0, "_linearDamping": 0,

View File

@@ -843,10 +843,10 @@
"__id__": 41 "__id__": 41
}, },
"enabledContactListener": true, "enabledContactListener": true,
"bullet": false, "bullet": true,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 4, "_group": 4,
"_type": 2, "_type": 1,
"_allowSleep": false, "_allowSleep": false,
"_gravityScale": 0, "_gravityScale": 0,
"_linearDamping": 0, "_linearDamping": 0,

View File

@@ -843,10 +843,10 @@
"__id__": 41 "__id__": 41
}, },
"enabledContactListener": true, "enabledContactListener": true,
"bullet": false, "bullet": true,
"awakeOnLoad": true, "awakeOnLoad": true,
"_group": 2, "_group": 2,
"_type": 2, "_type": 1,
"_allowSleep": false, "_allowSleep": false,
"_gravityScale": 0, "_gravityScale": 0,
"_linearDamping": 0, "_linearDamping": 0,

View File

@@ -25,9 +25,9 @@ export class Main extends Root {
smc.initialize = ecs.getEntity<Initialize>(Initialize); smc.initialize = ecs.getEntity<Initialize>(Initialize);
smc.monsters = [ smc.monsters = [
{profession:'m1',speed:50}, {profession:'m1',speed:50},
{profession:'m2',speed:50}, {profession:'m2',speed:60},
{profession:'m3',speed:50}, {profession:'m3',speed:70},
{profession:'m4',speed:50}, {profession:'m4',speed:80},
] ]
smc.heros = [ smc.heros = [
{profession:'war',speed:50}, {profession:'war',speed:50},

View File

@@ -12,4 +12,6 @@ export enum BoxSet {
HERO = 4, HERO = 4,
MONSTER_SKILL = 8, MONSTER_SKILL = 8,
HERO_SKILL = 16, HERO_SKILL = 16,
BOX_WIDTH = 64,
BOX_HEIGHT = 64
} }

View File

@@ -50,7 +50,7 @@ export class Hero extends ecs.Entity {
this.add(mv); this.add(mv);
//移除全局列表 //移除全局列表
smc.heros.splice(0,1)
// console.log(ecs.query(ecs.allOf(HeroViewComp))) // console.log(ecs.query(ecs.allOf(HeroViewComp)))
} }

View File

@@ -43,10 +43,10 @@ export class HeroViewComp extends CCComp {
// console.log('hero Contact,selfCollider',selfCollider); // console.log('hero Contact,selfCollider',selfCollider);
switch (otherCollider.group) { switch (otherCollider.group) {
case BoxSet.MONSTER: case BoxSet.MONSTER:
console.log('hero coolider MONSTER '); // console.log('hero coolider MONSTER ');
break; break;
case BoxSet.MONSTER_SKILL: case BoxSet.MONSTER_SKILL:
console.log('hero coolider MONSTER skill'); // console.log('hero coolider MONSTER skill');
break; break;
default: default:
break; break;

View File

@@ -1,4 +1,4 @@
import { v3, Vec3, _decorator } from "cc"; import { v3, Vec3, _decorator ,Prefab,instantiate} from "cc";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { smc } from "../../common/SingletonModuleComp"; import { smc } from "../../common/SingletonModuleComp";
@@ -56,19 +56,25 @@ export class MapViewComp extends CCComp {
private addHero() { private addHero() {
this.scene.node.active = true this.scene.node.active = true
// smc.monsters = ['war','magic','heath']
// smc.heros = ['war','magic','heath']
if (smc.heros.length>0){ if (smc.heros.length>0){
let hero = ecs.getEntity<Hero>(Hero); let hero = ecs.getEntity<Hero>(Hero);
hero.load(v3(-360,-60), smc.heros[0].profession); hero.load(v3(-360,-60), smc.heros[0].profession);
smc.heros.splice(0,1)
} }
if (smc.monsters.length>0){ if (smc.monsters.length>0){
let monster = ecs.getEntity<Monster>(Monster); var path = "game/monster/monster";
monster.load(v3(360,-60),smc.monsters[0].speed); var prefab: Prefab = oops.res.get(path, Prefab)!;
monster.move(v3(0,-60)); var node = instantiate(prefab);
smc.monsters.splice(0,1) var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!;
node.setPosition(v3(360,-60))
this.node.addChild(node);
// let monster = ecs.getEntity<Monster>(Monster);
// monster.load(v3(360,-60),smc.monsters[0].speed);
// monster.move(v3(0,-60));
// smc.monsters.splice(0,1)
} }
} }

View File

@@ -47,8 +47,9 @@ export class Monster extends ecs.Entity {
var mv = node.getComponent(MonsterViewComp)!; var mv = node.getComponent(MonsterViewComp)!;
mv.speed = speed; mv.speed = speed;
mv.ospeed = speed;
mv.Tpos = v3(0,0,0); mv.Tpos = v3(0,0,0);
this.add(mv); // this.add(mv);
smc.monsters_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}), smc.monsters_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}),
// node.setScale(-1, 1, 1); // node.setScale(-1, 1, 1);
oops.message.dispatchEvent("monster_load",this) oops.message.dispatchEvent("monster_load",this)

View File

@@ -23,7 +23,9 @@ export class MonsterViewComp extends CCComp {
/** 角色动画 */ /** 角色动画 */
as: MonsterSpine = null!; as: MonsterSpine = null!;
speed: number = 100; speed: number = 100;
ospeed: number = 100;
Tpos: Vec3 = v3(0,-60,0); Tpos: Vec3 = v3(0,-60,0);
timer: number = 0;
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start () { start () {
// 注册单个碰撞体的回调函数 // 注册单个碰撞体的回调函数
@@ -43,13 +45,11 @@ export class MonsterViewComp extends CCComp {
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次 // 只在两个碰撞体开始接触时被调用一次
// console.log('monster Contact,otherCollider',otherCollider); // console.log('monster Contact,otherCollider',otherCollider);
this.speed = 0;
this.timer = 1;
switch (otherCollider.group) { switch (otherCollider.group) {
case BoxSet.HERO:
console.log('monster coolider hero');
break;
case BoxSet.HERO_SKILL: case BoxSet.HERO_SKILL:
console.log('monster coolider hero skill'); // console.log('monster coolider hero skill');
break; break;
default: default:
break; break;
@@ -58,11 +58,17 @@ export class MonsterViewComp extends CCComp {
onLoad() { onLoad() {
this.as = this.getComponent(MonsterSpine); this.as = this.getComponent(MonsterSpine);
console.log('this.ospeed:',this);
} }
update(dt: number){ update(dt: number){
if(this.timer > 0){
this.timer -= dt;
if(this.timer <= 0){
this.speed = this.ospeed;
this.timer = 0;
}
}
if(this.node.position.x > -360){ if(this.node.position.x > -360){
this.move(dt); this.move(dt);
} }