需要修复 英雄目标错误

This commit is contained in:
2024-09-18 17:45:23 +08:00
parent 2ab7279b04
commit 01ad8b619e
17 changed files with 834 additions and 1723 deletions

View File

@@ -18,7 +18,7 @@ const { ccclass, property } = _decorator;
export class RoleSpine extends Component {
private loop: boolean = true;
private spine!: sp.Skeleton;
private default:string = "move";
private default:string = "idle";
private atk_name: string = "atk";
private move_name: string = "move";
private max_name: string = "max";
@@ -32,17 +32,16 @@ export class RoleSpine extends Component {
this.spine = this.node.getChildByName("anm")!.getComponent(sp.Skeleton);
this.spine.setEndListener(trackEntry => {
var animationName = trackEntry.animation ? trackEntry.animation.name : "";
console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
// if (animationName == "atk" || animationName== "max" ) {
// this.spine.setAnimation(0, this.default, true);
// }
// console.log("[track %s][animation %s] end.", trackEntry.trackIndex, animationName);
if (animationName == "atk" || animationName== "max" ) {
this.spine.setAnimation(0, this.default, true);
}
});
}
protected play(animName: string, loop: boolean) {
}
atk(){
this.spine.setAnimation(0, this.atk_name, false);
}
idle(){

View File

@@ -91,7 +91,7 @@ export class RoleViewComp extends CCComp {
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
is_atking:boolean = false;
type:number = 0;
onLoad() {
// this.BoxRang = this.node.getChildByName("range_box");
this.as = this.node.getComponent(RoleSpine);
@@ -182,7 +182,8 @@ export class RoleViewComp extends CCComp {
this.check_buff_atks(dt)
this.in_shield(dt);
this.in_stop(dt);
this.in_atk(dt);
this.atk_time += dt;
this.in_atk();
// this.move();
this.check_enemys()
}
@@ -259,7 +260,7 @@ export class RoleViewComp extends CCComp {
return false
}
}
in_atk(dt: number) {
in_atk() {
if(this.atk_time >= this.atk_cd){
// if(this.is_atking&&this.check_enemy_alive()){
// this.atk_time = 0;
@@ -273,11 +274,10 @@ export class RoleViewComp extends CCComp {
this.as.atk();
this.scheduleOnce(()=>{
this.shoot(this.skill,-30);
},0.4)
}else{
this.atk_time += dt;
},0.2)
}
}
hp_change(hp: number){
if(this.is_dead){
return;

View File

@@ -44,43 +44,32 @@ export class SingletonModuleComp extends ecs.Comp {
{x:-BoxSet.CSKILL_X+110,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X+165,y:BoxSet.CSKILL_Y+55,eid:0},
];
role_heros: any = [
{x:BoxSet.ROLE_FUX,y:50,eid:0},
{x:BoxSet.ROLE_FUX,y:0,eid:0},
{x:BoxSet.ROLE_FUX,y:-50,eid:0},
{x:BoxSet.ROLE_FUX+40,y:50,eid:0},
{x:BoxSet.ROLE_FUX+40,y:0,eid:0},
{x:BoxSet.ROLE_FUX+40,y:-50,eid:0},
{x:BoxSet.ROLE_BUX,y:50,eid:0},
{x:BoxSet.ROLE_BUX,y:0,eid:0},
{x:BoxSet.ROLE_BUX,y:-50,eid:0},
{x:BoxSet.ROLE_BUX-40,y:50,eid:0},
{x:BoxSet.ROLE_BUX-40,y:0,eid:0},
{x:BoxSet.ROLE_BUX-40,y:-50,eid:0},
];
monster_buffs: any = [];
/** 游戏主角 */
Role: Role = null;
t_monster:any={eid:0,pos:v3(0,0,0)};
t_hero:any={eid:0,pos:v3(0,0,0)};
/** 游戏数据 */
// data:data = null!;
/**怪物数据 数组 */
/**heros 数据 */
heros:any = [];
monsters:any = [];
skills:any = []
sk_info:any = []
monsters_dead:any = []
heros_dead:any = []
least_hp_monster_eid:number=0;
least_hp_monster_hp:number=1000;
least_hp_hero_eid:number=0;
least_hp_hero_hp:number=1000;
hero_pos:any=[
{x:-320,y:70},
{x:-320,y:0},
{x:-320,y:-70},
{x:-320,y:0},
{x:-320,y:0},
{x:-320,y:0},
]
enemy_pos:any =[
{x:320,y:70},
{x:320,y:0},
{x:320,y:-70},
{x:320,y:0},
{x:320,y:0},
{x:320,y:0},
]
vm_data: any = {
name : "纸片精灵大乱斗",
game_over:false,

View File

@@ -1,11 +1,8 @@
export const MissionNum = [1,2]
export const MissionNum = [1]
export const MonsetList = {
1:{
1:[1031,1032,1033,1011,1012,1013],
},
2:{
1:[1011,1012,1013,1031,1032,1033,],
},
}
}

View File

@@ -10,7 +10,7 @@ export const HeroSet = {
max_skill: "精准打击", skill_uuid: 9001, max_skill_uuid: 2003, word: "守护", info: "自身护盾", atktype: 1,
},
9011: {
uuid: 9004, path: "m1", type: 1, level: 1,cost:2, name: "冰法", atk: 15, hp: 20, atk_dis: 300, atk_cd: 2.5, power: 0, power_max: 10, speed: 30,
uuid: 9004, path: "m1", type: 3, level: 1,cost:2, name: "冰法", atk: 15, hp: 20, atk_dis: 300, atk_cd: 2.5, power: 0, power_max: 10, speed: 30,
max_skill: "寒冰箭", skill_uuid: 9002, max_skill_uuid: 1002, word: "守护", info: "自身护盾", atktype: 1,
},
9021: {
@@ -25,7 +25,7 @@ export const HeroSet = {
9041: {
uuid: 9009, path: "arc1", type: 3, level: 1,cost:2, name: "弓箭手", atk: 5, hp: 30, atk_dis: 200, atk_cd: 1.5, power: 0, power_max: 10, speed: 30,
uuid: 9009, path: "arc1", type: 2, level: 1,cost:2, name: "弓箭手", atk: 5, hp: 30, atk_dis: 200, atk_cd: 1.5, power: 0, power_max: 10, speed: 30,
max_skill: "精准射击", skill_uuid: 9003, max_skill_uuid: 1003, word: "狂暴", info: "全体攻击", atktype: 2
},

View File

@@ -58,21 +58,22 @@ export class Hero extends ecs.Entity {
hero_init(uuid:number=1001,node:Node,index:number=-1){
var hv = node.getComponent(HeroViewComp)!;
// console.log("hero_init",buff)
hv.speed =hv.ospeed = smc.heros[uuid].speed;
hv.hero_name= smc.heros[uuid].name;
hv.hp= hv.hp_max = smc.heros[uuid].hp;
hv.level = smc.heros[uuid].level;
hv.atk = smc.heros[uuid].atk;
hv.atk_cd = smc.heros[uuid].atk_cd;
hv.atk_dis = smc.heros[uuid].atk_dis;
hv.power = smc.heros[uuid].power;
hv.power_max= smc.heros[uuid].power_max;
hv.type = smc.heros[uuid].type;
hv.skill_uuid = smc.heros[uuid].skill_uuid;
hv.max_skill_uuid = smc.heros[uuid].max_skill_uuid;
let hero_set= smc.heros[uuid]
hv.speed =hv.ospeed = hero_set.speed;
hv.hero_name= hero_set.name;
hv.hp= hv.hp_max = hero_set.hp;
hv.level = hero_set.level;
hv.atk = hero_set.atk;
hv.atk_cd = hero_set.atk_cd;
hv.atk_dis = hero_set.atk_dis;
hv.power = hero_set.power;
hv.power_max= hero_set.power_max;
hv.type = hero_set.type;
hv.skill_uuid = hero_set.skill_uuid;
hv.max_skill_uuid = hero_set.max_skill_uuid;
hv.scale = 1;
hv.role_heros_index = index;
hv.Tpos = v3(0,0,0);
hv.type = hero_set.type;
this.add(hv);
}
set_ratio(uuid:number){

View File

@@ -5,7 +5,7 @@
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math} 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 { HeroSpine } from "./HeroSpine";
@@ -36,8 +36,8 @@ export class HeroViewComp extends CCComp {
@property(Material)
atkMaterial: Material;
@property(Node)
BoxRang:Node =null!
// @property(Node)
// BoxRang:Node =null!
is_role:boolean = false;
enemy_pos:Vec3=null!;
@@ -106,8 +106,8 @@ export class HeroViewComp extends CCComp {
// this.node.getChildByName("hp_max").setScale(this.scale,1);
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
// this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
// this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
// this.BoxRang.getComponent(BoxRangComp).offset_x = 300;
// console.log("monseter ",this.BoxRang);
// console.log("monseter ",this.BoxRang);
@@ -148,15 +148,24 @@ export class HeroViewComp extends CCComp {
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&selfCollider.tag==otherCollider.tag){
if(selfCollider.node.position.y < otherCollider.node.position.y){
if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
// console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
}
if(otherCollider.node.name=="role") return
let self_x = selfCollider.node.position.x;
let other_x = otherCollider.node.position.x;
if(otherCollider.node.getComponent(HeroViewComp).type == this.type && self_x < other_x && Math.abs(other_x-self_x) < 15 ){
this.stop_cd = 0.1;
}
// if(selfCollider.node.position.y < otherCollider.node.position.y){
// if(selfCollider.node.getSiblingIndex() < otherCollider.node.getSiblingIndex()){
// selfCollider.node.setSiblingIndex(otherCollider.node.getSiblingIndex()+1)
// // console.log("onPreSolve b:"+selfCollider.node.uuid+":"+selfCollider.node.getSiblingIndex()+"/"+otherCollider.node.uuid+":"+otherCollider.node.getSiblingIndex());
// }
// }
}
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
this.stop_cd = 0.1;
this.is_atking=true
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
@@ -171,7 +180,10 @@ export class HeroViewComp extends CCComp {
this.check_buff_atks(dt)
this.in_shield(dt);
this.in_stop(dt);
this.atk_time += dt;
this.check_enemy_alive()
this.in_atk(dt);
this.hp_show()
// this.in_speek(dt);
this.move(dt);
@@ -200,7 +212,7 @@ export class HeroViewComp extends CCComp {
this.node.getChildByName("top").getChildByName("hp").active = true;
}
}
move_to(){
move_to(target:any){
// if(this.stop_cd > 0){
// return
// }
@@ -208,13 +220,13 @@ export class HeroViewComp extends CCComp {
// return
// }
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
move.target = v3(smc.Role.RoleView.node.position.x+smc.role_heros[this.role_heros_index].x,smc.Role.RoleView.node.position.y+smc.role_heros[this.role_heros_index].y);
move.target = v3(target.x,target.y);
move.node = this.node;
move.speed = this.ospeed;
}
power_change(power: number){
this.power += power;
if(this.power >= this.power_max&&this.check_enemy_alive()){
if(this.power >= this.power_max){
this.as.atk()
// this.to_speek(smc.skills[this.max_skill_uuid].name)
this.scheduleOnce(()=>{
@@ -230,25 +242,23 @@ export class HeroViewComp extends CCComp {
}
get_enemy_pos(){
let pos =this.skill_pos()
let t_pos:Vec3 = v3(720,BoxSet.GAME_LINE)
let t_pos:Vec3 = v3(720,0)
if(this.enemy){
if(!this.enemy.isValid){
console.log("move_to",this.enemy.isValid);
return
}
t_pos = v3(this.enemy.position.x-this.node.position.x,this.enemy.position.y-(this.node.position.y+pos.y)+BoxSet.ATK_Y)
t_pos = v3(this.enemy.x-this.node.position.x,this.enemy.y-(this.node.position.y+pos.y))
}
console.log("get_hero_pos",this.enemy,this.node.position,t_pos);
return {pos,t_pos}
}
get_hero_pos(hero:any){
let pos =this.skill_pos()
let t_pos:Vec3 = v3(720,BoxSet.GAME_LINE)
let t_pos:Vec3 = v3(720,0)
if(!hero.HeroView.node.isValid){
console.log("hero.heroView.node.isValid",hero.HeroView);
return
}else{
t_pos = v3(hero.HeroView.node.position.x-this.node.position.x,hero.HeroView.node.position.y-(this.node.position.y+pos.y)+BoxSet.ATK_Y)
t_pos = v3(hero.HeroView.node.position.x-this.node.position.x,hero.HeroView.node.position.y-(this.node.position.y+pos.y))
}
return {pos,t_pos}
}
shoot_enemy(skill_uuid:number,y:number=0,x:number=0){
@@ -256,6 +266,7 @@ export class HeroViewComp extends CCComp {
let skill = ecs.getEntity<Skill>(Skill);
let atk = smc.skills[skill_uuid].atk+this.atk+this.buff_atk;
let {pos,t_pos}=this.get_enemy_pos()
pos.y=pos.y + y
pos.x=pos.x + x
skill.load(pos,BoxSet.HERO,this.node,skill_uuid,atk,t_pos);
@@ -348,19 +359,26 @@ export class HeroViewComp extends CCComp {
}
check_enemy_alive(){
if(this.enemy){
if(!this.enemy.isValid){
return false
let dir = 320
for (let i = 0; i <= 2; i++) {
let mon:any = smc.enemy_pos[i];
let squaredDistance =mon.x*mon.x+mon.y*mon.y
let distance = Math.sqrt(squaredDistance);
if(distance < dir){
dir = distance
this.enemy = mon
}
if(Math.abs(this.enemy.position.x-this.node.position.x) < this.atk_dis) return true;
return false
}
if(dir < this.atk_dis){
this.is_atking=true
}else{
return false
this.is_atking=false
}
}
in_atk(dt: number) {
if(this.atk_time >= this.atk_cd){
if(this.is_atking&&this.check_enemy_alive()){
if(this.is_atking){
this.atk_time = 0;
// console.log("atk_cd:"+this.atk_cd);
this.as.atk();
@@ -368,8 +386,6 @@ export class HeroViewComp extends CCComp {
this.handle_skill(this.skill_uuid)
},0.4)
}
}else{
this.atk_time += dt;
}
}
@@ -407,7 +423,6 @@ export class HeroViewComp extends CCComp {
if(this.hp <= 0){
this.dead();
this.is_dead = true;
// smc.role_heros[this.role_heros_index].eid == 0
setTimeout(() => {
this.ent.destroy();
}, 15);

View File

@@ -34,11 +34,13 @@ export class MapMonsterComp extends CCComp {
mission_list:any = []
setp_timer: Timer = new Timer(0.3);
target_timer: Timer = new Timer(0.1);
setp_num:number = 5;
setp_num:number = 6;
game_over:boolean = false;
start_ys:any[] = [70,0,-70];
hero_start_ys:any[] = [35,-35];
mon_index:number = 0
hero_index:number = 0
line:number=BoxSet.GAME_LINE
onLoad(){
// 监听全局事件
oops.message.on("other_add_monster", this.on_other_add_monster, this);
@@ -65,13 +67,14 @@ export class MapMonsterComp extends CCComp {
this.monster_refresh()
}
if (this.refresh_timer.update(dt)) {
this.setp_num = 5
this.setp_num = 6
}
if (this.mission_up_timer.update(dt)) {
// 刷新怪物定时器
this.cur_count += 1;
}
this.count_hero_pos()
this.count_mon_pos()
// if (this.game_timer.update(dt)) {
// smc.vm_data.game.g_time += 1;
// }
@@ -83,6 +86,56 @@ export class MapMonsterComp extends CCComp {
count = list.length
return count;
}
count_mon_pos(){
let monsters:any= ecs.query(ecs.allOf(MonModelComp));
let x = 320
let x1 = 320
let x2 = 320
for(let i=0;i<monsters.length;i++){
if(monsters[i].MonView == undefined) return
let mon:any = monsters[i].MonView.node.position
if(mon.x < x&&mon.y == (this.line +70)){
x = mon.x
continue
}
if(mon.x < x1&&mon.y == this.line){
x1 = mon.x
continue
}
if(mon.x < x2&&mon.y == (this.line -70)){
x2 = mon.x
continue
}
}
smc.enemy_pos[0].x=x
smc.enemy_pos[1].x=x1
smc.enemy_pos[2].x=x2
}
count_hero_pos(){
let heros:any= ecs.query(ecs.allOf(HeroModelComp));
let x = -320
let x1 = -320
let x2 = -320
for(let i=0;i<heros.length;i++){
if(heros[i].HeroView == undefined) return
let ho:any = heros[i].HeroView.node.position
if(ho.x > x&&ho.y == (this.line +70)){
x = ho.x
continue
}
if(ho.x > x1&&ho.y == this.line ){
x1 = ho.x
continue
}
if(ho.x > x2&&ho.y == (this.line -70)){
x2 = ho.x
continue
}
}
smc.hero_pos[0].x=x
smc.hero_pos[1].x=x1
smc.hero_pos[2].x=x2
}
load_role(){
let role = ecs.getEntity<Role>(Role);
let pos = v3(BoxSet.HERO_START+50,BoxSet.GAME_LINE)
@@ -97,23 +150,28 @@ export class MapMonsterComp extends CCComp {
private addHero(uuid:number=1001) {
let hero = ecs.getEntity<Hero>(Hero);
var scene = smc.map.MapView.scene;
let oy=RandomManager.instance.getRandomByObjectList(this.start_ys,1)
let pos:Vec3 = v3(-280,BoxSet.GAME_LINE+oy[0]);
let pos:Vec3 = v3(-280,BoxSet.GAME_LINE+this.start_ys[2]);
let monster_layer = scene.entityLayer!.node!
let scale = 1
hero.load(pos,scale,uuid,monster_layer);
this.hero_index += 1
if(this.hero_index > 2){
this.hero_index = 0
}
}
monster_refresh(){
if (this.setp_num <= 0){
return
}
let m:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],1)
let m:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],3)
var scene = smc.map.MapView.scene;
let oy=RandomManager.instance.getRandomInt(-70,70,1)
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE+oy)
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE+this.start_ys[this.mon_index])
let monster_layer = scene.entityLayer!.node!
this.addMonster(m[0],monster_layer,pos)
this.mon_index += 1
if(this.mon_index>2){
this.mon_index = 0
}
this.setp_num -= 1
}
private addMonster(uuid:number=1001,layer:any,pos:Vec3=v3(0,0,0)) {