添加2个游戏层,敌方精灵随机出现在3个层内
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact} from "cc";
|
||||
import { _decorator,Contact2DType,Collider2D ,IPhysics2DContact,v3, v2} 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 { BoxSet } from "../common/config/BoxSet";
|
||||
@@ -9,41 +9,46 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('BoxRangComp')
|
||||
@ecs.register('BoxRang', false)
|
||||
export class BoxRangComp extends CCComp {
|
||||
@property(MonsterViewComp)
|
||||
Hero_node:MonsterViewComp = null!;
|
||||
|
||||
Hero_node: any=null!;
|
||||
MonsterViewComp:MonsterViewComp = null!;
|
||||
box_group:number = BoxSet.DEFAULT;
|
||||
box_tag:number = BoxSet.ATK_RANGE;
|
||||
offset_x:number = 0;
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
collider.tag = this.box_tag;
|
||||
// console.log(collider,this.Hero_node);
|
||||
collider.offset = v2(this.offset_x,45);
|
||||
this.Hero_node = this.node.parent;
|
||||
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
|
||||
// console.log("range box",this.MonsterViewComp);
|
||||
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);
|
||||
// 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 (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
}
|
||||
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE){
|
||||
this.Hero_node.is_atking = true;
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if(selfCollider.group != otherCollider.group&&otherCollider.tag != BoxSet.ATK_RANGE&&otherCollider.tag != BoxSet.SKILL_TAG){
|
||||
// console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
this.MonsterViewComp.is_atking = true;
|
||||
}
|
||||
}
|
||||
// onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// // console.log("range box group: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| range box tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
|
||||
|
||||
}
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
// }
|
||||
// onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
// }
|
||||
// onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
|
||||
@@ -27,7 +27,7 @@ export class CSkill extends ecs.Entity {
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = 1,uuid:number=1001) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
console.log("load skill",this)
|
||||
// console.log("load skill",this)
|
||||
var path = "game/heros/skill";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
|
||||
@@ -16,6 +16,7 @@ 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";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
@@ -36,23 +37,19 @@ export class Monster extends ecs.Entity {
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001) {
|
||||
load(pos: Vec3 = Vec3.ZERO,scale:number = -1,uuid:number=1001,layer:Node=smc.map.MapView.scene.entityLayer!.node!) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/heros/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
var as = node.getComponent(MonsterSpine);
|
||||
|
||||
node.parent=layer
|
||||
// var as = node.getComponent(MonsterSpine);
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*scale, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.setPosition(pos)
|
||||
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
const url = 'game/heros/heros';
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(smc.heros[uuid].path);
|
||||
});
|
||||
this.hero_init(uuid,node)
|
||||
|
||||
@@ -26,13 +26,13 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('MonsterViewComp') // 定义为 Cocos Creator 组件
|
||||
@ecs.register('MonsterView', false) // 定义为 ECS 组件
|
||||
export class MonsterViewComp extends CCComp {
|
||||
|
||||
@property(Material)
|
||||
hitFlashMaterial: Material;
|
||||
orginalFlashMaterial: Material;
|
||||
sprite: Sprite;
|
||||
@property(BoxRangComp)
|
||||
BoxRang:BoxRangComp = null!;
|
||||
|
||||
@property(Node)
|
||||
BoxRang:Node =null!
|
||||
/** 角色动画 */
|
||||
as: MonsterSpine = null!;
|
||||
hero_uuid:number = 1001;
|
||||
@@ -76,21 +76,25 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
// EPhysics2DDrawFlags.CenterOfMass |
|
||||
// EPhysics2DDrawFlags.Joint |
|
||||
// EPhysics2DDrawFlags.Shape;
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
|
||||
// | EPhysics2DDrawFlags.Pair
|
||||
// |EPhysics2DDrawFlags.CenterOfMass
|
||||
// |EPhysics2DDrawFlags.Joint
|
||||
// |EPhysics2DDrawFlags.Shape;
|
||||
} /** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
|
||||
|
||||
this.BoxRang = this.node.getChildByName("range_box");
|
||||
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
|
||||
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*SkillSet[this.skill_uuid].dis-30;
|
||||
// console.log("monseter ",this.BoxRang);
|
||||
|
||||
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = this.box_group;
|
||||
this.BoxRang.box_group = this.box_group;
|
||||
// console.log(collider);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
@@ -102,9 +106,10 @@ export class MonsterViewComp extends CCComp {
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
|
||||
if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){
|
||||
if(selfCollider.group != otherCollider.group){
|
||||
let skill = otherCollider.node.getComponent(SkillCom)!;
|
||||
@@ -135,17 +140,19 @@ export class MonsterViewComp extends CCComp {
|
||||
let self_pos=selfCollider.node.getPosition();
|
||||
let other_pos=otherCollider.node.getPosition();
|
||||
if(selfCollider.group == BoxSet.HERO){
|
||||
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){
|
||||
if(self_pos.x < other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
|
||||
this.stop_cd=0.1
|
||||
}
|
||||
}
|
||||
if(selfCollider.group == BoxSet.MONSTER){
|
||||
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20){
|
||||
if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= 20&&self_pos.y==other_pos.y){
|
||||
this.stop_cd=0.1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
// console.log('monster onPostSolve'+selfCollider.group+"|"+otherCollider.group);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,15 +179,6 @@ export class MonsterViewComp extends CCComp {
|
||||
this.in_destroy();
|
||||
this.in_stop(dt);
|
||||
this.in_act(dt);
|
||||
switch (this.type) {
|
||||
case 1:
|
||||
this.as.walk();
|
||||
break;
|
||||
case 2:
|
||||
this.as.idle();
|
||||
break;
|
||||
}
|
||||
|
||||
this.move(dt);
|
||||
// this.update_pos();
|
||||
|
||||
@@ -213,7 +211,7 @@ export class MonsterViewComp extends CCComp {
|
||||
this.node.getChildByName("power").getComponent(ProgressBar)!.progress = power_progress;
|
||||
}
|
||||
shoot(skill_uuid:number){
|
||||
console.log("monster shoot");
|
||||
// console.log("monster shoot");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let x=0
|
||||
let pos = v3(x,40)
|
||||
|
||||
Reference in New Issue
Block a user