去掉物理碰撞组件,英雄的移动改由系统逻辑统一处理
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite, math, clamp, Game, tween} from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||
@@ -35,7 +34,7 @@ export class HeroViewComp extends CCComp {
|
||||
lv:number =1;
|
||||
slv:number =1;
|
||||
scale: number = 1; /** 角色阵营 1:hero -1 :mon */
|
||||
type: number = 0; /**角色类型 0近战 1 远程 2 辅助 */
|
||||
type: number = 0; /**角色类型 0近战-需要贴身 1远程-保持距离 2辅助 */
|
||||
fac:number=0; //阵营 0:hero 1:monster
|
||||
box_group:number = BoxSet.HERO;
|
||||
atk_range:number = 150;
|
||||
@@ -121,9 +120,7 @@ export class HeroViewComp extends CCComp {
|
||||
this.as = this.getComponent(HeroSpine);
|
||||
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
|
||||
start () {
|
||||
|
||||
this.as.idle()
|
||||
this.BUFFCOMP=this.node.getComponent(BuffComp);
|
||||
/** 方向 */
|
||||
@@ -133,72 +130,8 @@ export class HeroViewComp extends CCComp {
|
||||
this.node.setScale(this.node.scale.x*1.5,this.node.scale.y*1.5);
|
||||
this.node.getChildByName("top").getChildByName("sboss").active = true;
|
||||
}
|
||||
/** 显示角色血量 */
|
||||
/* 显示角色血量 */
|
||||
this.node.getChildByName("top").getChildByName("hp").active = true;
|
||||
|
||||
// this.node.getChildByName("shielded").active = false;
|
||||
// this.node.getChildByName("top").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").setScale(this.scale,1);
|
||||
// this.node.getChildByName("atk").getComponent(Label).string = this.ap.toString();
|
||||
// this.node.getChildByName("hp_max").setScale(this.scale,1);
|
||||
// this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
|
||||
|
||||
// 注册单个碰撞体的回调函数
|
||||
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
// console.log("hero collider ",this.scale,collider);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
// collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
|
||||
// collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
|
||||
if(oCol.tag==BoxSet.SKILL_TAG&&seCol.group != oCol.group){
|
||||
let skill = oCol.node.getComponent(SkillCom)!;
|
||||
// console.log(Date.now()+this.hero_name+":"+this.uuid+' onBeginContact: '+skill.s_name+skill.uuid);
|
||||
if(this.hp <= 0 ) return
|
||||
if(skill.tg< 3) return
|
||||
this.check_uatk(skill);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onEndContact (seCol: Collider2D, oCol: Collider2D) {
|
||||
|
||||
}
|
||||
onPreSolve (seCol: Collider2D, oCol: Collider2D) {
|
||||
let se_x = seCol.node.position.x;
|
||||
let ot_x = oCol.node.position.x;
|
||||
let oCom= oCol.node.getComponent(HeroViewComp)
|
||||
if(seCol.group == oCol.group&&seCol.tag==oCol.tag){
|
||||
|
||||
if(seCol.group==BoxSet.HERO){
|
||||
if(oCom.type == this.type&&oCom.yun_cd<=0&&oCom.ice_cd<=0 && se_x < ot_x && Math.abs(ot_x-se_x) < 40 ){
|
||||
// this.node.setSiblingIndex(oCol.node.getSiblingIndex()-10)
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
}
|
||||
if(seCol.group==BoxSet.MONSTER){
|
||||
if(oCom.type == this.type&&oCom.yun_cd<=0&&oCom.ice_cd<=0 && se_x > ot_x && Math.abs(ot_x-se_x) < 40 ){
|
||||
// this.node.setSiblingIndex(oCol.node.getSiblingIndex()-10)
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if(seCol.group != oCol.group&&oCol.tag == 0){
|
||||
this.stop_cd = 0.1;
|
||||
this.is_atking=true
|
||||
}
|
||||
}
|
||||
|
||||
onPostSolve (seCol: Collider2D, oCol: Collider2D) {
|
||||
}
|
||||
update(dt: number){
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
@@ -206,14 +139,11 @@ export class HeroViewComp extends CCComp {
|
||||
if(!this.in_grave()) this.to_grave()
|
||||
return
|
||||
}
|
||||
|
||||
if (this.pwt.update(dt)) {
|
||||
this.pw+=this.pws
|
||||
}
|
||||
|
||||
this.check_power()
|
||||
this.check_atk_counts()
|
||||
this.check_enemy_alive()
|
||||
this.check_mission_buff()
|
||||
this.hp_show()
|
||||
if(this.ice_cd > 0){
|
||||
@@ -227,8 +157,8 @@ export class HeroViewComp extends CCComp {
|
||||
this.at += dt;
|
||||
this.in_stop(dt);
|
||||
this.in_atk(dt);
|
||||
this.move(dt);
|
||||
}
|
||||
}
|
||||
|
||||
hp_show(){
|
||||
let hp_progress= this.hp/this.rhp_max;
|
||||
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
@@ -240,25 +170,6 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
}
|
||||
//移动
|
||||
move(dt: number){
|
||||
if(this.stop_cd > 0||smc.mission.is_victory||smc.mission.is_defeat){
|
||||
this.status_change("idle")
|
||||
return
|
||||
}
|
||||
if (this.node.position.x >= 300 && this.scale==1) {
|
||||
return;
|
||||
}
|
||||
if(this.scale===-1&&this.node.position.x <= -300){
|
||||
return;
|
||||
}
|
||||
this.status_change("move")
|
||||
|
||||
|
||||
// if(this.enemy){
|
||||
// return
|
||||
// }
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y+dt*this.dir_y, this.node.position.z);
|
||||
}
|
||||
check_mission_buff(){
|
||||
this.ap_max=(100+smc.vmdata.mission.ap)/100*this.ap
|
||||
this.crit_max=(100+smc.vmdata.mission.crit)/100*this.crit
|
||||
@@ -273,35 +184,7 @@ export class HeroViewComp extends CCComp {
|
||||
this.rhp_max=(100+smc.vmdata.mission.mhp)/100*this.hp_max
|
||||
}
|
||||
}
|
||||
check_enemy_alive(){
|
||||
// let dir = 720
|
||||
// let enemys=smc.enemy_pos
|
||||
// this.enemy = v3(720,this.node.position.y)
|
||||
// if(this.box_group == BoxSet.MONSTER){
|
||||
// enemys=smc.hero_pos
|
||||
// // console.log("MONSTER enemys",enemys);
|
||||
// this.enemy=v3(-720,this.node.position.y)
|
||||
// }
|
||||
// for (let i = 0; i < enemys.length; i++) {
|
||||
// let ho:any = enemys[i];
|
||||
// let x=Math.abs(ho.x-this.node.position.x)
|
||||
// if(x < dir){
|
||||
// dir = x
|
||||
// this.enemy = ho
|
||||
// }
|
||||
// }
|
||||
let dir = Math.abs(smc.mon_front_x-this.node.position.x)
|
||||
if(this.box_group == BoxSet.MONSTER){
|
||||
dir = Math.abs(smc.hero_front_x-this.node.position.x)
|
||||
}
|
||||
if(dir < this.dis){
|
||||
this.is_atking=true
|
||||
if(this.dis-dir > 80 &&this.type > 0 ) this.stop_cd = 0.1
|
||||
if(dir < 65 &&this.type == 0 ) this.stop_cd = 0.1
|
||||
}else{
|
||||
this.is_atking=false
|
||||
}
|
||||
}
|
||||
|
||||
//状态切换
|
||||
status_change(type:string){
|
||||
this.status=type
|
||||
@@ -872,19 +755,14 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
//进入墓地
|
||||
to_grave(){
|
||||
let pos =v3(-999,this.node.position.y)
|
||||
if(this.box_group == BoxSet.MONSTER){
|
||||
pos =v3(999,this.node.position.y)
|
||||
smc.vmdata.mission.mdead +=1
|
||||
}else{
|
||||
smc.vmdata.mission.dead +=1
|
||||
}
|
||||
let pos =v3(0,-1000,this.node.position.z)
|
||||
this.node.setPosition(pos)
|
||||
}
|
||||
//是否在墓地
|
||||
in_grave(){
|
||||
return this.node.position.x < -900 || this.node.position.x > 900;
|
||||
return this.node.position.y <= -900;
|
||||
}
|
||||
|
||||
to_alive(){
|
||||
let pos =v3(HeroSet.StartPos[this.type],this.node.position.y,this.node.position.z)
|
||||
this.node.setPosition(pos)
|
||||
|
||||
Reference in New Issue
Block a user