角色动画 确定

This commit is contained in:
walkpan
2024-08-26 07:33:26 +08:00
parent 68d7077e56
commit 4f96558d36
111 changed files with 54661 additions and 1391 deletions

View File

@@ -1,8 +1,9 @@
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact,v3, v2} from "cc";
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 { MonsterViewComp } from "./MonsterViewComp";
import { smc } from "../common/SingletonModuleComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@@ -19,44 +20,49 @@ export class BoxRangComp extends CCComp {
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
collider.offset = v2(this.offset_x,45);
// collider.offset = v2(this.offset_x,45);
this.Hero_node = this.node.parent;
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
// console.log("range box",this.MonsterViewComp);
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);
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("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.MonsterViewComp.is_atking = true;
if(Math.abs(otherCollider.node.position.x-selfCollider.node.position.x) < 120){
this.MonsterViewComp.stop_cd = 0.1
}
}
// 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.MonsterViewComp.is_atking = true;
// if(Math.abs(otherCollider.node.position.x-selfCollider.node.position.x) < 120){
// this.MonsterViewComp.stop_cd = 0.1
// }
// }
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
// console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.MonsterViewComp.is_atking = false;
}
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.MonsterViewComp.is_atking = true;
if(Math.abs(otherCollider.node.position.x-selfCollider.node.position.x) < 120){
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(Math.abs(other_pos.x-self_pos.x) < BoxSet.ATK_RANGE_X){
this.MonsterViewComp.stop_cd = 0.1
}
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}

View File

@@ -67,8 +67,7 @@ export class CSkillComp extends CCComp {
let dis = SkillSet[this.skill_uuid].dis+this.dis;
let atk = SkillSet[this.skill_uuid].atk+this.atk;
let speed = SkillSet[this.skill_uuid].speed+this.speed;
let sp_name = SkillSet[this.skill_uuid].sp_name
skill.load(pos,speed,dis,scale,this.node,sp_name,atk,angle,t_pos);
skill.load(pos,speed,dis,scale,this.node,this.skill_uuid,atk,angle,t_pos);
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {

View File

@@ -78,9 +78,7 @@ export class Hero extends ecs.Entity {
mv.change_name(smc.heros[uuid].name,1)
this.add(mv);
}
push_monsters_in(uuid:number=1001,eid:number=0){
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})
}
}

View File

@@ -32,6 +32,7 @@ export class Monster extends ecs.Entity {
}
destroy(): void {
this.remove(MonsterViewComp);
super.destroy();
}
@@ -66,16 +67,12 @@ export class Monster extends ecs.Entity {
mv.atk_cd = smc.heros[uuid].atk_cd;
mv.power = smc.heros[uuid].power;
mv.type = smc.heros[uuid].type;
mv.skill_uuid = 9002;
mv.skill_uuid = 9001;
mv.max_skill_uuid = smc.heros[uuid].max_skill_uuid;
mv.scale = -1;
mv.Tpos = v3(0,0,0);
mv.change_name(smc.heros[uuid].name,-1)
this.add(mv);
this.push_monsters_in(uuid,mv.ent.eid)
}
push_monsters_in(uuid:number=1001,eid:number=0){
smc.monsters_in.push({name:smc.heros[uuid].name,eid:eid})
}
}

View File

@@ -49,7 +49,7 @@ export class MonsterSpine extends Component {
this.spine.setAnimation(0, animName, loop);
}
atk() {
this.spine.setAnimation(0, "atk", false);
this.spine.setAnimation(0, "atk2", false);
}
setAlpha(value: number): void {
var color: Color = this.spine.color;

View File

@@ -47,7 +47,7 @@ export class MonsterViewComp extends CCComp {
hp_speed: number = 0; //每秒回复量
power: number = 0; /**能量**/
power_max: number = 100; /** 能量最大值 */
power_max: number = 600*3; /** 能量最大值 */
power_speed: number = 1; //能量回复速度每0.1秒回复量
skill_name: string = "base"; //技能名称
@@ -76,7 +76,7 @@ export class MonsterViewComp extends CCComp {
onLoad() {
this.as = this.getComponent(MonsterSpine);
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
// | EPhysics2DDrawFlags.Pair
// |EPhysics2DDrawFlags.CenterOfMass
// |EPhysics2DDrawFlags.Joint
@@ -89,7 +89,7 @@ export class MonsterViewComp extends CCComp {
this.BoxRang = this.node.getChildByName("range_box");
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*SkillSet[this.skill_uuid].dis-30;
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*SkillSet[this.skill_uuid].dis;
// console.log("monseter ",this.BoxRang);
// 注册单个碰撞体的回调函数
@@ -123,7 +123,7 @@ export class MonsterViewComp extends CCComp {
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE&&otherCollider.tag != BoxSet.SKILL_TAG){
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
this.is_atking = true;
this.stop_cd = 0.1;
}
@@ -132,25 +132,21 @@ export class MonsterViewComp extends CCComp {
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group == otherCollider.group){
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('monster view group 相同');
if(otherCollider.tag != BoxSet.SKILL_TAG){
let self_pos=selfCollider.node.getPosition();
let other_pos=otherCollider.node.getPosition();
if(selfCollider.group == BoxSet.HERO){
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
this.stop_cd=0.1
}
switch (selfCollider.group) {
case BoxSet.HERO:
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= BoxSet.MOVE_RANGE_X && self_pos.y==other_pos.y){
this.stop_cd=0.1
}
break;
case BoxSet.MONSTER:
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= BoxSet.MOVE_RANGE_X && self_pos.y==other_pos.y){
this.stop_cd=0.1
}
}
if(selfCollider.group == BoxSet.MONSTER){
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
this.stop_cd=0.1
}
}
}
}else{
// console.log('monster onPostSolve'+selfCollider.group+"|"+otherCollider.group);
}
@@ -178,7 +174,7 @@ export class MonsterViewComp extends CCComp {
this.in_stop(dt);
this.in_act(dt);
this.move(dt);
// this.update_pos();
}
@@ -191,7 +187,7 @@ export class MonsterViewComp extends CCComp {
* 如果角色属于正向阵营 (scale == 1) 且 x 轴位置大于等于 0则直接返回。
* 如果角色属于反向阵营 (scale != 1) 且 x 轴位置小于等于 0则直接返回。
*/
if ((this.scale === 1 && this.node.position.x >= 120) || (this.scale !== 1 && this.node.position.x <= -180)) {
if (this.scale === 1 && this.node.position.x >= 120) {
return;
}
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
@@ -213,12 +209,11 @@ export class MonsterViewComp extends CCComp {
let skill = ecs.getEntity<Skill>(Skill);
let x=32
let pos = v3(this.scale*32,30)
let speed =SkillSet[skill_uuid].speed;
let scale = this.scale
let speed =SkillSet[skill_uuid].speed;
let dis = SkillSet[skill_uuid].dis;
let atk = SkillSet[skill_uuid].atk+this.atk;
let sp_name = SkillSet[skill_uuid].sp_name;
skill.load(pos,speed,dis,scale,this.node,sp_name,atk);
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk);
}
in_act(dt: number) {
@@ -278,13 +273,6 @@ export class MonsterViewComp extends CCComp {
// break;
// }
}
update_pos(){
smc.monsters_in.forEach((element,index) => {
if(element.eid == this.ent.eid){
element.pos_x = this.node.position.x;
}
});
}
in_atked() {
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);