This commit is contained in:
2024-08-09 10:51:47 +08:00
parent 940b951cc7
commit 9fed7e0b03
15 changed files with 676 additions and 41 deletions

View File

@@ -27,10 +27,16 @@ export class MapViewComp extends CCComp {
private timer: Timer = new Timer(3);
onLoad(){
// 监听全局事件
oops.message.on("monster_load", this.onMonsterLoaded, this);
oops.message.on("do_add_monster", this.on_do_add_monster, this);
oops.message.on("do_add_hero", this.on_do_add_hero, this);
}
private onMonsterLoaded(event: string, args: any) {
// console.log('on_monster_load');
private on_do_add_monster(event: string, args: any) {
this.addMonster()
}
private on_do_add_hero(event: string, args: any) {
this.addHero()
this.addMonster()
}
reset(): void {
@@ -44,7 +50,7 @@ export class MapViewComp extends CCComp {
/** 转场 */
protected update(dt: number): void {
this.shuaxin(dt)
// this.shuaxin(dt)
this.gold_add(dt)
}
@@ -65,23 +71,11 @@ export class MapViewComp extends CCComp {
smc.vm_data.shuaxin.min += smc.vm_data.shuaxin.speed*dt;
if (smc.vm_data.shuaxin.min >= smc.vm_data.shuaxin.max) {
smc.vm_data.shuaxin.min = 0;
this.addHero();
}
}
/** 添加玩家 */
private addHero() {
this.scene.node.active = true
if (smc.monsters.length>0){
let monster = ecs.getEntity<Monster>(Monster);
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
let speed =smc.monsters[0].speed
let camp = -1
let prefab_path = smc.monsters[0].prefab_path
let name = smc.monsters[0].name
monster.load(pos,speed,camp,prefab_path,name);
smc.monsters.splice(0,1)
}
if(smc.heros.length>0) {
console.log("heros load")
let hero = ecs.getEntity<Hero>(Hero);
@@ -92,21 +86,23 @@ export class MapViewComp extends CCComp {
let name = smc.heros[0].name
hero.load(pos,speed,camp,prefab_path,name);
smc.heros.splice(0,1)
}
smc.vm_data.hp.min = 100
}
}
private addMonster() {
this.scene.node.active = true
if (smc.monsters.length>0){
let monster = ecs.getEntity<Monster>(Monster);
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
let speed =smc.monsters[0].speed
let camp = -1
let prefab_path = smc.monsters[0].prefab_path
let name = smc.monsters[0].name
monster.load(pos,speed,camp,prefab_path,name);
smc.monsters.splice(0,1)
}
}
private addMonster(name:string = "niu",speed:number = 100) {
}
private getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}