114 lines
3.7 KiB
TypeScript
114 lines
3.7 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 MapRoadUtils from "./map/road/MapRoadUtils";
|
|
import { MapViewScene } from "./MapViewScene";
|
|
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
|
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);
|
|
|
|
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(pos?: Vec3) {
|
|
|
|
this.scene.node.active = true
|
|
// smc.monsters = ['war','magic','heath']
|
|
// smc.heros = ['war','magic','heath']
|
|
// if (smc.heros.length>0){
|
|
// let hero = ecs.getEntity<Role>(Role);
|
|
// let x = this.getRandomInt(-300, 0)
|
|
// hero.load(this.aStarToVec3(x+',60'), false, "magic");
|
|
// }
|
|
if (smc.monsters.length>0){
|
|
let monster = ecs.getEntity<Monster>(Monster);
|
|
let x = this.getRandomInt(-100, 100)
|
|
monster.load(this.aStarToVec3(x+',-60'));
|
|
}
|
|
|
|
// smc.own.loadJoystick();
|
|
// smc.heros.forEach(element => {
|
|
// var heros$i = ecs.getEntity<Role>(Role);
|
|
// let i =1
|
|
// switch (element) {
|
|
// case "war":
|
|
// heros$i.load(this.aStarToVec3("-30,-60"), false);
|
|
// break;
|
|
// case "magic":
|
|
// heros$i.load(this.aStarToVec3("-140,-60"), false);
|
|
// break;
|
|
// case "heath":
|
|
// heros$i.load(this.aStarToVec3("-230,-60"), false)
|
|
// }
|
|
// i=i+1
|
|
// });
|
|
// let x = 1
|
|
// smc.monsters.forEach(element => {
|
|
// var monsters$x = ecs.getEntity<Role>(Role);
|
|
// switch (element) {
|
|
// case "war":
|
|
// monsters$x.load(this.aStarToVec3("30,-60"), true);
|
|
// break;
|
|
// case "magic":
|
|
// monsters$x.load(this.aStarToVec3("140,-60"), true);
|
|
// break;
|
|
// case "heath":
|
|
// monsters$x.load(this.aStarToVec3("230,-60"), true)
|
|
// }
|
|
// x=x+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;
|
|
}
|
|
private aStarToVec3(str: string) {
|
|
let array = str.split(",");
|
|
let x = parseInt(array[0]);
|
|
let y = parseInt(array[1]);
|
|
// let p = MapRoadUtils.instance.getPixelByDerect(x, y);
|
|
return v3(x, y);
|
|
}
|
|
|
|
|
|
|
|
}
|