技能开始

This commit is contained in:
2025-01-03 16:43:03 +08:00
parent df8738bd84
commit 0524eee5e0
21 changed files with 1347 additions and 233 deletions

View File

@@ -0,0 +1,49 @@
import { _decorator, Component, Node, tween, v3, Vec3 } from 'cc';
import { SkillCom } from './SkillCom';
const { ccclass, property } = _decorator;
@ccclass('BezCom')
export class BezCom extends Component {
start() {
let base =this.node.getComponent(SkillCom)
if(this.node.parent.scale.x < 0){
base.t_pos.x=base.t_pos.x*-1
}
let s_pos = v3(this.node.position.x,this.node.position.y)
let c_pos = v3((base.t_pos.x+this.node.position.x)/2,this.node.position.y+100)
let e_pos = v3(this.node.position.x+base.t_pos.x,this.node.position.y+base.t_pos.y)
let time =Math.abs(base.t_pos.x/base.speed)
BezCom.bezierTo(this.node,time,s_pos,c_pos,e_pos,{
onComplete: (target?: object) => {
base.is_destroy=true
},
}).start();
}
update(deltaTime: number) {
}
public static bezierTo(target: any, duration: number, c1: Vec3, c2: Vec3, to: Vec3, opts: any) {
opts = opts || Object.create(null);
/*
* @desc 二阶贝塞尔
* @param {number} t 当前百分比
* @param {} p1 起点坐标
* @param {} cp 控制点
* @param {} p2 终点坐标
* @returns {any}
*/
let twoBezier = (t:number, p1: Vec3, cp: Vec3, p2: Vec3) => {
let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
return v3(x, y, 0);
};
opts.onUpdate = (arg: Vec3, ratio: number) => {
target.position = twoBezier(ratio, c1, c2, to);
};
return tween(target).to(duration, {}, opts);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "5ebc6679-2a71-424f-bacf-48f20949fbd3",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,33 @@
import { _decorator, Component, Node, tween, v3, Vec3 } from 'cc';
import { SkillCom } from './SkillCom';
const { ccclass, property } = _decorator;
@ccclass('LineCom')
export class LineCom extends Component {
start() {
let base =this.node.getComponent(SkillCom)
let time = 720 / base.speed;
let squaredDistance = base.t_pos.x * base.t_pos.x + base.t_pos.y * base.t_pos.y;
let distance = Math.sqrt(squaredDistance);
time = distance / base.speed;
let e_pos=v3(this.node.position.x+base.t_pos.x,this.node.position.y+base.t_pos.y)
// console.log("skill tx:"+e_pos.x+" node :"+this.node.position.x)
this.node.getChildByName("skill").setRotationFromEuler(0,0,base.angle)
// console.log("skill ",this.node.getRotation())
tween(this.node).to( time,{ position: e_pos},
{
easing: "linear",
onUpdate: (target: Vec3, ratio: number) => { },
onComplete: (target?: object) => {
base.is_destroy=true
},
}
).start();
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "2050354e-73b6-40f3-8b1b-a7c1bbda9c59",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,24 @@
import { _decorator, Component, Node, tween, Vec3 } from 'cc';
import { SkillCom } from './SkillCom';
const { ccclass, property } = _decorator;
@ccclass('NoRunCom')
export class NoRunCom extends Component {
start() {
let base =this.node.getComponent(SkillCom)
tween(this.node).to( base.in_time,
{ position: new Vec3(this.node.position.x,this.node.position.y) },
{
onComplete: (target?: object) => {
base.is_destroy=true
},
}
).start();
}
update(deltaTime: number) {
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "3a728fd7-22ba-4bcf-bb88-588390346a31",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -30,7 +30,6 @@ export class Skill extends ecs.Entity {
var node = instantiate(prefab);
pos=v3(pos.x,pos.y)
node.parent = parent;
//转换pos为世界坐标
node.setPosition(pos)
var sv = node.getComponent(SkillCom)!;
let angle=0
@@ -47,16 +46,8 @@ export class Skill extends ecs.Entity {
sv.is_crit=is_crit
sv.crit_add=crit_add
// node.setScale(v3(node.scale.x*scale,node.scale.y))
sv.speed=SkillSet[uuid].speed;
sv.dis=SkillSet[uuid].dis;
sv.run_type=SkillSet[uuid].run;
if(sv.dis == 0){
sv.run_type=2
}
sv.in_time=SkillSet[uuid].in;
sv.t_pos = t_pos; // 目标增量
sv.type = SkillSet[uuid].type;
sv.box_tag= BoxSet.SKILL_TAG;

View File

@@ -12,16 +12,8 @@ const { ccclass, property } = _decorator;
@ccclass('SkillCom')
@ecs.register('SkillView', false)
export class SkillCom extends CCComp {
/** 视图层逻辑代码分离演示 */
// start() {
// // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// // this.on(ModuleEvent.Cmd, this.onHandler, this);
// }
s_uuid:number = 0;
speed:number = 200;
y_speed:number = 0;
x_speed:number = 0;
dis:number = 80;
scale:number = 1;
ap:number = 10;
atk_count:number = 0;
@@ -33,21 +25,11 @@ export class SkillCom extends CCComp {
box_group:number = 0;
box_tag:number=0;
type:number = 1;
time:Timer = new Timer(0.01);
run_type:number = 0; // 0有目标 带方向1贝塞尔曲线 2 不动 ,3 直线
in_time:number = 0.3; // 不动技能持续时间
start() {
console.log("skill start run_type:",this.run_type)
if(this.node.parent.scale.x < 0){
this.t_pos.x=this.t_pos.x*-1
}
this.x_speed=Math.cos(this.angle * Math.PI / 180) * this.speed-30*this.scale;
this.y_speed=Math.sin(this.angle * Math.PI / 180) * this.speed;
this.node.active=true
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
collider.sensor = true;
if (collider) {
@@ -56,125 +38,33 @@ export class SkillCom extends CCComp {
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
if(this.run_type == 3){ //直线,默认直线
let tx=this.node.position.x+this.dis
// console.log("skill tx:"+tx+" node :"+this.node.position.x)
let e_pos=v3(tx,this.node.position.y)
tween(this.node).to( 0.2,{ position: e_pos},
{onComplete: (target?: object) => { this.is_destroy=true },}
).start();
}
if(this.run_type == 0){ //直线,默认直线,有特定目标 朝向目标直线
let time = 720 / this.speed;
let squaredDistance = this.t_pos.x * this.t_pos.x + this.t_pos.y * this.t_pos.y;
let distance = Math.sqrt(squaredDistance);
time = distance / this.speed;
let e_pos=v3(this.node.position.x+this.t_pos.x,this.node.position.y+this.t_pos.y)
// console.log("skill tx:"+e_pos.x+" node :"+this.node.position.x)
this.node.getChildByName("skill").setRotationFromEuler(0,0,this.angle)
// console.log("skill ",this.node.getRotation())
tween(this.node).to( time,{ position: e_pos},
{
easing: "linear",
onUpdate: (target: Vec3, ratio: number) => { },
onComplete: (target?: object) => {
this.is_destroy=true
},
}
).start();
}
// console.log("skill run_type",this.run_type)
if(this.run_type == 1){ //贝塞尔曲线
// console.log("skill bezierTo",this.t_pos)
let s_pos = v3(this.node.position.x,this.node.position.y)
let c_pos = v3((this.t_pos.x+this.node.position.x)/2,this.node.position.y+100)
let e_pos = v3(this.node.position.x+this.t_pos.x,this.node.position.y+this.t_pos.y)
let time =Math.abs(this.t_pos.x/this.speed)
SkillCom.bezierTo(this.node,time,s_pos,c_pos,e_pos,{
onComplete: (target?: object) => {
this.is_destroy=true
},
}).start();
}
if(this.run_type == 2){ //原地不动的
tween(this.node).to( this.in_time,
{ position: new Vec3(this.node.position.x,this.node.position.y) },
{
onComplete: (target?: object) => {
this.is_destroy=true
},
}
).start();
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.group != selfCollider.group&&otherCollider.tag ==0){
this.atk_count+=1
// console.log("skill onBeginContact",selfCollider.group,otherCollider.group)
if(this.type==1 ){
this.is_destroy=true
}
// if(this.type==1 ){
// this.is_destroy=true
// }
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
}
update(deltaTime: number) {
this.toDestroy()
}
t_move(dt: number){
if( this.run_type!=0){
return
}
this.node.setPosition(v3(this.node.position.x+this.x_speed*dt*this.scale,this.node.position.y+this.y_speed*dt))
}
line_move(dt: number) {
if( this.run_type!=0 && this.t_pos){
return
}
this.node.setPosition(v3(this.node.position.x+dt*this.speed*this.scale,this.node.position.y))
}
bezier(t:number){
}
toDestroy() {
if(this.is_destroy){
this.ent.destroy()
}
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.is_destroy=false
this.node.destroy();
}
public static bezierTo(target: any, duration: number, c1: Vec3, c2: Vec3, to: Vec3, opts: any) {
opts = opts || Object.create(null);
/*
* @desc 二阶贝塞尔
* @param {number} t 当前百分比
* @param {} p1 起点坐标
* @param {} cp 控制点
* @param {} p2 终点坐标
* @returns {any}
*/
let twoBezier = (t:number, p1: Vec3, cp: Vec3, p2: Vec3) => {
let x = (1 - t) * (1 - t) * p1.x + 2 * t * (1 - t) * cp.x + t * t * p2.x;
let y = (1 - t) * (1 - t) * p1.y + 2 * t * (1 - t) * cp.y + t * t * p2.y;
return v3(x, y, 0);
};
opts.onUpdate = (arg: Vec3, ratio: number) => {
target.position = twoBezier(ratio, c1, c2, to);
};
return tween(target).to(duration, {}, opts);
}
}

View File

@@ -26,22 +26,26 @@ export class baseCom extends Component {
in_time:number = 0.3; // 不动技能持续时间
start() {
console.log("baseCom start")
// let collider = this.getComponent(Collider2D);
// collider.group = this.box_group;
// collider.tag = this.box_tag;
// collider.sensor = true;
// if (collider) {
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
// // collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
// }
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
collider.sensor = true;
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
}
onPostSolve(selfCollider: Collider2D, otherCollider: Collider2D){
if(otherCollider.group != selfCollider.group&&otherCollider.tag ==0){
this.atk_count+=1
// console.log("skill onBeginContact",selfCollider.group,otherCollider.group)
if(this.type==1 ){
this.is_destroy=true
}
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
}
reset() {