dd
This commit is contained in:
@@ -75,18 +75,17 @@ export class MapViewComp extends CCComp {
|
||||
}
|
||||
/** 添加玩家 */
|
||||
private addHero() {
|
||||
this.scene.node.active = true
|
||||
if(smc.heros.length>0) {
|
||||
console.log("heros load")
|
||||
let hero = ecs.getEntity<Hero>(Hero);
|
||||
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
||||
let speed =smc.heros[0].speed
|
||||
let camp = 1
|
||||
let prefab_path = smc.heros[0].prefab_path
|
||||
let name = smc.heros[0].name
|
||||
hero.load(pos,speed,camp,prefab_path,name);
|
||||
smc.heros.splice(0,1)
|
||||
}
|
||||
this.scene.node.active = true
|
||||
if(smc.heros.length>0) {
|
||||
let hero = ecs.getEntity<Hero>(Hero);
|
||||
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
||||
let speed =smc.heros[0].speed
|
||||
let camp = 1
|
||||
let prefab_path = smc.heros[0].prefab_path
|
||||
let name = smc.heros[0].name
|
||||
hero.load(pos,speed,camp,prefab_path,name);
|
||||
smc.heros.splice(0,1)
|
||||
}
|
||||
}
|
||||
private addMonster() {
|
||||
this.scene.node.active = true
|
||||
|
||||
@@ -14,15 +14,13 @@ import { smc } from "../common/SingletonModuleComp";
|
||||
import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { MonsterSpine } from "./MonsterSpine";
|
||||
import { MonsterViewComp } from "./MonsterViewComp";
|
||||
import { MoveToComp } from "../common/MoveTo";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`Monster`)
|
||||
export class Monster extends ecs.Entity {
|
||||
// 数据层
|
||||
MonsterModel!: MonsterModelComp;
|
||||
// 视图层
|
||||
MonsterView!: MonsterViewComp;
|
||||
RoleMoveTo!: MoveToComp; // 移动
|
||||
MonsterView!: MonsterViewComp; // 移动
|
||||
|
||||
protected init() {
|
||||
this.addComponents<ecs.Comp>(
|
||||
@@ -74,14 +72,6 @@ export class Monster extends ecs.Entity {
|
||||
|
||||
console.log(smc.heros_in,smc.monsters_in)
|
||||
}
|
||||
|
||||
/** 移动(ECS System处理逻辑,分享功能独立的业务代码) */
|
||||
move(target: Vec3,speed:number = 100) {
|
||||
var move = this.get(MoveToComp) || this.add(MoveToComp);
|
||||
move.target = target;
|
||||
move.node = this.MonsterView.node;
|
||||
move.speed = speed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate} 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";
|
||||
@@ -14,7 +14,9 @@ import { Hero } from "./Hero";
|
||||
import { MonsterModelComp } from "./MonsterModelComp";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { baseCom } from "../skills/baseCom";
|
||||
import { Skill } from "../skills/Skill";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -33,7 +35,7 @@ export class MonsterViewComp extends CCComp {
|
||||
/** 角色初始速度 */
|
||||
ospeed: number = 100;
|
||||
/**攻击速度 */
|
||||
atk_speed: number = 2;
|
||||
atk_speed: number = 1;
|
||||
atk_cd: number = 0;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
@@ -72,7 +74,7 @@ export class MonsterViewComp extends CCComp {
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case BoxSet.HERO:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
@@ -149,11 +151,11 @@ export class MonsterViewComp extends CCComp {
|
||||
in_act(dt: number) {
|
||||
if(this.atk_cd >= this.atk_speed){
|
||||
this.atk_cd = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
this.load_skill();
|
||||
}
|
||||
if(this.state == 2){
|
||||
this.atk_cd += dt;
|
||||
}
|
||||
this.atk_cd += dt;
|
||||
}
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
@@ -186,7 +188,21 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
});
|
||||
}
|
||||
load_skill(){
|
||||
// console.log("load_skill");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(0,0)
|
||||
let speed =200
|
||||
let scale = this.camp
|
||||
let range = 80
|
||||
skill.load(pos,speed,range,scale,this.node);
|
||||
}
|
||||
in_atked() {
|
||||
var path = "game/skills/atked";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
|
||||
}
|
||||
reset() {
|
||||
// console.log("node destroy:",this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
|
||||
57
assets/script/game/skills/Skill.ts
Normal file
57
assets/script/game/skills/Skill.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BoxSet } from "../common/config/BoxSet";
|
||||
import { SkillCom } from "./SkillCom";
|
||||
import { instantiate, Node, Prefab, Vec3 ,tween, v3,animation,Label,resources,SpriteFrame,Sprite} from "cc";
|
||||
|
||||
/** Skill 模块 */
|
||||
@ecs.register(`Skill`)
|
||||
export class Skill extends ecs.Entity {
|
||||
/** ---------- 数据层 ---------- */
|
||||
// SkillModel!: SkillModelComp;
|
||||
|
||||
/** ---------- 业务层 ---------- */
|
||||
// SkillBll!: SkillBllComp;
|
||||
|
||||
/** ---------- 视图层 ---------- */
|
||||
SkillView!: SkillCom;
|
||||
|
||||
/** 实始添加的数据层组件 */
|
||||
protected init() {
|
||||
|
||||
}
|
||||
|
||||
/** 模块资源释放 */
|
||||
destroy() {
|
||||
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
|
||||
this.remove(SkillCom);
|
||||
super.destroy();
|
||||
}
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,range:number = 50,scale:number = 1,parent:Node) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/skills/base";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = parent;
|
||||
node.setPosition(pos)
|
||||
var mv = node.getComponent(SkillCom)!;
|
||||
mv.speed = speed;
|
||||
mv.range = range;
|
||||
mv.scale = scale;
|
||||
if(scale == 1){
|
||||
mv.change_collider_group(BoxSet.HERO_SKILL)
|
||||
}else{
|
||||
mv.change_collider_group(BoxSet.MONSTER_SKILL)
|
||||
}
|
||||
this.add(mv);
|
||||
}
|
||||
}
|
||||
|
||||
/** Skill 模块业务逻辑系统组件,如无业务逻辑处理可删除此对象 */
|
||||
export class EcsSkillSystem extends ecs.System {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// this.add(new ecs.ComblockSystem());
|
||||
}
|
||||
}
|
||||
9
assets/script/game/skills/Skill.ts.meta
Normal file
9
assets/script/game/skills/Skill.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e7bac796-7cc3-47b4-904b-85a95cc15390",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
76
assets/script/game/skills/SkillCom.ts
Normal file
76
assets/script/game/skills/SkillCom.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { _decorator,Collider2D ,Contact2DType,v3,IPhysics2DContact} 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";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('SkillCom')
|
||||
@ecs.register('SkillView', false)
|
||||
export class SkillCom extends CCComp {
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
// start() {
|
||||
// // var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
// // this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||||
// }
|
||||
speed:number = 600;
|
||||
range:number = 80;
|
||||
scale:number = 1;
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
// this.reset()
|
||||
console.log('hero skill',selfCollider);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
// console.log('monster skill',selfCollider,otherCollider);
|
||||
// this.reset()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
change_collider_group(group:number){
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = group;
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
|
||||
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
||||
if(Math.abs(this.node.position.x) > this.range)
|
||||
{
|
||||
this.reset()
|
||||
}
|
||||
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/skills/SkillCom.ts.meta
Normal file
9
assets/script/game/skills/SkillCom.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "45646a08-c887-40db-85be-d1ce6b7442c3",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('base')
|
||||
export class base extends Component {
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
58
assets/script/game/skills/baseCom.ts
Normal file
58
assets/script/game/skills/baseCom.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { _decorator, Component, Node, tween ,Vec3,v3,Collider2D,Contact2DType} from 'cc';
|
||||
import { BoxSet } from '../common/config/BoxSet';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('baseCom')
|
||||
export class baseCom extends Component {
|
||||
speed:number = 600;
|
||||
range:number = 80;
|
||||
scale:number = 1;
|
||||
start() {
|
||||
let collider = this.getComponent(Collider2D);
|
||||
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
}
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) {
|
||||
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.HERO_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
// this.reset()
|
||||
console.log('hero skill',selfCollider,otherCollider);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
// console.log('monster skill',selfCollider,otherCollider);
|
||||
// this.reset()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
change_collider_group(group:number){
|
||||
let collider = this.getComponent(Collider2D);
|
||||
collider.group = group;
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z))
|
||||
this.node.setPosition(v3(this.node.position.x+deltaTime*this.speed*this.scale,this.node.position.y,this.node.position.z))
|
||||
if(Math.abs(this.node.position.x) > this.range)
|
||||
{
|
||||
this.node.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user