添加了几个英雄

This commit is contained in:
2024-09-09 10:48:52 +08:00
parent 3c2bf955a6
commit 0129c63bb9
279 changed files with 25842 additions and 6672 deletions

View File

@@ -5,6 +5,7 @@ import { RoleViewComp } from "./RoleViewComp";
import { RoleSpine } from "./RoleSpine";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { smc } from "../common/SingletonModuleComp";
import { BoxSet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator;
@@ -17,7 +18,7 @@ export class RoleBuffComp extends CCComp {
timer:Timer = new Timer(0.1);
buffs:any=[];
group:number=0;
group:number=BoxSet.HERO;
/**
skill_uuid:number=0;
atk:number=0;

View File

@@ -12,7 +12,7 @@ const { ccclass, property } = _decorator;
export class RoleRangComp extends CCComp {
Hero_node: any=null!;
RoleViewComp:RoleViewComp = null!;
box_group:number = BoxSet.DEFAULT;
box_group:number = BoxSet.HERO;
box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 0;
atk_range:number = 150;

View File

@@ -74,7 +74,7 @@ export class RoleViewComp extends CCComp {
shield_max:number = 200;
shield_time:number = 0; //护盾持续时间
box_group:number = 2;
box_group:number = BoxSet.HERO;
atk_range:number = 150;
private timer:Timer = new Timer(0.1); //计时器
is_dead:boolean = false; //是否摧毁
@@ -267,6 +267,7 @@ export class RoleViewComp extends CCComp {
if(this.hp <= 0){
this.dead();
this.is_dead = true;
smc.vm_data.game_over = true;
setTimeout(() => {
this.ent.destroy();
}, 15);

View File

@@ -57,6 +57,7 @@ export class SingletonModuleComp extends ecs.Comp {
least_hp_hero_hp:number=1000;
vm_data: any = {
name : "纸片精灵大乱斗",
game_over:false,
/**宝石数量 */
gems: 4,
unlock:5,

View File

@@ -1,11 +1,11 @@
export const MonSet={
1001:{uuid: 1101,path: "orc1",type: 1,level: 1,name: "绿洲兽人",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
1001:{uuid: 1001,path: "ge1",type: 1,level: 1,name: "战斗哥",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
skill: "base",max_skill: "base",skill_uuid: 9001,max_skill_uuid: 1001,word: "守护",info: "自身护盾", atktype: "攻击型",mon: "orc"},
1002:{uuid: 1002,path: "orc2",type: 1,level: 1,name: "荒野兽人",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
1002:{uuid: 1002,path: "ge2",type: 1,level: 1,name: "墨西哥",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
skill: "base",max_skill: "base",skill_uuid: 9001,max_skill_uuid: 1001,word: "守护",info: "自身护盾", atktype: "攻击型",mon: "orc"},
1003:{uuid: 1003,path: "orc3",type: 1,level: 1,name: "高阶兽人",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
1003:{uuid: 1003,path: "ge3",type: 1,level: 1,name: "铁头哥",atk: 4,hp: 24,atk_cd: 2,power: 50,speed: 30,
skill: "base",max_skill: "base",skill_uuid: 9001,max_skill_uuid: 1001,word: "守护",info: "自身护盾", atktype: "攻击型",mon: "orc"},
}

View File

@@ -0,0 +1 @@
{"ver":"1.2.0","importer":"directory","imported":true,"uuid":"d80f4c15-dc94-4c0f-a578-c3a906575911","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,83 @@
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact,v3, v2,Vec3} 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 { BoxSet } from "../common/config/BoxSet";
import { HeroViewComp } from "./HeroViewComp";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('BoxRangComp')
@ecs.register('BoxRang', false)
export class BoxRangComp extends CCComp {
Hero_node: any=null!;
HeroViewComp:HeroViewComp = null!;
box_group:number = BoxSet.HERO;
box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 300;
atk_range:number = 150;
/** 视图层逻辑代码分离演示 */
start() {
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
// collider.offset = v2(300*this.Hero_node.MonView.scale,collider.offset.y);
this.Hero_node = this.node.parent;
this.HeroViewComp=this.Hero_node.getComponent(HeroViewComp);
// console.log("range box",this.HeroViewComp);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
// console.log(this.node.name+"onBeginContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
// this.HeroViewComp.is_atking = true;
// if(Math.abs(otherCollider.node.position.x-selfCollider.node.position.x) < 120){
// this.HeroViewComp.stop_cd = 0.1
// }
// }
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.HeroViewComp.is_atking = false;
this.HeroViewComp.enemy = null;
}
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
let scene =smc.map.MapView.scene.mapLayer!.node!
let other_pos = otherCollider.node.getWorldPosition() ;
let self_pos = this.node.getWorldPosition();
// console.log("onPreSolve:",self_pos,other_pos);
if(this.HeroViewComp.enemy==null){
this.HeroViewComp.enemy = otherCollider.node;
}else{
if(this.HeroViewComp.enemy.isValid==false){
this.HeroViewComp.enemy = otherCollider.node;
}
}
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
this.HeroViewComp.is_atking = true;
// this.HeroViewComp.stop_cd = 0.1
}
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}

View File

@@ -1 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"5fd6bb0b-8ab2-4ffe-8682-108d9e999004","files":[],"subMetas":{},"userData":{}}
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"4d46fe9a-6a73-4e21-994b-ae00e9f624d0","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,95 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:47:56
* @LastEditors: dgflash
* @LastEditTime: 2022-08-04 15:43:04
*/
import { instantiate, Node, Prefab, Vec3 ,v3,resources,SpriteFrame,Sprite,SpriteAtlas} 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";
import { BoxSet } from "../common/config/BoxSet";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { HeroBuffComp } from "./HeroBuffComp";
import { HeroSet } from "../common/config/heroSet";
import { MonSet } from "../common/config/MonSet";
/** 角色实体 */
@ecs.register(`Hero`)
export class Hero extends ecs.Entity {
// 数据层
HeroModel!: HeroModelComp;
// 视图层
HeroView!: HeroViewComp;
HeroBuff!: HeroBuffComp; // 移动
protected init() {
this.addComponents<ecs.Comp>( HeroModelComp);
}
destroy(): void {
this.remove(HeroViewComp);
this.remove(HeroBuffComp);
super.destroy();
}
/** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
var path = "game/monster/"+MonSet[uuid].path;
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.parent=layer
// var as = node.getComponent(HeroSpine);
// let ratio=this.set_ratio(uuid);
// node.setScale(node.scale.x*scale*ratio, node.scale.y*ratio, 0);
node.setPosition(pos)
this.hero_init(uuid,node)
oops.message.dispatchEvent("mon_load",this)
}
set_ratio(uuid:number){
let ratio=1;
switch (MonSet[uuid].level) {
case 2:
ratio=1.05
break;
case 3:
ratio=1.1
break;
case 4:
ratio=1.15
break;
case 5:
ratio=1.2
break;
default:
ratio=1
}
return ratio;
}
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(HeroViewComp)!;
var buff =node.getComponent(HeroBuffComp)!;
// console.log("hero_init",buff)
mv.speed =mv.ospeed = smc.monsters[uuid].speed;
mv.hero_name= smc.monsters[uuid].name;
buff.group=mv.box_group= BoxSet.MONSTER;
mv.hp= mv.hp_max = smc.monsters[uuid].hp;
mv.level = smc.monsters[uuid].level;
mv.atk = smc.monsters[uuid].atk;
mv.atk_cd = smc.monsters[uuid].atk_cd;
mv.power = smc.monsters[uuid].power;
mv.type = smc.monsters[uuid].type;
mv.skill_uuid = 9001;
mv.max_skill_uuid = smc.monsters[uuid].max_skill_uuid;
mv.scale = -1;
mv.Tpos = v3(0,0,0);
this.add(mv);
this.add(buff);
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"31289da2-91ea-4ffe-85f3-879a3ac7641d","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,153 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:42:59
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:18
*/
import { _decorator,Sprite,Color} 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";
import { Hero } from "./Hero";
import { HeroModelComp } from "./HeroModelComp";
import { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Skill } from "../skills/Skill";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../skills/SkillCom";
import { BoxRangComp } from "./BoxRangComp";
import { Tooltip } from "../skills/Tooltip";
import { HeroViewComp } from "./HeroViewComp";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('HeroBuffComp') // 定义为 Cocos Creator 组件
@ecs.register('HeroBuff', false) // 定义为 ECS 组件
export class HeroBuffComp extends CCComp {
/** 角色动画 */
as: HeroSpine = null!;
mv!: HeroViewComp;
timer:Timer = new Timer(0.1);
buffs:any=[];
group:number=BoxSet.HERO;
/**
skill_uuid:number=0;
atk:number=0;
hp:number=0;
shield:number=0;
time:number=0;
**/
onLoad() {
this.as = this.node.getComponent(HeroSpine);
this.mv= this.getComponent(HeroViewComp);
} /** 视图层逻辑代码分离演示 */
start () {
}
add_buff(uuid:number=0,args:any[]){
// console.log("add_buff",smc.skills[uuid]);
let new_buff={
skill_uuid:uuid,
skill_name:smc.skills[uuid].name,
atk:smc.skills[uuid].atk,
hp:smc.skills[uuid].hp,
shield:smc.skills[uuid].shield,
time:smc.skills[uuid].bsd,
bcd:smc.skills[uuid].bcd,
sk_uuid:smc.skills[uuid].uuid,
args:args
}
this.buff_add(new_buff);
}
update(dt: number){
if (this.timer.update(dt)) {
this.buff_update()
}
}
reset() {
this.node.destroy();
}
buff_add(buff:any){
if(!this.node.isValid){ return }
let i = 0
if(this.buffs.length >=0){
this.buffs.forEach((b:any,index:number)=>{
if(b.skill_uuid==buff.skill_uuid){
b.time=buff.time;
if(buff.atk>0){
this.node.getChildByName("avatar").setScale(1.2,1.2)
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
this.mv.atk+=(buff.atk+buff.args.atk-b.atk);
}
if(buff.hp>0){
this.mv.hp+=(buff.hp+buff.args.hp);
this.mv.add_hp(buff.hp+buff.args.hp);
// this.mv.hp_max+=(buff.hp-b.hp);
}
if(buff.shield>0){
this.mv.shield=(buff.shield+buff.args.shield);
// this.mv.shield_max=(buff.shield+buff.args.shield);
}
i=index
}
})
}
if (i==0||this.buffs.length==0) {
this.buffs.push(buff);
if(buff.atk>0){
this.mv.atk+=(buff.atk+buff.args.atk);
this.node.getChildByName("avatar").setScale(1.2,1.2)
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#F16F6F");
}
if(buff.hp>0){
this.mv.hp+=(buff.hp+buff.args.hp);
this.mv.add_hp(buff.hp+buff.args.hp);
// this.mv.hp_max+=buff.hp;
}
if(buff.shield>0){
this.mv.shield=(buff.shield+buff.args.shield);
// this.mv.shield_max=(buff.shield+buff.args.shield);
}
}
console.log("buff add:",this.mv);
}
buff_remove(index:number){
if(this.buffs[index].atk>0){
this.mv.atk-=(this.buffs[index].atk+this.buffs[index].args.atk);
this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite).color= new Color().fromHEX("#FFFFFF");
this.node.getChildByName("avatar").setScale(1,1)
}
if(this.buffs[index].shield>0){
this.mv.shield=0
// this.mv.shield_max-=(this.buffs[index].shield+this.buffs[index].args.shield);
}
// if(this.buffs[index].hp>0){
// this.mv.hp_max-=this.buffs[index].hp;
// }
console.log("buff remove:",this.mv,this.buffs[index]);
}
buff_update(){
this.buffs.forEach((buff:any,index:number)=>{
buff.time -= 0.1;
if(buff.time <= 0){
this.buff_remove(index);
}
})
this.buffs = this.buffs.filter((buff:any) => buff.time > 0);
// console.log(this.buffs,this.buffs);
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"56aac6b6-8d82-4bc5-8cb1-d227489ce0c8","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,29 @@
/*
* @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 = "mon";
/** speed */
// speed: number = 0;
/** 动画名资源 */
anim: string = "mon";
reset() {
this.id = -1;
// this.speed = 0;
this.name = "";
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"c9121e83-b457-492d-aa56-2119d79a3360","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,85 @@
/*
* @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 ,Animation, AnimationClip, AnimationState,} from "cc";
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
import { smc } from "../../../script/game/common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/**
* SPINE角色模型
*/
@ccclass('HeroSpine')
export class HeroSpine extends Component {
@property(Animation)
animator: Animation = null!;
idle_clip: AnimationClip = null!;
atk_clip: AnimationClip = null!;
max_clip: AnimationClip = null!;
move_clip: AnimationClip = null!;
default_clip:string = "idle";
onLoad() {
// 角色控制组件
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
this.idle_clip = this.animator.clips[0];
this.atk_clip = this.animator.clips[1];
this.max_clip = this.animator.clips[2];
this.move_clip = this.animator.clips[3];
let animation = this.animator.getComponent(Animation);
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
}
/** 初始化动画 */
protected initAnimator() {
this.animator=this.node.getChildByName("anm").getComponent(Animation);
// console.log("mon spine init",this.animator);
}
onAnimationEvent(type: Animation.EventType, state: AnimationState){
if(type==Animation.EventType.FINISHED){
if(state.name==this.atk_clip.name||state.name==this.max_clip.name){
this.default();
}
}
}
change_default(value:string){
this.default_clip=value;
this.animator.play(this.default_clip);
}
default() {
this.animator.play(this.default_clip);
}
idle(){
if(!this.animator.getState(this.idle_clip.name).isPlaying){
this.animator.play(this.idle_clip.name);
}
}
atk() {
if(!this.animator.getState(this.atk_clip.name).isPlaying){
this.animator.play(this.atk_clip.name);
}
}
max(){
if(!this.animator.getState(this.max_clip.name).isPlaying){
this.animator.play(this.max_clip.name);
}
}
move(){
if(!this.animator.getState(this.move_clip.name).isPlaying){
this.animator.play(this.move_clip.name);
}
}
onDestroy() {
this.node.destroy();
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"a03797e6-86f0-4771-b35c-045fe5e373bc","files":[],"subMetas":{},"userData":{}}

View File

@@ -0,0 +1,427 @@
/*
* @Author: dgflash
* @Date: 2021-11-18 17:42:59
* @LastEditors: dgflash
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} 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";
import { Hero } from "./Hero";
import { HeroModelComp } from "./HeroModelComp";
import { BoxSet } from "../common/config/BoxSet";
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Skill } from "../skills/Skill";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../skills/SkillCom";
import { SkillSet } from "../common/config/SkillSet";
import { Tooltip } from "../skills/Tooltip";
import { HeroBuffComp } from "./HeroBuffComp";
import { MoveToComp } from "../common/ecs/position/MoveTo";
import { BoxRangComp } from "./BoxRangComp";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@ccclass('HeroViewComp') // 定义为 Cocos Creator 组件
@ecs.register('HeroView', false) // 定义为 ECS 组件
export class HeroViewComp extends CCComp {
@property(Material)
hitFlashMaterial: Material;
orginalFlashMaterial: Material;
sprite: Sprite;
@property(Node)
BoxRang:Node =null!
buff:HeroBuffComp =null!
is_role:boolean = false;
enemy_pos:Vec3=null!;
enemy:any=null!;
/** 角色动画 */
as: HeroSpine = null!;
hero_uuid:number = 1001;
hero_name : string = "hero";
level:number =1;
scale: number = 1; /** 角色阵营 1hero -1 :mon */
type: number = 1; /**角色类型 1前排 2 后排 */
state: number = 1; /** 状态 1move ,2: act 3: stop */
hp: number = 100; /** 血量 */
hp_max: number = 100; /** 最大血量 */
hp_speed: number = 0; //每秒回复量
power: number = 0; /**能量**/
power_max: number = 1200; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "base"; //技能名称
max_skill_name: string = "base"; //大技能名称
skill_uuid:number = 9001;
max_skill_uuid:number = 1001;
atk: number = 10; /**攻击力 */
// atk_speed: number = 1;
atk_cd: number = 1.3; /**攻击速度 攻击间隔 */
atk_time: number = 0; /** 冷却时间 */
speed: number = 100; /** 角色移动速度 */
ospeed: number = 100; /** 角色初始速度 */
Tpos: Vec3 = v3(0,-60,0);
stop_cd: number = 0.5; /*停止倒计时*/
shield:number = 0; //护盾量
shield_max:number = 200;
shield_time:number = 0; //护盾持续时间
box_group:number = BoxSet.HERO;
atk_range:number = 150;
private timer:Timer = new Timer(1); //计时器
private m_timer:Timer = new Timer(0.1);
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
is_atking:boolean = false;
onLoad() {
this.as = this.getComponent(HeroSpine);
this.buff=this.node.getComponent(HeroBuffComp);
// this.BoxRang = this.node.getChildByName("range_box");
// this.BoxRang = this.node.getChildByName("range_box");
} /** 视图层逻辑代码分离演示 */
start () {
this.as.idle()
this.sprite = this.node.getChildByName("anm").getComponent(Sprite);
// this.node.getChildByName("top").setScale(this.scale,1);
// this.node.getChildByName("atk").setScale(this.scale,1);
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
// this.node.getChildByName("hp_max").setScale(this.scale,1);
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
// this.BoxRang.getComponent(BoxRangComp).offset_x = 300;
// console.log("monseter ",this.BoxRang);
// console.log("monseter ",this.BoxRang);
// if(this.box_group == BoxSet.MON){
// this.enemy=smc.Role.RoleView.node
// // console.log("mon enemy ",this.enemy);
// }
this.buff.group=this.box_group
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
// this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString();
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.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) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
this.is_atking = true;
this.stop_cd = 0.1;
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
// console.log('mon view group 相同');
switch (selfCollider.group) {
case BoxSet.HERO:
if(self_pos.x < other_pos.x){
// this.stop_cd=0.1
}
break;
case BoxSet.MONSTER:
if(self_pos.x > other_pos.x){
// this.stop_cd=0.1
}
break
}
}
}
update(dt: number){
if (this.timer.update(dt)) {
this.power_change(this.power_speed)
}
this.in_destroy();
this.in_shield();
this.in_stop(dt);
this.in_act(dt);
// this.move(dt);
// if(this.m_timer.update(dt)){
// this.move_to()
// }
}
move(dt: number){
if(this.stop_cd > 0){
return
}
if (this.scale === 1 && this.node.position.x >= 120) {
return;
}
if(this.scale===-1&&this.node.position.x <= BoxSet.HERO_START){
return;
}
// if(this.enemy){
// return
// }
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
}
move_to(){
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
move.target = v3(smc.Role.RoleView.node.position.x+10,smc.Role.RoleView.node.position.y);
move.node = this.node;
move.speed = this.ospeed;
// if(this.box_group == BoxSet.MON){
// if(smc.t_hero.eid != 0){
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
// if(smc.t_hero.pos.x < this.node.position.x){
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_hero.pos.x+20,smc.t_hero.pos.y);
// }else{
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_hero.pos.x-20,smc.t_hero.pos.y);
// }
// move.node = this.node;
// move.speed = this.ospeed;
// }
// }
// if(this.box_group == BoxSet.HERO){
// if(smc.t_mon.eid != 0){
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
// if(smc.t_mon.pos.x < this.node.position.x){
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_mon.pos.x+20,smc.t_mon.pos.y);
// }else{
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_mon.pos.x-20,smc.t_mon.pos.y);
// }
// move.node = this.node;
// move.speed = this.ospeed;
// }
// }
}
power_change(power: number){
this.power += power;
if(this.power >= this.power_max){
this.as.atk()
this.scheduleOnce(()=>{
this.do_max_skill();
},0.5)
this.power = 0
}
let power_progress= this.power/this.power_max;
this.node.getChildByName("top").getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
}
shoot(skill_uuid:number){
// console.log("mon shoot");
let skill = ecs.getEntity<Skill>(Skill);
let x=32
let pos = v3(35*this.scale,50)
let scale = this.scale
let speed =smc.skills[skill_uuid].speed;
let dis = smc.skills[skill_uuid].dis;
let atk = smc.skills[skill_uuid].atk+this.atk;
let angle=0
let t_pos:Vec3 = v3(0,0)
if(this.enemy){
if(!this.enemy.isValid){
console.log("move_to",this.enemy.isValid);
return
}
t_pos = v3(this.enemy.position.x-this.node.position.x,this.enemy.position.y-this.node.position.y)
angle = Math.atan2(t_pos.y,t_pos.x) * 180 / Math.PI;
if(this.scale == -1){
angle = angle +180
}
}else{
t_pos=null
}
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk,angle,t_pos);
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
}
//使用max_skill
do_max_skill(){
let skill = ecs.getEntity<Skill>(Skill);
let x=32
let pos = v3(-40*this.scale,BoxSet.MAX_SKILL_SY)
let scale = this.scale
let speed =smc.skills[this.max_skill_uuid].speed;
let dis = smc.skills[this.max_skill_uuid].dis;
let atk = smc.skills[this.max_skill_uuid].atk+this.atk;
skill.load(pos,speed,dis,scale,this.node,this.max_skill_uuid,atk);
this.tooltip(3,smc.skills[this.max_skill_uuid].name,this.max_skill_uuid);
}
in_act(dt: number) {
if(this.atk_time >= this.atk_cd){
if(this.is_atking){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
this.scheduleOnce(()=>{
this.shoot(this.skill_uuid);
},0.4)
}
}else{
this.atk_time += dt;
}
}
in_shield(){
let shield_progress= this.shield/this.shield_max;
this.node.getChildByName("top").getChildByName("shield").getComponent(ProgressBar)!.progress = shield_progress;
// if(this.shield <= 0){
// this.node.getChildByName("shield").active=false
// }else{
// this.node.getChildByName("shield").active=true
// }
}
hp_change(hp: number){
if(this.is_dead){
return;
}
let lhp=this.shield_change(hp);
if(lhp == 0){
return;
}
this.hp += lhp;
this.tooltip(1,hp.toString());
if(this.hp > this.hp_max){
this.hp = this.hp_max;
}
let hp_progress= this.hp/this.hp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.hp <= 0){
this.dead();
this.remove_smc_data()
this.is_dead = true;
setTimeout(() => {
this.ent.destroy();
}, 15);
}
}
remove_smc_data(){
if(smc.t_monster.eid == this.ent.eid){
smc.t_monster = {eid:0,pos:v3(0,0,0)}
}
if(smc.t_hero.eid == this.ent.eid){
smc.t_hero = {eid:0,pos:v3(0,0,0)}
}
}
add_hp(hp: number=0){
console.log("hero 加血动画");
this.tooltip(2,hp.toString());
let hp_progress= this.hp/this.hp_max;
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
}
shield_change(hp: number){
let ls=this.shield - hp;
if(ls <= 0){
this.shield = 0;
return ls;
}else{
this.shield = ls;
return 0;
}
}
tooltip(type:number=1,value:string="",s_uuid:number=1001){
// console.log("tooltip",type);
let tip =ecs.getEntity<Tooltip>(Tooltip);
let pos = this.node.getPosition();
let node =this.node.parent
pos.y=pos.y+60;
tip.load(pos,type,value,s_uuid,node);
}
get_mon_pos(){
return this.node.getPosition()
}
/** 静止时间 */
in_stop (dt: number) {
if(this.stop_cd > 0){
this.stop_cd -= dt;
if(this.stop_cd <= 0){
this.stop_cd = 0;
this.is_atking = false;
}
}
}
in_destroy(){
// switch (this.scale) {
// case -1:
// if(this.node.position.x < BoxSet.LETF_END){
// this.toDestroy();
// }
// break;
// case 1:
// if(this.node.position.x > BoxSet.RIGHT_END){
// this.toDestroy();
// }
// break;
// }
}
in_atked() {
if(this.is_role){
var path = "game/skills/atked";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
let pos = v3(0,60)
node.setPosition(pos)
node.parent = this.node;
}else{
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
this.scheduleOnce(() => {
this.sprite.setSharedMaterial(this.orginalFlashMaterial, 0);
}, 0.1);
}
}
dead(){
var path = "game/skills/dead";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
node.setPosition(this.node.position.x,this.node.position.y+30,this.node.position.z);
node.parent = this.node.parent;
}
toDestroy(){
}
reset() {
this.is_dead = false;
this.node.destroy();
}
}

View File

@@ -0,0 +1 @@
{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"873f877e-4a89-4c12-8f03-8934f1651878","files":[],"subMetas":{},"userData":{}}

View File

@@ -37,6 +37,7 @@ export class MapMonsterComp extends CCComp {
setp_timer: Timer = new Timer(0.5);
target_timer: Timer = new Timer(0.1);
setp_num:number = 1;
game_over:boolean = false;
onLoad(){
// 监听全局事件
oops.message.on("other_add_monster", this.on_other_add_monster, this);
@@ -58,6 +59,9 @@ export class MapMonsterComp extends CCComp {
}
protected update(dt: number): void {
if(smc.vm_data.game_over){
return
}
if(this.setp_timer.update(dt)){
this.monster_refresh()
}

View File

@@ -12,7 +12,7 @@ const { ccclass, property } = _decorator;
export class BoxRangComp extends CCComp {
Hero_node: any=null!;
MonViewComp:MonViewComp = null!;
box_group:number = BoxSet.DEFAULT;
box_group:number = BoxSet.MONSTER;
box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 300;
atk_range:number = 150;

View File

@@ -32,7 +32,7 @@ export class MonBuffComp extends CCComp {
timer:Timer = new Timer(0.1);
buffs:any=[];
group:number=0;
group:number=BoxSet.MONSTER;
/**
skill_uuid:number=0;
atk:number=0;

View File

@@ -17,45 +17,67 @@ const { ccclass, property } = _decorator;
export class MonSpine extends Component {
@property(Animation)
animator: Animation = null!;
idle_clip: AnimationClip = null!;
atk_clip: AnimationClip = null!;
max_clip: AnimationClip = null!;
move_clip: AnimationClip = null!;
default_clip:string = "idle";
onLoad() {
// 角色控制组件
this.initAnimator();
LayerUtil.setNodeLayer(LayerUtil.MAP, this.node);
this.idle_clip = this.animator.clips[0];
this.atk_clip = this.animator.clips[1];
this.move_clip = this.animator.clips[0];
this.max_clip = this.animator.clips[2];
this.move_clip = this.animator.clips[3];
let animation = this.animator.getComponent(Animation);
animation.on(Animation.EventType.FINISHED, this.onAnimationEvent, this)
}
/** 初始化动画 */
protected initAnimator() {
this.animator=this.node.getChildByName("mon").getComponent(Animation);
this.animator=this.node.getChildByName("anm").getComponent(Animation);
// console.log("mon spine init",this.animator);
}
onAnimationEvent(type: Animation.EventType, state: AnimationState){
if(type==Animation.EventType.FINISHED){
if(state.name==this.atk_clip.name){
this.move();
if(state.name==this.atk_clip.name||state.name==this.max_clip.name){
this.default();
}
}
}
change_default(value:string){
this.default_clip=value;
this.animator.play(this.default_clip);
}
default() {
this.animator.play(this.default_clip);
}
idle(){
if(!this.animator.getState(this.idle_clip.name).isPlaying){
this.animator.play(this.idle_clip.name);
}
}
atk() {
if(!this.animator.getState(this.atk_clip.name).isPlaying){
this.animator.play(this.atk_clip.name);
}
}
max(){
if(!this.animator.getState(this.max_clip.name).isPlaying){
this.animator.play(this.max_clip.name);
}
}
move(){
if(!this.animator.getState(this.move_clip.name).isPlaying){
this.animator.play(this.move_clip.name);
}
}
onDestroy() {
this.node.destroy();
}

View File

@@ -1,72 +0,0 @@
/*
* @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 MonSpineAnimator extends Component {
private animName: string = "move";
private loop: boolean = true;
private spine!: sp.Skeleton;
start() {
this.spine = this.getComponent(sp.Skeleton)!;
// console.log("MonSpineAnimator 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 == "atk2" ||animationName == "magic"||animationName=="max") {
this.spine.setAnimation(0, "move", true);
}
});
}
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("MonSpineAnimator playAnimation");
if (animName) {
// console.log("MonSpineAnimator playAnimation animName", animName);
this.animName = animName;
this.loop = loop;
this.spine.setAnimation(0, this.animName, this.loop);
}
else {
}
}
}

View File

@@ -75,7 +75,7 @@ export class MonViewComp extends CCComp {
shield_max:number = 200;
shield_time:number = 0; //护盾持续时间
box_group:number = 2;
box_group:number = BoxSet.MONSTER;
atk_range:number = 150;
private timer:Timer = new Timer(1); //计时器
private m_timer:Timer = new Timer(0.1);
@@ -91,7 +91,7 @@ export class MonViewComp extends CCComp {
} /** 视图层逻辑代码分离演示 */
start () {
this.as.move()
this.sprite = this.node.getChildByName("mon").getComponent(Sprite);
this.sprite = this.node.getChildByName("anm").getComponent(Sprite);
// this.node.getChildByName("top").setScale(this.scale,1);
// this.node.getChildByName("atk").setScale(this.scale,1);
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5e2825cf-c282-4297-be1f-631d2dc3bec5",
"uuid": "f7b9c48b-c4ed-4641-9f2f-ab5b317e7f0c",
"files": [],
"subMetas": {},
"userData": {}