技能还有错误

This commit is contained in:
2024-08-21 17:55:15 +08:00
parent 76a7854e94
commit ee7f1c322b
7 changed files with 78 additions and 55 deletions

View File

@@ -287,7 +287,7 @@
"_restitution": 0, "_restitution": 0,
"_offset": { "_offset": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 15.2, "x": 1.2,
"y": 0.3 "y": 0.3
}, },
"_size": { "_size": {
@@ -328,7 +328,6 @@
"__id__": 0 "__id__": 0
}, },
"fileId": "c46/YsCPVOJYA4mWEpNYRx", "fileId": "c46/YsCPVOJYA4mWEpNYRx",
"instance": null, "instance": null
"targetOverrides": null
} }
] ]

View File

@@ -47,7 +47,7 @@ export const HeroSet ={
} }
export const SkillSet={ export const SkillSet={
1001:{uuid: 1001,path: "1001",type: 1,level: 1,name: "火球术-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,}, 1001:{uuid: 1001,path: "1001",type: 1,level: 1,name: "火球术-初级",sp_name:"fire",dis:1720,count:1,atk: 4,sd:10,cd:1,speed:400,},
1002:{uuid: 1002,path: "1002",type: 1,level: 1,name: "寒冰箭-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,}, 1002:{uuid: 1002,path: "1002",type: 1,level: 1,name: "寒冰箭-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,},
1003:{uuid: 1003,path: "1003",type: 1,level: 1,name: "狂暴-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,}, 1003:{uuid: 1003,path: "1003",type: 1,level: 1,name: "狂暴-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,},
1004:{uuid: 1004,path: "1004",type: 1,level: 1,name: "守护-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,}, 1004:{uuid: 1004,path: "1004",type: 1,level: 1,name: "守护-初级",sp_name:"fire",dis:720,count:1,atk: 4,sd:10,cd:1,speed:400,},

View File

@@ -34,7 +34,7 @@ export class CSkill extends ecs.Entity {
var scene = smc.map.MapView.scene; var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!; node.parent = scene.entityLayer!.node!;
node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z); node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
let cskills = ecs.query(ecs.allOf(CSkillComp)) // let cskills = ecs.query(ecs.allOf(CSkillComp))
for (let index = 1; index <= 8; index++) { for (let index = 1; index <= 8; index++) {
if(smc.player_buffs[index].eid == 0){ if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x pos.x=smc.player_buffs[index].x
@@ -44,7 +44,7 @@ export class CSkill extends ecs.Entity {
} }
} }
console.log("load skill",pos,smc.player_buffs) // console.log("load skill",pos,smc.player_buffs)
node.setPosition(pos.x*scale,pos.y,pos.z) node.setPosition(pos.x*scale,pos.y,pos.z)
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
const url = 'game/heros/skill'; const url = 'game/heros/skill';

View File

@@ -7,6 +7,7 @@ import { SkillSet } from "../common/config/CardSet";
import { Monster } from "./Monster"; import { Monster } from "./Monster";
import { MonsterModelComp } from "./MonsterModelComp"; import { MonsterModelComp } from "./MonsterModelComp";
import { MonsterViewComp } from "./MonsterViewComp"; import { MonsterViewComp } from "./MonsterViewComp";
import { BoxSet } from "../common/config/BoxSet";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
/** 视图层对象 */ /** 视图层对象 */
@@ -44,17 +45,30 @@ export class CSkillComp extends CCComp {
shoot() { shoot() {
let skill = ecs.getEntity<Skill>(Skill); let skill = ecs.getEntity<Skill>(Skill);
let pos = v3(0,0) let pos = v3(0,0)
let t_pos:Vec3=null let t_pos = v3(0,0)
let angle = 0
let m_pos=v3(0,0)
let monsters:any = ecs.query(ecs.allOf(MonsterModelComp)); let monsters:any = ecs.query(ecs.allOf(MonsterModelComp));
for (const monster of monsters) { if (monsters.length > 0) {
t_pos= monster.getComponent(MonsterViewComp).get_monster_pos() m_pos = monsters[0].MonsterView.get_monster_pos()
}else{
m_pos = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
} }
t_pos = v3(m_pos.x-this.node.position.x,m_pos.y-this.node.position.y)
// console.log("m_pos",this.node.position,m_pos);
let dx=m_pos.x-this.node.position.x
let dy=m_pos.y-this.node.position.y
let dir=v3(dx,dy,0)
let randian=Math.atan2(dir.y,dir.x)
angle = randian * (180 / Math.PI);
// console.log("angle",angle);
let scale = this.scale let scale = this.scale
let dis = SkillSet[this.skill_uuid].dis+this.dis; let dis = SkillSet[this.skill_uuid].dis+this.dis;
let atk = SkillSet[this.skill_uuid].atk+this.atk; let atk = SkillSet[this.skill_uuid].atk+this.atk;
let speed = SkillSet[this.skill_uuid].speed+this.speed; let speed = SkillSet[this.skill_uuid].speed+this.speed;
let sp_name = SkillSet[this.skill_uuid].sp_name let sp_name = SkillSet[this.skill_uuid].sp_name
skill.load(pos,speed,dis,scale,this.node,sp_name,atk,t_pos); skill.load(pos,speed,dis,scale,this.node,sp_name,atk,angle,t_pos);
} }
/** 全局消息逻辑处理 */ /** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) { // private onHandler(event: string, args: any) {

View File

@@ -28,7 +28,7 @@ export class Skill extends ecs.Entity {
this.remove(SkillCom); this.remove(SkillCom);
super.destroy(); 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 path = "game/skills/"+skill_name;
var prefab: Prefab = oops.res.get(path, Prefab)!; var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab); var node = instantiate(prefab);
@@ -42,6 +42,7 @@ export class Skill extends ecs.Entity {
sv.dis = dis; sv.dis = dis;
sv.scale = scale; sv.scale = scale;
sv.atk = atk; sv.atk = atk;
sv.angle = angle;
sv.t_pos = t_pos; sv.t_pos = t_pos;
if(scale == 1){ if(scale == 1){
sv.change_collider_group(BoxSet.HERO_SKILL) sv.change_collider_group(BoxSet.HERO_SKILL)

View File

@@ -16,26 +16,43 @@ export class SkillCom extends CCComp {
// // this.on(ModuleEvent.Cmd, this.onHandler, this); // // this.on(ModuleEvent.Cmd, this.onHandler, this);
// } // }
speed:number = 200; speed:number = 200;
y_speed:number = 0;
x_speed:number = 0;
dis:number = 80; dis:number = 80;
scale:number = 1; scale:number = 1;
atk:number = 10; atk:number = 10;
angle:number = 0;
t_pos:Vec3 = null; t_pos:Vec3 = null;
is_destroy:boolean = false; is_destroy:boolean = false;
start() { start() {
this.node.active=true 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); let collider = this.getComponent(Collider2D);
if (collider) { if (collider) {
// collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); // collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
} }
if(this.t_pos){ if(this.t_pos){
tween(this.node).to( 0.5,{ position: new Vec3(0, 10, 0) } ).start(); //通过欧拉角 延长 目标点位置
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.check_to_destroy()
},
} ).start();
}else{ }else{
tween(this.node).to( this.dis/this.speed, tween(this.node).to( this.dis/this.speed,
{ position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) }, { position: new Vec3(this.node.position.x+this.scale*this.dis,this.node.position.y) },
{ {
onComplete: (target?: object) => { onComplete: (target?: object) => {
this.toDestroy() this.check_to_destroy()
}, },
} }
).start(); ).start();
@@ -48,28 +65,17 @@ export class SkillCom extends CCComp {
case BoxSet.HERO_SKILL: case BoxSet.HERO_SKILL:
switch (otherCollider.group){ switch (otherCollider.group){
case BoxSet.MONSTER: case BoxSet.MONSTER:
if(this.is_destroy){ case BoxSet.DEFAULT:
return this.check_to_destroy()
}else{ break
this.is_destroy = true;
this.toDestroy();
}
// this.speed = 0;
// this.timer = 1;
// console.log("speed:"+this.speed+" | timer:"+this.timer);
break;
} }
break; break;
case BoxSet.MONSTER_SKILL: case BoxSet.MONSTER_SKILL:
switch (otherCollider.group){ switch (otherCollider.group){
case BoxSet.PLAYER: case BoxSet.PLAYER:
case BoxSet.HERO: case BoxSet.HERO:
if(!this.is_destroy){ case BoxSet.DEFAULT:
this.is_destroy = true; this.check_to_destroy()
this.toDestroy();
}
break break
} }
} }
@@ -83,23 +89,26 @@ export class SkillCom extends CCComp {
update(deltaTime: number) { update(deltaTime: number) {
// this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z)) // this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
this.move(deltaTime) this.move(deltaTime)
if(Math.abs(this.node.position.x) > this.dis) // if(Math.abs(this.node.position.x) > this.dis)
{ // {
if(this.is_destroy){ // this.check_to_destroy()
return
}else{
this.is_destroy = true;
this.toDestroy()
}
} // }
} }
move(dt: number) { 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) { // private onHandler(event: string, args: any) {
// switch (event) { // switch (event) {
@@ -109,16 +118,16 @@ export class SkillCom extends CCComp {
// } // }
toDestroy() { toDestroy() {
// this.node.active = false; // this.node.active = false;
var scene = smc.map.MapView.scene; // var scene = smc.map.MapView.scene;
this.node.parent = scene.entityLayer!.node!; // this.node.parent = scene.entityLayer!.node!;
// console.log("toDestroy"); // console.log("toDestroy");
if (this.node.isValid) {
// console.log("this.node.isValid"); // console.log("this.node.isValid");
setTimeout(() => { setTimeout(() => {
// console.log("SkillCom.node.destroy",this); // console.log("SkillCom.node.destroy",this);
this.ent.destroy() this.ent.destroy()
}, 10); }, 10);
}
} }
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */

View File

@@ -51,11 +51,11 @@
} }
], ],
"collisionMatrix": { "collisionMatrix": {
"0": 103, "0": 127,
"1": 55, "1": 55,
"2": 79, "2": 79,
"3": 36, "3": 37,
"4": 66, "4": 67,
"5": 11, "5": 11,
"6": 21 "6": 21
} }