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 { Niu } from "../../monster/niu/Niu"; import { BoxSet } from "../../common/config/BoxSet"; import { Hero } from "../../heros/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){ this.addMonster(smc.monsters[0].name,smc.monsters[0].speed) smc.monsters.splice(0,1) } // if(smc.heros.length>0) { // this.addMonster(smc.heros[0].name,100) // } } private addMonster(name:string = "niu",speed:number = 100) { let monster = null switch (name) { case "niu": monster = ecs.getEntity(Niu); break; case "hero": monster = ecs.getEntity(Monster); break; default: break; } monster.load(v3(BoxSet.RIGHT_END,-60),speed); } private getRandomInt(min: number, max: number): number { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } }