This commit is contained in:
walkpan
2024-09-09 07:56:18 +08:00
parent 47af795c12
commit 9bac2d5c5b
264 changed files with 96262 additions and 53551 deletions

View File

@@ -14,14 +14,14 @@ export class BoxRangComp extends CCComp {
MonsterViewComp:MonsterViewComp = null!;
box_group:number = BoxSet.DEFAULT;
box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 0;
offset_x:number = 300;
atk_range:number = 150;
/** 视图层逻辑代码分离演示 */
start() {
let collider = this.getComponent(Collider2D);
collider.group = this.box_group;
collider.tag = this.box_tag;
// collider.offset = v2(this.offset_x,40);
// collider.offset = v2(300*this.Hero_node.MonsterView.scale,collider.offset.y);
this.Hero_node = this.node.parent;
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
// console.log("range box",this.MonsterViewComp);
@@ -64,9 +64,8 @@ export class BoxRangComp extends CCComp {
}
}
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
this.MonsterViewComp.is_atking = true;
this.MonsterViewComp.stop_cd = 0.1
// this.MonsterViewComp.stop_cd = 0.1
}
}

View File

@@ -12,6 +12,7 @@ import { smc } from "../common/SingletonModuleComp";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { HeroModelComp } from "./HeroModelComp";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { MonModelComp } from "../mon/MonModelComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@@ -62,9 +63,9 @@ export class CSkillComp extends CCComp {
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(MonModelComp));
if (monsters.length > 0) {
m_pos = monsters[0].MonsterView.get_monster_pos()
m_pos = monsters[0].MonView.node.position
}else{
m_pos = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
@@ -98,7 +99,7 @@ export class CSkillComp extends CCComp {
// 94role 临时buff
// 95role 永久buff
let uuid= this.skill_uuid;
let atk:number=smc.Role.MonsterView.atk
let atk:number=smc.Role.RoleView.atk
let args:any = {
atk:atk*GameSet.ATK_TO_ATK_RATIO,
hp:atk*GameSet.ATK_TO_HP_RATIO,

View File

@@ -15,7 +15,6 @@ import { MonsterModelComp } from "./MonsterModelComp";
import { MonsterSpine } from "./MonsterSpine";
import { MonsterViewComp } from "./MonsterViewComp";
import {HeroModelComp} from "./HeroModelComp";
import { CardSet } from "../common/config/CardSet";
import { BoxSet } from "../common/config/BoxSet";
import { MonsterBuffComp } from "./MonsterBuffComp";
/** 角色实体 */

View File

@@ -12,7 +12,6 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { UIID } from "../common/config/GameUIConfig";
import { smc } from "../common/SingletonModuleComp";
import{HeroCardViewComp} from "./HeroCardViewComp";
import { CardSet } from "../common/config/CardSet";
import { SkillSet } from "../common/config/SkillSet";
/** 角色实体 */
@ecs.register(`HeroCard`)

View File

@@ -4,7 +4,6 @@ import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/modu
import { data } from "../data/data";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { smc } from "../common/SingletonModuleComp";
import { CardSet } from "../common/config/CardSet";
import { SkillSet } from "../common/config/SkillSet";
import { HeroCard } from "./HeroCard";
import { HeroModelComp } from "./HeroModelComp";

View File

@@ -14,7 +14,6 @@ import { smc } from "../common/SingletonModuleComp";
import { MonsterModelComp } from "./MonsterModelComp";
import { MonsterSpine } from "./MonsterSpine";
import { MonsterViewComp } from "./MonsterViewComp";
import { CardSet } from "../common/config/CardSet";
import { BoxSet } from "../common/config/BoxSet";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { MonsterBuffComp } from "./MonsterBuffComp";
@@ -46,8 +45,8 @@ export class Monster extends ecs.Entity {
var node = instantiate(prefab);
node.parent=layer
// var as = node.getComponent(MonsterSpine);
// let ratio=this.set_ratio(uuid);
node.setScale(node.scale.x*scale, node.scale.y, node.scale.z);
let ratio=this.set_ratio(uuid);
node.setScale(node.scale.x*scale*ratio, node.scale.y*ratio, 0);
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
node.setPosition(pos)
@@ -60,29 +59,30 @@ export class Monster extends ecs.Entity {
this.hero_init(uuid,node)
oops.message.dispatchEvent("monster_load",this)
}
// set_ratio(uuid:number){
// let ratio=1;
// switch (smc.heros[uuid].level) {
// case 2:
// ratio=1.1
// break;
// case 3:
// ratio=1.2
// break;
// case 4:
// ratio=1.3
// break;
// case 5:
// ratio=1.4
// break;
// default:
// ratio=1
// }
// return ratio;
// }
set_ratio(uuid:number){
let ratio=1;
switch (smc.heros[uuid].level) {
case 2:
ratio=1.05
break;
case 3:
ratio=1.1
break;
case 4:
ratio=1.15
break;
case 5:
ratio=1.2
break;
default:
ratio=1
}
return ratio;
}
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(MonsterViewComp)!;
var buff =node.getComponent(MonsterBuffComp)!;
// console.log("hero_init",smc.heros,uuid)
mv.speed =mv.ospeed = smc.heros[uuid].speed;
mv.hero_name= smc.heros[uuid].name;
buff.group=mv.box_group= BoxSet.MONSTER;

View File

@@ -5,7 +5,7 @@
* @LastEditTime: 2022-08-17 12:36:18
*/
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} from "cc";
import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,RigidBody2D ,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} 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 { MonsterSpine } from "./MonsterSpine";
@@ -19,9 +19,10 @@ import { Skill } from "../skills/Skill";
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
import { SkillCom } from "../skills/SkillCom";
import { SkillSet } from "../common/config/SkillSet";
import { BoxRangComp } from "./BoxRangComp";
import { Tooltip } from "../skills/Tooltip";
import { MonsterBuffComp } from "./MonsterBuffComp";
import { MoveToComp } from "../common/ecs/position/MoveTo";
import { BoxRangComp } from "./BoxRangComp";
const { ccclass, property } = _decorator;
/** 角色显示组件 */
@@ -78,6 +79,7 @@ export class MonsterViewComp extends CCComp {
box_group:number = 2;
atk_range:number = 150;
private timer:Timer = new Timer(1); //计时器
private m_timer:Timer = new Timer(0.1);
is_dead:boolean = false; //是否摧毁
is_stop:boolean = false;
is_atking:boolean = false;
@@ -85,24 +87,26 @@ export class MonsterViewComp extends CCComp {
onLoad() {
this.as = this.getComponent(MonsterSpine);
this.buff=this.node.getComponent(MonsterBuffComp);
this.BoxRang = this.node.getChildByName("range_box");
// this.BoxRang = this.node.getChildByName("range_box");
// this.BoxRang = this.node.getChildByName("range_box");
} /** 视图层逻辑代码分离演示 */
start () {
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
this.node.getChildByName("top").setScale(this.scale,1);
this.node.getChildByName("atk").setScale(this.scale,1);
this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
this.node.getChildByName("hp_max").setScale(this.scale,1);
this.node.getChildByName("hp_max").getComponent(Label).string=this.hp_max.toString();
this.node.getChildByName("top").setScale(this.scale,1);
// this.node.getChildByName("atk").setScale(this.scale,1);
// this.node.getChildByName("atk").getComponent(Label).string = this.atk.toString();
// 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).offset_x = this.scale*smc.skills[this.skill_uuid].dis/3;
// this.BoxRang.getComponent(BoxRangComp).offset_x = 300;
// console.log("monseter ",this.BoxRang);
// console.log("monseter ",this.BoxRang);
// if(this.box_group == BoxSet.MONSTER){
// this.enemy=smc.Role.RoleView.node
// // console.log("monster enemy ",this.enemy);
// }
this.buff.group=this.box_group
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
@@ -118,6 +122,7 @@ export class MonsterViewComp extends CCComp {
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
if(selfCollider.group != otherCollider.group){
let skill = otherCollider.node.getComponent(SkillCom)!;
@@ -132,11 +137,11 @@ export class MonsterViewComp extends CCComp {
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0){
this.is_atking = true;
this.stop_cd = 0.1;
}
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) {
if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){
@@ -146,12 +151,12 @@ export class MonsterViewComp extends CCComp {
switch (selfCollider.group) {
case BoxSet.HERO:
if(self_pos.x < other_pos.x){
this.stop_cd=0.1
// this.stop_cd=0.1
}
break;
case BoxSet.MONSTER:
if(self_pos.x > other_pos.x){
this.stop_cd=0.1
// this.stop_cd=0.1
}
break
}
@@ -168,7 +173,9 @@ export class MonsterViewComp extends CCComp {
this.in_stop(dt);
this.in_act(dt);
this.move(dt);
// if(this.m_timer.update(dt)){
// this.move_to()
// }
}
move(dt: number){
@@ -178,8 +185,52 @@ export class MonsterViewComp extends CCComp {
if (this.scale === 1 && this.node.position.x >= 120) {
return;
}
if(this.scale===-1&&this.node.position.x <= BoxSet.HERO_START){
return;
}
// if(this.enemy){
// return
// }
this.node.setPosition(this.node.position.x+dt*this.speed*this.scale, this.node.position.y, this.node.position.z);
}
move_to(){
var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
move.target = v3(smc.Role.RoleView.node.position.x+10,smc.Role.RoleView.node.position.y);
move.node = this.node;
move.speed = this.ospeed;
// if(this.box_group == BoxSet.MONSTER){
// if(smc.t_hero.eid != 0){
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
// if(smc.t_hero.pos.x < this.node.position.x){
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_hero.pos.x+20,smc.t_hero.pos.y);
// }else{
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_hero.pos.x-20,smc.t_hero.pos.y);
// }
// move.node = this.node;
// move.speed = this.ospeed;
// }
// }
// if(this.box_group == BoxSet.HERO){
// if(smc.t_monster.eid != 0){
// var move = this.ent.get(MoveToComp) || this.ent.add(MoveToComp);
// if(smc.t_monster.pos.x < this.node.position.x){
// // this.node.setScale(-Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_monster.pos.x+20,smc.t_monster.pos.y);
// }else{
// // this.node.setScale(Math.abs(this.node.scale.x),this.node.scale.y)
// move.target = v3(smc.t_monster.pos.x-20,smc.t_monster.pos.y);
// }
// move.node = this.node;
// move.speed = this.ospeed;
// }
// }
}
power_change(power: number){
this.power += power;
if(this.power >= this.power_max){
@@ -204,6 +255,10 @@ export class MonsterViewComp extends CCComp {
let angle=0
let t_pos:Vec3 = v3(0,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)
angle = Math.atan2(t_pos.y,t_pos.x) * 180 / Math.PI;
if(this.scale == -1){
@@ -269,12 +324,21 @@ export class MonsterViewComp extends CCComp {
this.node.getChildByName("top").getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
if(this.hp <= 0){
this.dead();
this.remove_smc_data()
this.is_dead = true;
setTimeout(() => {
this.ent.destroy();
}, 15);
}
}
remove_smc_data(){
if(smc.t_monster.eid == this.ent.eid){
smc.t_monster = {eid:0,pos:v3(0,0,0)}
}
if(smc.t_hero.eid == this.ent.eid){
smc.t_hero = {eid:0,pos:v3(0,0,0)}
}
}
add_hp(hp: number=0){
console.log("hero 加血动画");
this.tooltip(2,hp.toString());
@@ -335,7 +399,7 @@ export class MonsterViewComp extends CCComp {
let pos = v3(0,60)
node.setPosition(pos)
node.parent = this.node;
}else{
this.sprite.setSharedMaterial(this.hitFlashMaterial, 0);
this.scheduleOnce(() => {