This commit is contained in:
2024-08-02 17:06:21 +08:00
parent 52cefb71b4
commit d5f2f65ee6
22 changed files with 920 additions and 75 deletions

View File

@@ -24,14 +24,14 @@ export class Main extends Root {
protected async run() {
smc.initialize = ecs.getEntity<Initialize>(Initialize);
smc.monsters = [
{prefab_path:'hero',name:'lang',speed:110},
// {prefab_path:'niu',name:'m2',speed:80},
{prefab_path:'lang',name:'迅狼',speed:110},
{prefab_path:'hero',name:'火猴',speed:110},
// {prefab_path:'niu',name:'m3',speed:40},
// {prefab_path:'niu',name:'m4',speed:80},
]
smc.heros = [
// {prefab_path:'niu',name:'war',speed:110},
{prefab_path:'hero',name:'hero',speed:60},
{prefab_path:'lang',name:'迅狼',speed:110},
{prefab_path:'hero',name:'火猴',speed:110},
// {prefab_path:'niu',name:'heath',speed:60},
// {prefab_path:'niu',name:'war',speed:60},
]

View File

@@ -15,5 +15,8 @@ export enum BoxSet {
BOX_WIDTH = 64,
BOX_HEIGHT = 64,
LETF_END = -400,
RIGHT_END = 400
RIGHT_END = 400,
HERO_START = -309,
MONSTER_START = 309,
GAME_LINE = -60,
}

View File

@@ -58,7 +58,7 @@ export class MapViewComp extends CCComp {
this.scene.node.active = true
if (smc.monsters.length>0){
let monster = ecs.getEntity<Monster>(Monster);
let pos:Vec3 = v3(BoxSet.RIGHT_END,-60)
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
let speed =smc.monsters[0].speed
let camp = -1
let prefab_path = smc.monsters[0].prefab_path
@@ -70,7 +70,7 @@ export class MapViewComp extends CCComp {
if(smc.heros.length>0) {
console.log("heros load")
let monster = ecs.getEntity<Monster>(Monster);
let pos = v3(BoxSet.LETF_END,-60)
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

View File

@@ -0,0 +1,56 @@
/*
* @Author: dgflash
* @Date: 2022-08-04 15:22:33
* @LastEditors: dgflash
* @LastEditTime: 2023-05-12 18:04:45
*/
import { Component, Node, Prefab, _decorator ,instantiate} from 'cc';
import { Timer } from '../../../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer';
import {oops} from "../../../../../../../extensions/oops-plugin-framework/assets/core/Oops";
const { ccclass, property } = _decorator;
/**
* 物体层
* 注:
* 1、这里的深度排序如果有性能问题可考虑修改为非每帧排序
* 2、如果全3D世界显示角色相关显示对象则不需要2D深度排序只引用2D地图上的位置信息
*/
@ccclass('SkillLayer')
export default class SkillLayer extends Component {
private timer: Timer = new Timer(0.2);
@property(Prefab)
light: Prefab = null;
onLoad(){
// 监听全局事件
oops.message.on("monster_load", this.onMonsterLoaded, this);
oops.message.on("hero_load", this.onHeroLoaded, this);
}
onMonsterLoaded(){
const light = instantiate(this.light);
light.setPosition(300,-30,0);
this.node.addChild(light);
}
onHeroLoaded(){
const light = instantiate(this.light);
light.setPosition(-300,-30,0);
this.node.addChild(light);
}
update(dt: number) {
this.timer.update(dt)
// if (this.timer.update(dt))
// this.node.children.sort(this.zIndexSort);
}
// private zIndexSort(a: Node, b: Node) {
// let a_zIndex = a.getComponent(Charactor)!.zIndex;
// let b_zIndex = b.getComponent(Charactor)!.zIndex;
// return a_zIndex - b_zIndex;
// }
public clear() {
this.node.children.forEach(n => {
});
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"7852ab4a-120b-4c93-9d76-9b48c382599f","files":[],"subMetas":{},"userData":{"simulateGlobals":[]}}

View File

@@ -0,0 +1,23 @@
import { _decorator, Component, Node, sp } from 'cc';
const { ccclass, property ,} = _decorator;
@ccclass('light')
export class light extends Component {
private spine!: sp.Skeleton;
start() {
}
protected onLoad(): void {
this.spine = this.getComponent(sp.Skeleton)!;
this.spine.setCompleteListener(trackEntry => {
this.node.destroy()
});
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "fc960e39-45c0-41bf-8ff8-04a4acca0c38",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -37,7 +37,9 @@ export class Monster extends ecs.Entity {
/** 加载角色 */
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/"+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;
@@ -47,7 +49,7 @@ export class Monster extends ecs.Entity {
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/'+name+'/spriteFrame';
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);

View File

@@ -61,6 +61,9 @@ export class MonsterSpine extends Component {
play(animName: string, loop: boolean): void {
this.spine.setAnimation(0, animName, loop);
}
atk() {
this.spine.setAnimation(0, "atk", false);
}
setAlpha(value: number): void {
var color: Color = this.spine.color;
color.a = 255 * (value / 1);

View File

@@ -23,7 +23,22 @@ export default class MonsterSpineAnimator extends Component {
// console.log("MonsterSpineAnimator start");
this.playAnimation(this.animName, this.loop);
}
mixTime:number= 0.2;
protected onLoad(): void {
this.spine = this.getComponent(sp.Skeleton)!;
// this.spine?.setMix('atk', 'move', this.mixTime);
// this.spine?.setMix('move','atk', this.mixTime);
this.spine.setEndListener(trackEntry => {
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
// console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
if (animationName == "atk") {
this.spine.setAnimation(0, "move", true);
}
});
}
lateUpdate(dt: number) {
//
}

View File

@@ -31,6 +31,11 @@ export class MonsterViewComp extends CCComp {
speed: number = 100;
/** 角色初始速度 */
ospeed: number = 100;
/**攻击速度 */
atk_speed: number = 2;
atk_cd: number = 0;
/** 状态 1move ,2: act 3: stop */
state: number = 1;
Tpos: Vec3 = v3(0,-60,0);
timer: number = 0;
@@ -52,9 +57,10 @@ export class MonsterViewComp extends CCComp {
case BoxSet.MONSTER:
switch (otherCollider.tag){
case BoxSet.HERO:
this.state = 2;
// console.log("im monster other is hero");
this.speed = 0;
this.timer = 1;
// this.speed = 0;
// this.timer = 1;
// console.log("speed:"+this.speed+" | timer:"+this.timer);
break;
case BoxSet.HERO_SKILL:
@@ -67,7 +73,7 @@ export class MonsterViewComp extends CCComp {
case BoxSet.HERO:
switch (otherCollider.tag){
case BoxSet.MONSTER:
this.state = 2;
break;
case BoxSet.HERO_SKILL:
@@ -119,7 +125,7 @@ export class MonsterViewComp extends CCComp {
this.in_destroy();
this.in_stop(dt);
this.in_act(dt);
switch (this.type) {
case 1:
this.as.walk();
@@ -133,9 +139,19 @@ export class MonsterViewComp extends CCComp {
this.update_pos();
}
move(dt: number){
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
}
in_act(dt: number) {
if(this.atk_cd >= this.atk_speed){
this.atk_cd = 0;
this.as.atk();
}
if(this.state == 2){
this.atk_cd += dt;
}
}
/** 静止时间 */
in_stop (dt: number) {
if(this.timer > 0){