98 lines
3.0 KiB
TypeScript
98 lines
3.0 KiB
TypeScript
import { v3, Vec3, _decorator ,Prefab,instantiate} from "cc";
|
|
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { smc } from "../../common/SingletonModuleComp";
|
|
// import { Role } from "../../role/Role";
|
|
import { BoxSet } from "../../common/config/BoxSet";
|
|
import { Hero } from "../../monster/Hero";
|
|
import { Monster } from "../../monster/Monster";
|
|
// import MapRoadUtils from "./map/road/MapRoadUtils";
|
|
import { MapViewScene } from "./MapViewScene";
|
|
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('MapViewComp')
|
|
@ecs.register('MapView', false)
|
|
export class MapViewComp extends CCComp {
|
|
scene: MapViewScene = null!;
|
|
|
|
/** 是否正在转场 */
|
|
|
|
|
|
/** 当前地图数据 */
|
|
current_map: any;
|
|
/** 转场碰撞点对象集合 */
|
|
|
|
private timer: Timer = new Timer(3);
|
|
onLoad(){
|
|
// 监听全局事件
|
|
oops.message.on("monster_load", this.onMonsterLoaded, this);
|
|
}
|
|
private onMonsterLoaded(event: string, args: any) {
|
|
console.log('on_monster_load');
|
|
}
|
|
reset(): void {
|
|
|
|
}
|
|
|
|
start() {
|
|
this.scene = this.getComponent(MapViewScene);
|
|
|
|
}
|
|
|
|
/** 转场 */
|
|
protected update(dt: number): void {
|
|
if (this.timer.update(dt)) {
|
|
// console.log('每2秒触发一次');
|
|
this.addHero();
|
|
}
|
|
}
|
|
|
|
private mapLoaded() {
|
|
|
|
}
|
|
|
|
/** 添加玩家 */
|
|
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);
|
|
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
|
let speed =smc.heros[0].speed
|
|
let camp = 1
|
|
let prefab_path = smc.heros[0].prefab_path
|
|
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(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;
|
|
}
|
|
|
|
}
|