修改了很多

This commit is contained in:
2025-03-27 23:25:10 +08:00
parent 3a15541170
commit 67704725b2
40 changed files with 9140 additions and 4253 deletions

View File

@@ -4,9 +4,10 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { GameEvent } from "../common/config/GameEvent";
import { AnimType, endType } from "../common/config/SkillSet";
import { AnimType, endType, SkillSet } from "../common/config/SkillSet";
import { EndAnmCom } from './EndAnmCom';
import { BoxSet } from "../common/config/BoxSet";
import { HeroFac, HeroSet } from "../common/config/heroSet";
const { ccclass, property } = _decorator;
@@ -38,6 +39,9 @@ export class SkillCom extends CCComp {
rigid:RigidBody2D=null!; // 动画名称
target:any=null;
caster:any=null;
distance_x:number=0;
distance_y:number=0;
private moveDirection: Vec3 | null = null; // 添加一个属性来存储移动方向
protected onLoad(): void {
@@ -60,6 +64,44 @@ export class SkillCom extends CCComp {
// this.rigid.wakeUp();
// }
// 根据动画类型开始相应的运动
let dir_x = this.target.node.position.x > this.node.position.x ? 1 : -1
this.node.scale = v3(dir_x,1,1)
// 根据目标位置设置节点朝向
if (this.target && this.target.node) {
// 计算朝向
let direction = this.target.node.position.x > this.node.position.x ? 1 : -1;
// 设置节点缩放来改变朝向
this.node.scale = v3(direction * Math.abs(this.scale), this.scale, 1);
}
let dir_y = (this.target.node.position.y+BoxSet.ATK_Y) > this.node.position.y ? 1 : -1
if(this.target.node.position.y+BoxSet.ATK_Y==this.node.position.y){
dir_y=0
}
// 计算这一帧的移动距离
this.distance_x = SkillSet[this.s_uuid].speed*dir_x;
this.distance_y = this.distance_x*Math.abs(this.target.node.position.y-this.node.position.y)/Math.abs(this.target.node.position.x-this.node.position.x)*dir_y;
this.startMovement();
// 计算目标角度
if (this.target && this.target.node) {
const targetPos = this.target.node.position;
const currentPos = this.node.position;
// 计算角度(弧度)
const dx = targetPos.x - currentPos.x;
const dy = (targetPos.y + BoxSet.ATK_Y) - currentPos.y;
const angle = Math.atan2(dy, dx);
// 将弧度转换为角度并设置节点旋转
this.angle = angle * 180 / Math.PI;
this.node.angle = this.angle; // 移除负号,修正角度方向
}
// 计算速度分量
const radians = this.angle * Math.PI / 180; // 移除负号,使用正确的角度
this.distance_x = this.speed * Math.cos(radians);
this.distance_y = this.speed * Math.sin(radians);
this.startMovement();
}
// onBeginContact (seCol: Collider2D, oCol: Collider2D) {
@@ -70,9 +112,6 @@ export class SkillCom extends CCComp {
private startMovement() {
switch(this.animType) {
case AnimType.linear:
this.startLinearMove();
break;
case AnimType.parabolic:
this.startBezierMove();
break;
@@ -88,19 +127,19 @@ export class SkillCom extends CCComp {
}
}
private startLinearMove() {
if(this.group==BoxSet.HERO){
this.targetPos.x=720
}else{
this.targetPos.x=-720
private startLinearMove(dt: number) {
if (!this.speed || this.is_destroy) return;
// 使用角度方向移动
const newX = this.node.position.x + this.distance_x * dt;
const newY = this.node.position.y + this.distance_y * dt;
this.node.setPosition(newX, newY, this.node.position.z);
// 检查是否超出边界
if (newX < -400 || newX > 400) {
this.is_destroy = true;
}
const duration = Vec3.distance(this.startPos, this.targetPos) / this.speed;
tween(this.node)
.to(duration, { position: this.targetPos })
.call(() => {
this.is_destroy = true;
})
.start();
}
private startBezierMove() {
@@ -191,6 +230,8 @@ export class SkillCom extends CCComp {
update(deltaTime: number) {
if(smc.mission.pause) return;
this.toDestroy();
this.startLinearMove(deltaTime);
}
toDestroy() {
if(this.is_destroy){
@@ -202,7 +243,7 @@ export class SkillCom extends CCComp {
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.is_destroy=false
this.is_destroy = false;
this.node.destroy();
this.animType = 0;
this.endType = 0;
@@ -210,6 +251,7 @@ export class SkillCom extends CCComp {
this.inTime = 0;
this.startPos.set();
this.targetPos.set();
this.moveDirection = null; // 重置移动方向
}
}