This commit is contained in:
2024-07-21 22:39:39 +08:00
parent 883261dac6
commit 064b6bf1ae
14 changed files with 348 additions and 43 deletions

View File

@@ -5,7 +5,7 @@ import { smc } from "../../common/SingletonModuleComp";
import { Role } from "../../role/Role";
// 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')
@@ -20,7 +20,7 @@ export class MapViewComp extends CCComp {
current_map: any;
/** 转场碰撞点对象集合 */
private timer: Timer = new Timer(2);
reset(): void {
@@ -28,11 +28,16 @@ export class MapViewComp extends CCComp {
start() {
this.scene = this.getComponent(MapViewScene);
this.addHero();
}
/** 转场 */
protected update(dt: number): void {
if (this.timer.update(dt)) {
console.log('每2秒触发一次');
this.addHero();
}
}
private mapLoaded() {
@@ -40,33 +45,60 @@ export class MapViewComp extends CCComp {
/** 添加玩家 */
private addHero(pos?: Vec3) {
if (pos == null) {
this.scene.node.active = true
smc.own = ecs.getEntity<Role>(Role);
smc.own.load(this.aStarToVec3("-360,-60"), false);
// 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<Role>(Role);
let x = this.getRandomInt(0, 300)
monster.load(this.aStarToVec3(x+'60'), true, "magic");
}
// smc.own.loadJoystick();
// 测试玩家
var test = ecs.getEntity<Role>(Role);
test.load(this.aStarToVec3("-270,-60"), false);
var test1 = ecs.getEntity<Role>(Role);
test1.load(this.aStarToVec3("-180,-60"), false);
var test2 = ecs.getEntity<Role>(Role);
test2.load(this.aStarToVec3("-90,-60"), false);
// var test3 = ecs.getEntity<Role>(Role);
// test3.load(this.aStarToVec3("0,-60"), false);
var test4 = ecs.getEntity<Role>(Role);
test4.load(this.aStarToVec3("90,-60"), true,"monster");
var test5 = ecs.getEntity<Role>(Role);
test5.load(this.aStarToVec3("180,-60"), true,"magic");
var test6 = ecs.getEntity<Role>(Role);
test6.load(this.aStarToVec3("270,-60"), true,"heath");
var test7 = ecs.getEntity<Role>(Role);
test7.load(this.aStarToVec3("360,-60"), true);
}
// 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]);