dd
This commit is contained in:
@@ -24,16 +24,16 @@ export class Main extends Root {
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
smc.monsters = [
|
||||
{prefab_path:'niu',name:'m1',speed:40},
|
||||
{prefab_path:'niu',name:'m2',speed:80},
|
||||
{prefab_path:'niu',name:'m3',speed:40},
|
||||
{prefab_path:'niu',name:'m4',speed:80},
|
||||
{prefab_path:'niu',name:'m1',speed:110},
|
||||
// {prefab_path:'niu',name:'m2',speed:80},
|
||||
// {prefab_path:'niu',name:'m3',speed:40},
|
||||
// {prefab_path:'niu',name:'m4',speed:80},
|
||||
]
|
||||
smc.heros = [
|
||||
{prefab_path:'niu',name:'war',speed:60},
|
||||
{prefab_path:'niu',name:'magic',speed:60},
|
||||
{prefab_path:'niu',name:'heath',speed:60},
|
||||
{prefab_path:'niu',name:'war',speed:60},
|
||||
{prefab_path:'niu',name:'war',speed:110},
|
||||
// {prefab_path:'niu',name:'magic',speed:60},
|
||||
// {prefab_path:'niu',name:'heath',speed:60},
|
||||
// {prefab_path:'niu',name:'war',speed:60},
|
||||
]
|
||||
console.log("Game start");
|
||||
}
|
||||
|
||||
@@ -47,12 +47,11 @@ export class Monster extends ecs.Entity {
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
var mv = node.getComponent(MonsterViewComp)!;
|
||||
console.log('speed:'+speed)
|
||||
mv.speed =mv.ospeed = speed;
|
||||
mv.hero_name= name;
|
||||
mv.camp = camp;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
mv.change_name(name)
|
||||
mv.change_name(name,camp)
|
||||
this.add(mv);
|
||||
if(camp == 1){
|
||||
smc.heros_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0})
|
||||
|
||||
@@ -23,9 +23,15 @@ export class MonsterViewComp extends CCComp {
|
||||
/** 角色动画 */
|
||||
as: MonsterSpine = null!;
|
||||
hero_name : string = "hero";
|
||||
/** 角色阵营 1:hero -1 :monster */
|
||||
camp: number = 1;
|
||||
/**角色类型 1:近战 2 远程 */
|
||||
type: number = 1;
|
||||
/** 角色移动速度 */
|
||||
speed: number = 100;
|
||||
/** 角色初始速度 */
|
||||
ospeed: number = 100;
|
||||
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
timer: number = 0;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
@@ -42,12 +48,33 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
// 只在两个碰撞体开始接触时被调用一次
|
||||
// console.log('onBeginContact otherCollider.tag :',otherCollider,selfCollider);
|
||||
if ( otherCollider.tag == BoxSet.HERO && selfCollider.tag == BoxSet.MONSTER) {
|
||||
this.speed = 0
|
||||
this.timer = 0.5
|
||||
switch (selfCollider.tag) {
|
||||
case BoxSet.MONSTER:
|
||||
switch (otherCollider.tag){
|
||||
case BoxSet.HERO:
|
||||
console.log("im monster other is hero");
|
||||
this.speed = 0;
|
||||
this.timer = 1;
|
||||
console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.HERO:
|
||||
switch (otherCollider.tag){
|
||||
case BoxSet.MONSTER:
|
||||
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// 只在两个碰撞体结束接触时被调用一次
|
||||
@@ -69,30 +96,45 @@ export class MonsterViewComp extends CCComp {
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
|
||||
console.log('hero load ent:',this);
|
||||
// console.log('hero load ent:',this);
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
EPhysics2DDrawFlags.Pair |
|
||||
EPhysics2DDrawFlags.CenterOfMass |
|
||||
EPhysics2DDrawFlags.Joint |
|
||||
EPhysics2DDrawFlags.Shape;
|
||||
}
|
||||
change_name(hero_name:string){
|
||||
change_name(hero_name:string='hero',camp:number=1){
|
||||
this.name=hero_name;
|
||||
let label:any =this.node.getChildByName("top").getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = hero_name;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if(camp==1){
|
||||
collider.tag=BoxSet.HERO;
|
||||
}else{
|
||||
collider.tag=BoxSet.MONSTER;
|
||||
}
|
||||
|
||||
}
|
||||
update(dt: number){
|
||||
if(this.timer > 0){
|
||||
this.timer -= dt;
|
||||
if(this.timer <= 0){
|
||||
this.speed = this.ospeed;
|
||||
console.log("speed:"+this.speed);
|
||||
this.timer = 0;
|
||||
}
|
||||
}
|
||||
switch (this.type) {
|
||||
case 1:
|
||||
this.as.walk();
|
||||
break;
|
||||
case 2:
|
||||
this.as.idle();
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.camp == -1){
|
||||
if(this.node.position.x < BoxSet.LETF_END){
|
||||
console.log(this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.node.destroy();
|
||||
}else{
|
||||
this.move(dt);
|
||||
@@ -100,9 +142,7 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
if(this.camp == 1){
|
||||
if(this.node.position.x > BoxSet.RIGHT_END){
|
||||
console.log(this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.node.destroy();
|
||||
this.reset();
|
||||
}else{
|
||||
this.move(dt);
|
||||
}
|
||||
@@ -125,6 +165,9 @@ export class MonsterViewComp extends CCComp {
|
||||
// console.log('smc.monsters_in',smc.monsters_in);
|
||||
}
|
||||
reset() {
|
||||
console.log("node destroy:",this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user