碰撞体 基本完成,开始精灵技能释放优化
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
/** 碰撞分组 */
|
||||
export enum BoxSet {
|
||||
//物理碰撞tag
|
||||
SKILL_TAG=8,
|
||||
ATK_RANGE = 4,
|
||||
DEFAULT = 1,
|
||||
MONSTER = 2,
|
||||
HERO = 4,
|
||||
|
||||
@@ -29,7 +29,7 @@ export class MapMonsterComp extends CCComp {
|
||||
cur_mission:number = 1; //当前关卡方案
|
||||
mission_list:any = []
|
||||
setp_timer: Timer = new Timer(0.5);
|
||||
setp_num:number = 2;
|
||||
setp_num:number = 5;
|
||||
onLoad(){
|
||||
// 监听全局事件
|
||||
oops.message.on("do_add_monster", this.on_do_add_monster, this);
|
||||
@@ -49,7 +49,7 @@ export class MapMonsterComp extends CCComp {
|
||||
this.monster_refresh()
|
||||
}
|
||||
if (this.refresh_timer.update(dt)) {
|
||||
this.setp_num = RandomManager.instance.getRandomInt(this.min_monster_num,this.max_monster_num,2)
|
||||
// this.setp_num = RandomManager.instance.getRandomInt(this.min_monster_num,this.max_monster_num,2)
|
||||
}
|
||||
if (this.mission_up_timer.update(dt)) {
|
||||
// 刷新怪物定时器
|
||||
|
||||
@@ -67,6 +67,8 @@ export class Monster extends ecs.Entity {
|
||||
mv.atk_cd = smc.heros[uuid].atk_cd;
|
||||
mv.power = smc.heros[uuid].power;
|
||||
mv.type = smc.heros[uuid].type;
|
||||
mv.skill_name = "base2";
|
||||
mv.max_skill_name = "fire";
|
||||
mv.scale = -1;
|
||||
mv.Tpos = v3(0,0,0);
|
||||
mv.change_name(smc.heros[uuid].name,-1)
|
||||
|
||||
@@ -47,7 +47,7 @@ export class MonsterViewComp extends CCComp {
|
||||
power_max: number = 100; /** 能量最大值 */
|
||||
power_speed: number = 1; //能量回复速度每0.1秒回复量
|
||||
|
||||
skill_name: string = "atk"; //技能名称
|
||||
skill_name: string = "base"; //技能名称
|
||||
max_skill_name: string = "base"; //大技能名称
|
||||
|
||||
atk: number = 10; /**攻击力 */
|
||||
@@ -67,6 +67,7 @@ export class MonsterViewComp extends CCComp {
|
||||
private timer:Timer = new Timer(0.1); //计时器
|
||||
is_dead:boolean = false; //是否摧毁
|
||||
is_stop:boolean = false;
|
||||
is_atking:boolean = false;
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
@@ -93,29 +94,35 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// 只在两个碰撞体结束接触时被调用一次
|
||||
// console.log('onEndContact');
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
if(otherCollider.tag != 8){
|
||||
this.stop_cd = 0.5;
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
// console.log('onPostSolve',skill);
|
||||
this.in_atked();
|
||||
this.hp_change(skill.atk);
|
||||
}
|
||||
}
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
// console.log('onPostSolve',skill);
|
||||
this.in_atked();
|
||||
this.hp_change(skill.atk);
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
||||
if(otherCollider.tag != BoxSet.SKILL_TAG&&selfCollider.tag != BoxSet.ATK_RANGE){
|
||||
this.stop_cd = 0.1;
|
||||
}
|
||||
}
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
||||
this.is_atking = true;
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
if(selfCollider.group == otherCollider.group){
|
||||
console.log('group 相同');
|
||||
if(otherCollider.tag != 8){
|
||||
// console.log('monster view group 相同');
|
||||
if(otherCollider.tag != BoxSet.SKILL_TAG){
|
||||
let self_pos=selfCollider.node.getPosition();
|
||||
let other_pos=otherCollider.node.getPosition();
|
||||
if(selfCollider.group == BoxSet.HERO){
|
||||
@@ -191,23 +198,26 @@ export class MonsterViewComp extends CCComp {
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max){
|
||||
this.load_skill(this.max_skill_name);
|
||||
this.shoot(this.max_skill_name);
|
||||
this.power = 0
|
||||
}
|
||||
let power_progress= this.power/this.power_max;
|
||||
this.node.getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
|
||||
}
|
||||
in_act(dt: number) {
|
||||
|
||||
if(this.atk_time >= this.atk_cd){
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
this.scheduleOnce(()=>{
|
||||
this.load_skill(this.skill_name);
|
||||
},0.2)
|
||||
|
||||
if(this.is_atking){
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
this.scheduleOnce(()=>{
|
||||
this.shoot(this.skill_name);
|
||||
},0.2)
|
||||
}
|
||||
}else{
|
||||
this.atk_time += dt;
|
||||
}
|
||||
this.atk_time += dt;
|
||||
}
|
||||
hp_change(hp: number){
|
||||
if(this.is_dead){
|
||||
@@ -220,9 +230,10 @@ export class MonsterViewComp extends CCComp {
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp <= 0){
|
||||
this.dead();
|
||||
this.is_dead = true;
|
||||
setTimeout(() => {
|
||||
this.toDestroy();
|
||||
this.ent.destroy();
|
||||
}, 15);
|
||||
|
||||
}
|
||||
@@ -232,8 +243,8 @@ export class MonsterViewComp extends CCComp {
|
||||
if(this.stop_cd > 0){
|
||||
this.stop_cd -= dt;
|
||||
if(this.stop_cd <= 0){
|
||||
// this.speed = this.ospeed;
|
||||
this.stop_cd = 0;
|
||||
this.is_atking = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,19 +269,19 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
});
|
||||
}
|
||||
load_skill(skill_name:string){
|
||||
console.log("load_skill");
|
||||
shoot(skill_name:string){
|
||||
console.log("monster shoot");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let x=30
|
||||
if(this.scale==1){
|
||||
x=40
|
||||
x=0
|
||||
}else{
|
||||
x=-20
|
||||
x=-0
|
||||
}
|
||||
let pos = v3(x,50)
|
||||
let pos = v3(x,40)
|
||||
let speed =350
|
||||
let scale = this.scale
|
||||
let dis = 30;
|
||||
let dis = 50;
|
||||
console.log(speed);
|
||||
skill.load(pos,speed,dis,scale,this.node,skill_name,this.atk);
|
||||
}
|
||||
@@ -294,9 +305,7 @@ export class MonsterViewComp extends CCComp {
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
toDestroy(){
|
||||
this.dead();
|
||||
|
||||
this.ent.destroy();
|
||||
|
||||
}
|
||||
reset() {
|
||||
this.is_dead = false;
|
||||
|
||||
@@ -44,10 +44,11 @@ export class Skill extends ecs.Entity {
|
||||
sv.atk = atk;
|
||||
sv.angle = angle;
|
||||
sv.t_pos = t_pos;
|
||||
sv.box_tag= BoxSet.SKILL_TAG;
|
||||
if(scale == 1){
|
||||
sv.box_group=BoxSet.HERO_SKILL
|
||||
sv.box_group=BoxSet.HERO
|
||||
}else{
|
||||
sv.box_group=BoxSet.MONSTER_SKILL
|
||||
sv.box_group=BoxSet.MONSTER
|
||||
}
|
||||
this.add(sv);
|
||||
}
|
||||
|
||||
@@ -25,14 +25,17 @@ export class SkillCom extends CCComp {
|
||||
t_pos:Vec3 = null;
|
||||
is_destroy:boolean = false;
|
||||
box_group:number = 0;
|
||||
box_tag:number=0;
|
||||
start() {
|
||||
this.node.active=true
|
||||
this.node.angle = this.angle;
|
||||
|
||||
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);
|
||||
}
|
||||
if(this.t_pos){
|
||||
@@ -57,41 +60,45 @@ export class SkillCom extends CCComp {
|
||||
}
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
case BoxSet.DEFAULT:
|
||||
setTimeout(() => {
|
||||
this.toDestroy()
|
||||
}, 10);
|
||||
break
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.PLAYER:
|
||||
case BoxSet.HERO:
|
||||
case BoxSet.DEFAULT:
|
||||
setTimeout(() => {
|
||||
this.toDestroy()
|
||||
}, 10);
|
||||
break
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(otherCollider.group != selfCollider.group){
|
||||
console.log("skill end contact")
|
||||
setTimeout(() => {
|
||||
this.toDestroy()
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// console.log("skill post contact")
|
||||
// switch (selfCollider.group) {
|
||||
|
||||
// case BoxSet.HERO:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.MONSTER:
|
||||
// case BoxSet.DEFAULT:
|
||||
// setTimeout(() => {
|
||||
// this.toDestroy()
|
||||
// }, 10);
|
||||
// break
|
||||
// }
|
||||
// break;
|
||||
// case BoxSet.MONSTER:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.PLAYER:
|
||||
// case BoxSet.HERO:
|
||||
// case BoxSet.DEFAULT:
|
||||
// setTimeout(() => {
|
||||
// this.toDestroy()
|
||||
// }, 10);
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
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)
|
||||
// {
|
||||
// this.toDestroy()
|
||||
|
||||
// }
|
||||
// this.move(deltaTime)
|
||||
|
||||
|
||||
}
|
||||
move(dt: number) {
|
||||
|
||||
Reference in New Issue
Block a user