From c3e72b246941ecbabc9ab3845bfb78e93e8e1605 Mon Sep 17 00:00:00 2001 From: walkpan Date: Sun, 4 Aug 2024 22:34:43 +0800 Subject: [PATCH] dd --- assets/script/game/map/view/MapViewComp.ts | 8 +-- assets/script/game/monster/Hero.ts | 71 ++++++++++++++++++++++ assets/script/game/monster/Hero.ts.meta | 9 +++ 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 assets/script/game/monster/Hero.ts create mode 100644 assets/script/game/monster/Hero.ts.meta diff --git a/assets/script/game/map/view/MapViewComp.ts b/assets/script/game/map/view/MapViewComp.ts index 8378adfb..2544f0c9 100644 --- a/assets/script/game/map/view/MapViewComp.ts +++ b/assets/script/game/map/view/MapViewComp.ts @@ -2,9 +2,9 @@ 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 { Role } from "../../role/Role"; import { BoxSet } from "../../common/config/BoxSet"; -import { Hero } from "../../heros/Hero"; +import { Hero } from "../../monster/Hero"; import { Monster } from "../../monster/Monster"; // import MapRoadUtils from "./map/road/MapRoadUtils"; import { MapViewScene } from "./MapViewScene"; @@ -69,13 +69,13 @@ export class MapViewComp extends CCComp { if(smc.heros.length>0) { console.log("heros load") - let monster = ecs.getEntity(Monster); + let hero = ecs.getEntity(Hero); let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE) let speed =smc.heros[0].speed let camp = 1 let prefab_path = smc.heros[0].prefab_path let name = smc.heros[0].name - monster.load(pos,speed,camp,prefab_path,name); + hero.load(pos,speed,camp,prefab_path,name); smc.heros.splice(0,1) } smc.vm_data.hp.min = 100 diff --git a/assets/script/game/monster/Hero.ts b/assets/script/game/monster/Hero.ts new file mode 100644 index 00000000..b47582e4 --- /dev/null +++ b/assets/script/game/monster/Hero.ts @@ -0,0 +1,71 @@ + +/* + * @Author: dgflash + * @Date: 2021-11-18 17:47:56 + * @LastEditors: dgflash + * @LastEditTime: 2022-08-04 15:43:04 + */ +import { instantiate, Node, Prefab, Vec3 ,tween, v3,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact, animation,Label,resources,SpriteFrame,Sprite} 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 { MonsterModelComp } from "./MonsterModelComp"; +import { MonsterSpine } from "./MonsterSpine"; +import { MonsterViewComp } from "./MonsterViewComp"; +/** 角色实体 */ +@ecs.register(`Hero`) +export class Hero extends ecs.Entity { + // 数据层 + MonsterModel!: MonsterModelComp; + // 视图层 + MonsterView!: MonsterViewComp; + + protected init() { + this.addComponents( + MonsterModelComp); + + } + + destroy(): void { + this.remove(MonsterViewComp); + super.destroy(); + } + + /** 加载角色 */ + load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") { + // var path = "game/monster/"+prefab_path; + var path = "game/monster/hero"; + + var prefab: Prefab = oops.res.get(path, Prefab)!; + var node = instantiate(prefab); + var scene = smc.map.MapView.scene; + node.parent = scene.entityLayer!.node!; + var as = node.getComponent(MonsterSpine); + + node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z); + node.setPosition(pos) + console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) + const url = 'game/heros/hero/'+prefab_path+'/spriteFrame'; + resources.load(url, SpriteFrame, (err: any, spriteFrame) => { + const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); + + sprite.spriteFrame = spriteFrame; + }); + + var mv = node.getComponent(MonsterViewComp)!; + mv.speed =mv.ospeed = speed; + mv.hero_name= name; + mv.camp = camp; + mv.Tpos = v3(0,0,0); + mv.change_name(name,camp) + this.add(mv); + smc.heros_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}) + oops.message.dispatchEvent("hero_load",this) + } + + + + +} \ No newline at end of file diff --git a/assets/script/game/monster/Hero.ts.meta b/assets/script/game/monster/Hero.ts.meta new file mode 100644 index 00000000..217e2cc1 --- /dev/null +++ b/assets/script/game/monster/Hero.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "a45699e6-eeb3-4af3-99a2-de740888bf56", + "files": [], + "subMetas": {}, + "userData": {} +}