技能还有错误
This commit is contained in:
@@ -28,7 +28,7 @@ export class Skill extends ecs.Entity {
|
||||
this.remove(SkillCom);
|
||||
super.destroy();
|
||||
}
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,dis:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10,t_pos:Vec3 = null) {
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,dis:number = 50,scale:number = 1,parent:Node,skill_name:string = "base",atk:number =10,angle = 0,t_pos:Vec3 = null) {
|
||||
var path = "game/skills/"+skill_name;
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
@@ -42,6 +42,7 @@ export class Skill extends ecs.Entity {
|
||||
sv.dis = dis;
|
||||
sv.scale = scale;
|
||||
sv.atk = atk;
|
||||
sv.angle = angle;
|
||||
sv.t_pos = t_pos;
|
||||
if(scale == 1){
|
||||
sv.change_collider_group(BoxSet.HERO_SKILL)
|
||||
|
||||
@@ -16,29 +16,46 @@ export class SkillCom extends CCComp {
|
||||
// // this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
// }
|
||||
speed:number = 200;
|
||||
y_speed:number = 0;
|
||||
x_speed:number = 0;
|
||||
dis:number = 80;
|
||||
scale:number = 1;
|
||||
atk:number = 10;
|
||||
angle:number = 0;
|
||||
t_pos:Vec3 = null;
|
||||
is_destroy:boolean = false;
|
||||
start() {
|
||||
this.node.active=true
|
||||
this.node.angle = this.angle;
|
||||
//根据目标坐标、欧拉角、预设距离增量speed 来计算新的x增量,y增量
|
||||
// this.x_speed = Math.cos(this.angle * Math.PI / 180) * this.speed;
|
||||
// this.y_speed = Math.sin(this.angle * Math.PI / 180) * this.speed;
|
||||
|
||||
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
if(this.t_pos){
|
||||
tween(this.node).to( 0.5,{ position: new Vec3(0, 10, 0) } ).start();
|
||||
}else{
|
||||
tween(this.node).to( this.dis/this.speed,
|
||||
{ position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
|
||||
//通过欧拉角 延长 目标点位置
|
||||
this.t_pos.x=Math.cos(this.angle * Math.PI / 180) * this.dis;
|
||||
this.t_pos.y=Math.sin(this.angle * Math.PI / 180) * this.dis;
|
||||
tween(this.node).to( 1,{ angle:this.angle,position: this.t_pos},
|
||||
{
|
||||
onComplete: (target?: object) => {
|
||||
this.toDestroy()
|
||||
},
|
||||
}
|
||||
).start();
|
||||
onComplete: (target?: object) => {
|
||||
// this.check_to_destroy()
|
||||
},
|
||||
} ).start();
|
||||
}else{
|
||||
tween(this.node).to( this.dis/this.speed,
|
||||
{ position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
|
||||
{
|
||||
onComplete: (target?: object) => {
|
||||
this.check_to_destroy()
|
||||
},
|
||||
}
|
||||
).start();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -48,29 +65,18 @@ export class SkillCom extends CCComp {
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
|
||||
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
case BoxSet.DEFAULT:
|
||||
this.check_to_destroy()
|
||||
break
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.PLAYER:
|
||||
case BoxSet.HERO:
|
||||
if(!this.is_destroy){
|
||||
this.is_destroy = true;
|
||||
this.toDestroy();
|
||||
}
|
||||
break
|
||||
case BoxSet.DEFAULT:
|
||||
this.check_to_destroy()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,23 +89,26 @@ export class SkillCom extends CCComp {
|
||||
update(deltaTime: number) {
|
||||
// this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
|
||||
this.move(deltaTime)
|
||||
if(Math.abs(this.node.position.x) > this.dis)
|
||||
{
|
||||
if(this.is_destroy){
|
||||
return
|
||||
}else{
|
||||
this.is_destroy = true;
|
||||
this.toDestroy()
|
||||
}
|
||||
// if(Math.abs(this.node.position.x) > this.dis)
|
||||
// {
|
||||
// this.check_to_destroy()
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
move(dt: number) {
|
||||
// this.node.setPosition(v3(this.node.position.x+dt*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
||||
// this.node.setPosition(v3(this.node.position.x+dt*this.x_speed*this.scale,this.node.position.y+this.y_speed,this.node.position.z))
|
||||
}
|
||||
|
||||
|
||||
check_to_destroy(){
|
||||
if(!this.is_destroy){
|
||||
this.is_destroy = true;
|
||||
setTimeout(() => {
|
||||
this.toDestroy();
|
||||
}, 10);
|
||||
|
||||
}
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
@@ -109,16 +118,16 @@ export class SkillCom extends CCComp {
|
||||
// }
|
||||
toDestroy() {
|
||||
// this.node.active = false;
|
||||
var scene = smc.map.MapView.scene;
|
||||
this.node.parent = scene.entityLayer!.node!;
|
||||
// var scene = smc.map.MapView.scene;
|
||||
// this.node.parent = scene.entityLayer!.node!;
|
||||
// console.log("toDestroy");
|
||||
if (this.node.isValid) {
|
||||
|
||||
// console.log("this.node.isValid");
|
||||
setTimeout(() => {
|
||||
// console.log("SkillCom.node.destroy",this);
|
||||
this.ent.destroy()
|
||||
}, 10);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
|
||||
Reference in New Issue
Block a user