monster add

This commit is contained in:
2024-07-22 09:47:28 +08:00
parent 064b6bf1ae
commit e3b5f4bd05
31 changed files with 4417 additions and 17 deletions

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d69b1760-afe9-4a23-bc30-01ee0adf48cc",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,88 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:26
*/
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../script/game/common/SingletonModuleComp";
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
import HeroSpineAnimator from "./HeroSpineAnimator";
const { ccclass, property } = _decorator;
/**
* SPINE角色模型
*/
@ccclass('HeroSpine')
export class HeroSpine extends Component {
@property({ type: HeroSpineAnimator, tooltip: '动画控制器' })
animator: HeroSpineAnimator = null!;
private spine!: sp.Skeleton;
// private charactor!: Charactor;
onLoad() {
// 角色控制组件
// this.charactor = this.addComponent(Charactor)!;
this.initAnimator();
// this.setSkin("magic");
// this.animator.play("idle", true);
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
}
/** 初始化动画 */
protected initAnimator() {
this.spine = this.animator.getComponent(sp.Skeleton)!;
}
// setState(value: CharactorState): void {
// switch (value) {
// case CharactorState.Idle:
// this.idle();
// break;
// case CharactorState.Run:
// this.walk();
// break;
// }
// }
setSkin(value: string): void {
console.log("HeroSpine setSkin", value);
this.spine.setSkin(value);
}
play(animName: string, loop: boolean): void {
this.spine.setAnimation(0, animName, loop);
}
setAlpha(value: number): void {
var color: Color = this.spine.color;
color.a = 255 * (value / 1);
this.spine.color = color;
}
setPos(value: Vec3): void {
this.node.position = value;
}
checkTouch(event: EventTouch): boolean {
return false;
}
onDestroy() {
this.node.destroy();
}
walk() {
}
idle() {
}
}

View File

@@ -1 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"b5ce7cce-a8eb-439f-b034-13d10f8f9e2f","files":[],"subMetas":{},"userData":{}}
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"c66b3a64-90df-4454-b232-a18b05baed20","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,58 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:08:35
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:26:38
*/
import { sp, _decorator ,Component} from "cc";
const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
/**
* Spine状态机组件主状态机trackIndex为0
*/
@ccclass
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class HeroSpineAnimator extends Component {
private animName: string = "idle";
private loop: boolean = true;
private spine!: sp.Skeleton;
start() {
this.spine = this.getComponent(sp.Skeleton)!;
console.log("HeroSpineAnimator start");
this.playAnimation(this.animName, this.loop);
}
lateUpdate(dt: number) {
//
}
play(animName: string, loop: boolean) {
if (animName) {
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);
}
else {
}
}
/**
* 播放动画
* @override
* @param animName 动画名
* @param loop 是否循环播放
*/
protected playAnimation(animName: string, loop: boolean) {
console.log("HeroSpineAnimator playAnimation");
if (animName) {
console.log("HeroSpineAnimator playAnimation animName", animName);
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);
}
else {
}
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"4f84982c-c68b-4950-b521-892438804b1a","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,33 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:42:59
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:18
*/
import { 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 { HeroSpine } from "./HeroSpine";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
@ecs.register('HeroView', false) // 定义为 ECS 组件
export class HeroViewComp extends CCComp {
/** 角色动画 */
as: HeroSpine = null!;
/** 角色控制器 */
/** 视图层逻辑代码分离演示 */
onLoad() {
this.as = this.getComponent(HeroSpine);
}
reset() {
this.node.destroy();
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"ffc9ef3c-4de8-4996-abe0-296d8956dcfe","files":[],"subMetas":{},"userData":{}}

View File

@@ -3,6 +3,7 @@ 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 MapRoadUtils from "./map/road/MapRoadUtils";
import { MapViewScene } from "./MapViewScene";
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
@@ -49,15 +50,15 @@ export class MapViewComp extends CCComp {
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<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");
let monster = ecs.getEntity<Monster>(Monster);
let x = this.getRandomInt(-100, 100)
monster.load(this.aStarToVec3(x+',-60'));
}
// smc.own.loadJoystick();

View File

@@ -2,7 +2,7 @@
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "d5604362-ce57-4bc2-9a05-cb1ba2e170a2",
"uuid": "9addebc8-0dc6-46c3-b9d5-091539127714",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -0,0 +1,54 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:47:56
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:43:04
*/
import { instantiate, Node, Prefab, Vec3 } 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(`Monster`)
export class Monster extends ecs.Entity {
// 数据层
MonsterModel!: MonsterModelComp;
// 视图层
MonsterView!: MonsterViewComp;
protected init() {
this.addComponents<ecs.Comp>(
MonsterModelComp);
}
destroy(): void {
this.remove(MonsterViewComp);
super.destroy();
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO) {
var path = "game/monster/monster";
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.setPosition(pos)
var mv = node.getComponent(MonsterViewComp)!;
this.add(mv);
node.setScale(-1, 1, 1);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "e889d785-f34d-46f5-825c-8906863db245",
"files": [],
"subMetas": {},
"userData": {}
}

View 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('MonsterModel')
export class MonsterModelComp extends ecs.Comp {
/** 角色编号 */
id: number = -1;
/** 角色名 */
name: string = "monster";
/** 动画名资源 */
anim: string = "monster";
reset() {
this.id = -1;
this.name = "";
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "b5f2873a-5007-436b-95ef-1e73281a374f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -5,8 +5,8 @@
* @LastEditTime: 2022-08-04 15:26:26
*/
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
import { LayerUtil } from "../../../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../common/SingletonModuleComp";
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../script/game/common/SingletonModuleComp";
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
import MonsterSpineAnimator from "./MonsterSpineAnimator";
@@ -36,6 +36,7 @@ export class MonsterSpine extends Component {
/** 初始化动画 */
protected initAnimator() {
this.spine = this.animator.getComponent(sp.Skeleton)!;
console.log("MonsterSpine initAnimator", this.spine);
}

View File

@@ -14,13 +14,13 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator;
@ccclass
@disallowMultiple
@requireComponent(sp.Skeleton)
export default class RoleSpineAnimator extends Component {
export default class MonsterSpineAnimator extends Component {
private animName: string = "idle";
private loop: boolean = true;
private spine!: sp.Skeleton;
start() {
this.spine = this.getComponent(sp.Skeleton)!;
console.log("RoleSpineAnimator start");
console.log("MonsterSpineAnimator start");
this.playAnimation(this.animName, this.loop);
}
@@ -44,9 +44,9 @@ export default class RoleSpineAnimator extends Component {
* @param loop
*/
protected playAnimation(animName: string, loop: boolean) {
console.log("RoleSpineAnimator playAnimation");
console.log("MonsterSpineAnimator playAnimation");
if (animName) {
console.log("RoleSpineAnimator playAnimation animName", animName);
console.log("MonsterSpineAnimator playAnimation animName", animName);
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);

View File

@@ -6,8 +6,8 @@
*/
import { 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 { 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";
const { ccclass, property } = _decorator;

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "dc1b7210-4d5c-477c-81c5-7d6bb4bb823f",
"files": [],
"subMetas": {},
"userData": {}
}