Files
heros/assets/script/game/map/view/MapViewComp.ts
2024-07-29 17:04:03 +08:00

82 lines
2.4 KiB
TypeScript

import { v3, Vec3, _decorator } 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 { Monster } from "../../monster/Monster";
import { Hero } from "../../heros/Hero";
// 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(2);
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
// smc.monsters = ['war','magic','heath']
// smc.heros = ['war','magic','heath']
if (smc.heros.length>0){
let hero = ecs.getEntity<Hero>(Hero);
hero.load(v3(-360,-60), smc.heros[0].profession);
}
if (smc.monsters.length>0){
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)
}
}
private getRandomInt(min: number, max: number): number {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
}