添加role 删除多余地图文件
This commit is contained in:
9
assets/script/game/Role/Player.ts.meta
Normal file
9
assets/script/game/Role/Player.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1c56e8f6-c810-4a25-a499-ae1b39579a83",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/Role/PlayerModelComp.ts.meta
Normal file
9
assets/script/game/Role/PlayerModelComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "307a4494-1b3f-43d7-a489-8ab3c92bdb76",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/Role/PlayerSpine.ts.meta
Normal file
9
assets/script/game/Role/PlayerSpine.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e2701b2d-48ad-478f-9f91-2dfdcc897ffb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/Role/PlayerSpineAnimator.ts.meta
Normal file
9
assets/script/game/Role/PlayerSpineAnimator.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6bd906b8-b499-4ef5-90e5-1c73bd5d2ceb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
9
assets/script/game/Role/PlayerViewComp.ts.meta
Normal file
9
assets/script/game/Role/PlayerViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ce8e182a-d776-4361-9de5-cde2246c65a2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
68
assets/script/game/Role/Role.ts
Normal file
68
assets/script/game/Role/Role.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
/*
|
||||
* @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,resources ,SpriteAtlas,Sprite,v3} 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 { RoleModelComp } from "./RoleModelComp";
|
||||
import { RoleSpine } from "./RoleSpine";
|
||||
import { RoleViewComp } from "./RoleViewComp";
|
||||
import { RoleSet } from "../common/config/RoleSet";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Role`)
|
||||
export class Role extends ecs.Entity {
|
||||
// 数据层
|
||||
RoleModel!: RoleModelComp;
|
||||
// 视图层
|
||||
RoleView!: RoleViewComp;
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
RoleModelComp);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.remove(RoleViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=101) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/heros/role";
|
||||
|
||||
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*scale, 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/player';
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path);
|
||||
});
|
||||
this.hero_init(uuid,node)
|
||||
oops.message.dispatchEvent("hero_load",this)
|
||||
}
|
||||
|
||||
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
|
||||
var rv = node.getComponent(RoleViewComp)!;
|
||||
|
||||
this.add(rv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
9
assets/script/game/Role/Role.ts.meta
Normal file
9
assets/script/game/Role/Role.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9457fea4-0213-4426-a3ed-5234cc7985dc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
27
assets/script/game/Role/RoleModelComp.ts
Normal file
27
assets/script/game/Role/RoleModelComp.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('RoleModel')
|
||||
export class RoleModelComp extends ecs.Comp {
|
||||
/** 角色编号 */
|
||||
id: number = -1;
|
||||
|
||||
/** 角色名 */
|
||||
name: string = "Role";
|
||||
|
||||
/** 动画名资源 */
|
||||
anim: string = "Role";
|
||||
|
||||
reset() {
|
||||
this.id = -1;
|
||||
this.name = "";
|
||||
}
|
||||
}
|
||||
9
assets/script/game/Role/RoleModelComp.ts.meta
Normal file
9
assets/script/game/Role/RoleModelComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1ae88b75-8890-46c0-a795-faf44c20ff92",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
68
assets/script/game/Role/RoleSpine.ts
Normal file
68
assets/script/game/Role/RoleSpine.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* @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 "../common/SingletonModuleComp";
|
||||
import RoleSpineAnimator from "./RoleSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* RPG SPINE角色模型
|
||||
*/
|
||||
@ccclass('RoleSpine')
|
||||
export class RoleSpine extends Component {
|
||||
@property({ type: RoleSpineAnimator, tooltip: '动画控制器' })
|
||||
animator: RoleSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
|
||||
this.initAnimator();
|
||||
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
|
||||
}
|
||||
|
||||
/** 初始化动画 */
|
||||
protected initAnimator() {
|
||||
this.spine = this.animator.getComponent(sp.Skeleton)!;
|
||||
}
|
||||
|
||||
setSkin(value: string): void {
|
||||
console.log("RoleSpine 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() {
|
||||
|
||||
}
|
||||
}
|
||||
9
assets/script/game/Role/RoleSpine.ts.meta
Normal file
9
assets/script/game/Role/RoleSpine.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "de8f3803-ed59-466e-b93b-f1e3e587113d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
58
assets/script/game/Role/RoleSpineAnimator.ts
Normal file
58
assets/script/game/Role/RoleSpineAnimator.ts
Normal 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 RoleSpineAnimator extends Component {
|
||||
private animName: string = "move";
|
||||
private loop: boolean = true;
|
||||
private spine!: sp.Skeleton;
|
||||
start() {
|
||||
this.spine = this.getComponent(sp.Skeleton)!;
|
||||
// console.log("RoleSpineAnimator 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("RoleSpineAnimator playAnimation");
|
||||
if (animName) {
|
||||
// console.log("RoleSpineAnimator playAnimation animName", animName);
|
||||
this.animName = animName;
|
||||
this.loop = loop;
|
||||
this.spine.setAnimation(0, this.animName, this.loop);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/Role/RoleSpineAnimator.ts.meta
Normal file
9
assets/script/game/Role/RoleSpineAnimator.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "7238526c-ee07-4d38-be30-ec2a4a5359c4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
117
assets/script/game/Role/RoleViewComp.ts
Normal file
117
assets/script/game/Role/RoleViewComp.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-11-18 17:42:59
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, v3,_decorator ,Collider2D,Contact2DType,IPhysics2DContact,Material,Sprite,ProgressBar} 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 { RoleSpine } from "./RoleSpine";
|
||||
import {BoxSet} from "../common/config/BoxSet"
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { SkillCom } from "../skills/SkillCom";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@ccclass('RoleViewComp') // 定义为 Cocos Creator 组件
|
||||
@ecs.register('RoleView', false) // 定义为 ECS 组件
|
||||
export class RoleViewComp extends CCComp {
|
||||
@property(Material)
|
||||
hitFlashMaterial: Material;
|
||||
orginalFlashMaterial: Material;
|
||||
sprite: Sprite;
|
||||
/** 角色动画 */
|
||||
as: RoleSpine = null!;
|
||||
/** 角色属性 */
|
||||
hp: number = 1000;
|
||||
hp_max:number = 1000;
|
||||
power: number = 0;
|
||||
stop_cd:number = 0;
|
||||
atk_cd:number = 0;
|
||||
atk:number = 2;
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(RoleSpine);
|
||||
|
||||
}
|
||||
start () {
|
||||
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
console.log("Role view start")
|
||||
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
// console.log('onPostSolve',skill);
|
||||
this.in_atked();
|
||||
if(this.hp <= 0 ){
|
||||
return
|
||||
}
|
||||
this.hp_change(skill.atk);
|
||||
}
|
||||
}
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
if(selfCollider.group == otherCollider.group){
|
||||
// console.log('monster view group 相同');
|
||||
|
||||
}else{
|
||||
// console.log('monster onPostSolve'+selfCollider.group+"|"+otherCollider.group);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
in_atked() {
|
||||
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
|
||||
this.scheduleOnce(() => {
|
||||
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
|
||||
}, 0.1);
|
||||
}
|
||||
hp_change(hp: number){
|
||||
this.hp -= hp;
|
||||
if(this.hp > this.hp_max){
|
||||
this.hp = this.hp_max;
|
||||
}
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp <= 0){
|
||||
console.log("dead");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
9
assets/script/game/Role/RoleViewComp.ts.meta
Normal file
9
assets/script/game/Role/RoleViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "b8b21b3c-dd6b-466b-8bdf-010481a9c576",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user