背后载入
This commit is contained in:
@@ -24,7 +24,12 @@ export class Main extends Root {
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
smc.monsters = ['war','magic','heath']
|
||||
smc.heros = ['war','magic','heath']
|
||||
smc.heros = [
|
||||
{profession:'war',speed:60},
|
||||
{profession:'magic',speed:60},
|
||||
{profession:'heath',speed:60},
|
||||
{profession:'war',speed:60},
|
||||
]
|
||||
console.log("Game start");
|
||||
}
|
||||
protected initGui() {
|
||||
|
||||
63
assets/script/game/heros/Hero.ts
Normal file
63
assets/script/game/heros/Hero.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:47:56
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:43:04
|
||||
*/
|
||||
import { instantiate, Node, Prefab, tween, Vec3,Label } from "cc";
|
||||
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { HeroModelComp } from "./HeroModelComp";
|
||||
import { HeroSpine } from "./HeroSpine";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Hero`)
|
||||
export class Hero extends ecs.Entity {
|
||||
// 数据层
|
||||
HeroModel!: HeroModelComp;
|
||||
// 视图层
|
||||
HeroView!: HeroViewComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
HeroModelComp);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(HeroViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,profession:string = "war") {
|
||||
var path = "game/heros/"+profession;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
let label =node.getChildByName("top").getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = profession;
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
var as = node.getComponent(HeroSpine);
|
||||
node.setPosition(pos)
|
||||
node.setScale(1, 1, 1);
|
||||
var mv = node.getComponent(HeroViewComp)!;
|
||||
this.add(mv);
|
||||
let speed = smc.heros[0].speed;
|
||||
tween(node).to(speed/60, { position: new Vec3(0, -60, 0) }, {
|
||||
onComplete: () => {
|
||||
// this.as.walk();
|
||||
}
|
||||
}).start();
|
||||
//移除全局列表
|
||||
smc.heros.splice(0,1)
|
||||
console.log(ecs.query(ecs.allOf(HeroViewComp))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
assets/script/game/heros/Hero.ts.meta
Normal file
1
assets/script/game/heros/Hero.ts.meta
Normal file
@@ -0,0 +1 @@
|
||||
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"984e9949-2b16-4e46-bb30-6ac00a2a838e","files":[],"subMetas":{},"userData":{}}
|
||||
27
assets/script/game/heros/HeroModelComp.ts
Normal file
27
assets/script/game/heros/HeroModelComp.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 15:56:01
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 13:43:25
|
||||
*/
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
|
||||
/**
|
||||
* 角色属性数据
|
||||
*/
|
||||
@ecs.register('HeroModel')
|
||||
export class HeroModelComp extends ecs.Comp {
|
||||
/** 角色编号 */
|
||||
id: number = -1;
|
||||
|
||||
/** 角色名 */
|
||||
name: string = "Hero";
|
||||
|
||||
/** 动画名资源 */
|
||||
anim: string = "Hero";
|
||||
|
||||
reset() {
|
||||
this.id = -1;
|
||||
this.name = "";
|
||||
}
|
||||
}
|
||||
1
assets/script/game/heros/HeroModelComp.ts.meta
Normal file
1
assets/script/game/heros/HeroModelComp.ts.meta
Normal file
@@ -0,0 +1 @@
|
||||
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"0ce59d56-a495-4b95-9405-a8a85d47a439","files":[],"subMetas":{},"userData":{}}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator } from "cc";
|
||||
import { Vec3, _decorator ,tween} 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 { HeroSpine } from "./HeroSpine";
|
||||
@@ -23,6 +23,7 @@ export class HeroViewComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@ import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs
|
||||
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 { 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";
|
||||
@@ -45,69 +46,28 @@ export class MapViewComp extends CCComp {
|
||||
}
|
||||
|
||||
/** 添加玩家 */
|
||||
private addHero(pos?: Vec3) {
|
||||
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<Role>(Role);
|
||||
// let x = this.getRandomInt(-300, 0)
|
||||
// hero.load(this.aStarToVec3(x+',60'), false, "magic");
|
||||
// }
|
||||
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);
|
||||
let x = this.getRandomInt(-100, 100)
|
||||
monster.load(this.aStarToVec3(x+',-60'));
|
||||
monster.load(v3(360,-60));
|
||||
smc.monsters.splice(0,1)
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-04 15:43:04
|
||||
*/
|
||||
import { instantiate, Node, Prefab, Vec3 } from "cc";
|
||||
import { instantiate, Node, Prefab, Vec3 ,tween} from "cc";
|
||||
import { UICallbacks } from "../../../../extensions/oops-plugin-framework/assets/core/gui/layer/Defines";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
@@ -14,7 +14,7 @@ import { smc } from "../common/SingletonModuleComp";
|
||||
import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { MonsterSpine } from "./MonsterSpine";
|
||||
import { MonsterViewComp } from "./MonsterViewComp";
|
||||
|
||||
import { MoveTo } from "../../../../extensions/oops-plugin-framework/assets/libs/animator-move/MoveTo";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
@@ -48,7 +48,12 @@ export class Monster extends ecs.Entity {
|
||||
var mv = node.getComponent(MonsterViewComp)!;
|
||||
this.add(mv);
|
||||
node.setScale(-1, 1, 1);
|
||||
tween(node).to(1, { position: new Vec3(0, -60, 0) }, {
|
||||
onComplete: () => {
|
||||
// this.as.walk();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator } from "cc";
|
||||
import { Vec3, _decorator ,tween} 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 { MonsterSpine } from "./MonsterSpine";
|
||||
@@ -23,6 +23,8 @@ export class MonsterViewComp extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
//移动到0,-60
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,51 +23,6 @@ export default class RoleSpineAnimator extends Component {
|
||||
this.spine = this.getComponent(sp.Skeleton)!;
|
||||
console.log("RoleSpineAnimator start smc.heros",smc.heros);
|
||||
|
||||
let heros=smc.heros
|
||||
if(heros.length>0){
|
||||
/**
|
||||
* 取第一个heros
|
||||
*/
|
||||
|
||||
this.spine.setSkin(heros[0])
|
||||
console.log("RoleSpineAnimator setSkin", heros[0]);
|
||||
switch (heros[0]) {
|
||||
case 'war':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
case 'magic':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
case 'heath':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
default:
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
}
|
||||
//移除smc.heros[0],heros key 重新取
|
||||
heros.splice(0,1)
|
||||
smc.heros=heros
|
||||
|
||||
}else if(smc.monsters.length>0){
|
||||
this.spine.setSkin(smc.monsters[0])
|
||||
console.log("RoleSpineAnimator setSkin", smc.monsters[0]);
|
||||
switch (smc.monsters[0]) {
|
||||
case 'war':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
case 'magic':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
case 'heath':
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
default:
|
||||
this.spine.setAnimation(0, 'idle', true)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
lateUpdate(dt: number) {
|
||||
|
||||
Reference in New Issue
Block a user