dd
This commit is contained in:
@@ -36,7 +36,7 @@ export class Hero extends ecs.Entity {
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
var path = "game/heros/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
|
||||
@@ -11,7 +11,8 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { UIID } from "../common/config/GameUIConfig";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
import{HeroCardViewComp} from "./HeroCardViewComp";
|
||||
import { CardSet } from "../common/config/CardSet";
|
||||
/** 角色实体 */
|
||||
@ecs.register(`HeroCard`)
|
||||
export class HeroCard extends ecs.Entity {
|
||||
@@ -27,28 +28,31 @@ export class HeroCard extends ecs.Entity {
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
// this.remove(MonsterViewComp);
|
||||
this.remove(HeroCardViewComp);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
load(pos: Vec3 = Vec3.ZERO,uuid:number=1001,parent:Node) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
|
||||
var path = "game/heros/cards/hero_card";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
var scene = smc.map.MapView.scene;
|
||||
node.parent = scene.entityLayer!.node!;
|
||||
node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, node.getChildByName("avatar").scale.y, node.getChildByName("avatar").scale.z);
|
||||
node.parent = parent;
|
||||
// node.getChildByName("avatar").setScale(node.getChildByName("avatar").scale.x*camp, 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/hero/'+prefab_path+'/spriteFrame';
|
||||
resources.load(url, SpriteFrame, (err: any, spriteFrame) => {
|
||||
const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
var hcv = node.getComponent(HeroCardViewComp)!;
|
||||
hcv.card_name=CardSet[uuid].name
|
||||
hcv.card_uid=uuid
|
||||
this.add(hcv);
|
||||
// // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
|
||||
// const url = 'game/heros/hero/'+prefab_path+'/spriteFrame';
|
||||
// resources.load(url, SpriteFrame, (err: any, spriteFrame) => {
|
||||
// const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
|
||||
|
||||
sprite.spriteFrame = spriteFrame;
|
||||
});
|
||||
// sprite.spriteFrame = spriteFrame;
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
|
||||
77
assets/script/game/monster/HeroCardViewComp.ts
Normal file
77
assets/script/game/monster/HeroCardViewComp.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { _decorator ,Vec2,NodeEventType,EventTouch} 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 { data } from "../data/data";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroCardViewComp')
|
||||
@ecs.register('HeroCardView', false)
|
||||
export class HeroCardViewComp extends CCComp {
|
||||
card_name:string = "hero_card";
|
||||
card_type:string = "hero";
|
||||
card_uid:number = 1000;
|
||||
/** 方向 */
|
||||
private _dir: Vec2 = new Vec2(0, 0);
|
||||
public get dir(): Vec2 {
|
||||
return this._dir;
|
||||
}
|
||||
public set dir(value: Vec2) {
|
||||
this._dir = value;
|
||||
}
|
||||
pos_x=0;
|
||||
pos_y=0;
|
||||
protected onLoad(): void {
|
||||
this.node.on(NodeEventType.TOUCH_START, this.onTouchMove, this);
|
||||
this.node.on(NodeEventType.TOUCH_MOVE, this.onTouchMove, this);
|
||||
this.node.on(NodeEventType.TOUCH_END, this.onTouchEnd, this);
|
||||
this.node.on(NodeEventType.TOUCH_CANCEL, this.onTouchEnd, this);
|
||||
oops.message.on("destroy hero_card", this.on_destroy_node, this);
|
||||
}
|
||||
|
||||
|
||||
private on_destroy_node(event: string, args: any) {
|
||||
// if(this.ent.eid == args){
|
||||
// this.reset();
|
||||
// }
|
||||
}
|
||||
|
||||
onTouchMove(event: EventTouch) {
|
||||
console.log("onTouchMove");
|
||||
let delta = event.getDelta();
|
||||
this.node.setPosition(this.node.position.x+delta.x,this.node.position.y+delta.y);
|
||||
}
|
||||
onTouchEnd(){
|
||||
if(this.node.position.y-this.pos_y > 50){
|
||||
this.use_card()
|
||||
}else{
|
||||
this.node.setPosition(this.pos_x,this.pos_y);
|
||||
}
|
||||
console.log(ecs.query(ecs.allOf(HeroCardViewComp)))
|
||||
|
||||
}
|
||||
use_card(){
|
||||
oops.message.dispatchEvent("do_add_hero",this.ent)
|
||||
this.ent.destroy();
|
||||
}
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
this.pos_x=this.node.position.x;
|
||||
this.pos_y=this.node.position.y;
|
||||
}
|
||||
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/monster/HeroCardViewComp.ts.meta
Normal file
9
assets/script/game/monster/HeroCardViewComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ad422ad0-14e7-4547-8703-1bb4d5b10d01",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ export class Monster extends ecs.Entity {
|
||||
/** 加载角色 */
|
||||
load(pos: Vec3 = Vec3.ZERO,speed:number = 100,camp:number = 1,prefab_path:string = "monster",name:string="hero") {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/monster/hero";
|
||||
var path = "game/heros/hero";
|
||||
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
@@ -70,7 +70,7 @@ export class Monster extends ecs.Entity {
|
||||
oops.message.dispatchEvent("monster_load",this)
|
||||
}
|
||||
|
||||
console.log(smc.heros_in,smc.monsters_in)
|
||||
// console.log(smc.heros_in,smc.monsters_in)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
import { Color, Component, EventTouch, sp, Vec3, _decorator } from "cc";
|
||||
import { LayerUtil } from "../../../../extensions/oops-plugin-framework/assets/core/utils/LayerUtil";
|
||||
import { smc } from "../../../script/game/common/SingletonModuleComp";
|
||||
// import Charactor, { CharactorDirection, CharactorState } from "../../map/view/map/charactor/Charactor";
|
||||
import MonsterSpineAnimator from "./MonsterSpineAnimator";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -21,11 +20,9 @@ export class MonsterSpine extends Component {
|
||||
animator: MonsterSpineAnimator = null!;
|
||||
|
||||
private spine!: sp.Skeleton;
|
||||
// private charactor!: Charactor;
|
||||
|
||||
onLoad() {
|
||||
// 角色控制组件
|
||||
// this.charactor = this.addComponent(Charactor)!;
|
||||
|
||||
this.initAnimator();
|
||||
// this.setSkin("magic");
|
||||
@@ -43,16 +40,7 @@ export class MonsterSpine extends Component {
|
||||
|
||||
|
||||
|
||||
// setState(value: CharactorState): void {
|
||||
// switch (value) {
|
||||
// case CharactorState.Idle:
|
||||
// this.idle();
|
||||
// break;
|
||||
// case CharactorState.Run:
|
||||
// this.walk();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
setSkin(value: string): void {
|
||||
console.log("MonsterSpine setSkin", value);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @LastEditTime: 2022-08-17 12:36:18
|
||||
*/
|
||||
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate} from "cc";
|
||||
import { Vec3, _decorator , v3,Collider2D,Contact2DType,IPhysics2DContact,EPhysics2DDrawFlags,Label,Node,Prefab,instantiate,ProgressBar} 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";
|
||||
@@ -17,6 +17,7 @@ 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";
|
||||
import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 角色显示组件 */
|
||||
@@ -30,23 +31,37 @@ export class MonsterViewComp extends CCComp {
|
||||
camp: number = 1;
|
||||
/**角色类型 1:近战 2 远程 */
|
||||
type: number = 1;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
/** 血量 */
|
||||
hp: number = 100;
|
||||
hp_max: number = 100;
|
||||
hp_speed: number = 0; //回复速度
|
||||
/**能量**/
|
||||
power: number = 0;
|
||||
power_max: number = 100;
|
||||
power_speed: number = 1; //回复速度
|
||||
skill_name: string = "base";
|
||||
max_skill_name: string = "base";
|
||||
/**攻击力 */
|
||||
atk: number = 10;
|
||||
/**攻击速度 */
|
||||
// atk_speed: number = 1;
|
||||
atk_cd: number = 1.3;
|
||||
atk_time: number = 0;
|
||||
/** 角色移动速度 */
|
||||
speed: number = 100;
|
||||
/** 角色初始速度 */
|
||||
ospeed: number = 100;
|
||||
/**攻击速度 */
|
||||
atk_speed: number = 1;
|
||||
atk_cd: number = 0;
|
||||
/** 状态 1:move ,2: act 3: stop */
|
||||
state: number = 1;
|
||||
|
||||
Tpos: Vec3 = v3(0,-60,0);
|
||||
timer: number = 0;
|
||||
stop_cd: number = 0;
|
||||
private timer:Timer = new Timer(0.1);
|
||||
is_dead:boolean = false;
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start () {
|
||||
// 注册单个碰撞体的回调函数
|
||||
let collider = this.getComponent(Collider2D);
|
||||
|
||||
if (collider) {
|
||||
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
||||
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
|
||||
@@ -54,37 +69,10 @@ export class MonsterViewComp extends CCComp {
|
||||
collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
switch (selfCollider.group) {
|
||||
case BoxSet.MONSTER:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.HERO:
|
||||
this.state = 2;
|
||||
// console.log('onBeginContact',selfCollider,otherCollider);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
// console.log("speed:"+this.speed+" | timer:"+this.timer);
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
case BoxSet.MONSTER_SKILL:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case BoxSet.HERO:
|
||||
switch (otherCollider.group){
|
||||
case BoxSet.MONSTER:
|
||||
this.state = 2;
|
||||
break;
|
||||
case BoxSet.HERO_SKILL:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
@@ -96,17 +84,47 @@ export class MonsterViewComp extends CCComp {
|
||||
// console.log('onPreSolve');
|
||||
// }
|
||||
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
|
||||
if (otherCollider.group === BoxSet.HERO && selfCollider.group === BoxSet.MONSTER) {
|
||||
// console.log('onPostSolve otherCollider.group :'+otherCollider.group);
|
||||
// this.speed = 0;
|
||||
// this.timer = 1;
|
||||
if(otherCollider.group== BoxSet.HERO_SKILL || otherCollider.group== BoxSet.MONSTER_SKILL){
|
||||
this.in_atked();
|
||||
this.hp_change(10);
|
||||
}
|
||||
// switch (selfCollider.group) {
|
||||
// case BoxSet.HERO:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.MONSTER:
|
||||
// break;
|
||||
// case BoxSet.MONSTER_SKILL:
|
||||
// this.in_atked();
|
||||
// this.hp_change(10);
|
||||
// break;
|
||||
// }
|
||||
// case BoxSet.MONSTER:
|
||||
// switch (otherCollider.group){
|
||||
// case BoxSet.HERO:
|
||||
// // console.log('onBeginContact',selfCollider,otherCollider);
|
||||
// // setTimeout(() => {
|
||||
// // this.toDestroy();
|
||||
// // }, 10);
|
||||
|
||||
// // this.speed = 0;
|
||||
// // this.stop_cd = 1;
|
||||
// // console.log("speed:"+this.speed+" | stop_cd:"+this.stop_cd);
|
||||
// break;
|
||||
// case BoxSet.HERO_SKILL:
|
||||
// this.in_atked();
|
||||
// this.hp_change(10);
|
||||
// break;
|
||||
// // case BoxSet.MONSTER_SKILL:
|
||||
// // break;
|
||||
// }
|
||||
// break;
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
onLoad() {
|
||||
this.as = this.getComponent(MonsterSpine);
|
||||
|
||||
// console.log('hero load ent:',this);
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb |
|
||||
// EPhysics2DDrawFlags.Pair |
|
||||
@@ -116,7 +134,7 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
change_name(hero_name:string='hero',camp:number=1){
|
||||
this.name=hero_name;
|
||||
let label:any =this.node.getChildByName("top").getChildByName("lab_name")
|
||||
let label:any =this.node.getChildByName("lab_name")
|
||||
label.getComponent(Label)!.string = hero_name;
|
||||
let collider = this.getComponent(Collider2D);
|
||||
if(camp==1){
|
||||
@@ -124,10 +142,12 @@ export class MonsterViewComp extends CCComp {
|
||||
}else{
|
||||
collider.group=BoxSet.MONSTER;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(dt: number){
|
||||
|
||||
if (this.timer.update(dt)) {
|
||||
this.power_change(this.power_speed)
|
||||
}
|
||||
this.in_destroy();
|
||||
this.in_stop(dt);
|
||||
this.in_act(dt);
|
||||
@@ -148,22 +168,49 @@ export class MonsterViewComp extends CCComp {
|
||||
move(dt: number){
|
||||
this.node.setPosition(this.node.position.x+dt*this.speed*this.camp, this.node.position.y, this.node.position.z);
|
||||
}
|
||||
power_change(power: number){
|
||||
this.power += power;
|
||||
if(this.power >= this.power_max){
|
||||
this.load_skill(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_cd >= this.atk_speed){
|
||||
this.atk_cd = 0;
|
||||
if(this.atk_time >= this.atk_cd){
|
||||
this.atk_time = 0;
|
||||
// console.log("atk_cd:"+this.atk_cd);
|
||||
this.as.atk();
|
||||
this.load_skill();
|
||||
this.load_skill(this.skill_name);
|
||||
}
|
||||
this.atk_time += dt;
|
||||
}
|
||||
hp_change(hp: number){
|
||||
if(this.is_dead){
|
||||
return;
|
||||
}
|
||||
this.hp -= hp;
|
||||
if(this.hp > this.hp_max){
|
||||
this.hp = this.hp_max;
|
||||
}
|
||||
let hp_progress= this.hp/this.hp_max;
|
||||
this.node.getChildByName("hp").getComponent(ProgressBar)!.progress = hp_progress;
|
||||
if(this.hp <= 0){
|
||||
this.is_dead = true;
|
||||
setTimeout(() => {
|
||||
this.toDestroy();
|
||||
}, 15);
|
||||
|
||||
}
|
||||
this.atk_cd += dt;
|
||||
}
|
||||
/** 静止时间 */
|
||||
in_stop (dt: number) {
|
||||
if(this.timer > 0){
|
||||
this.timer -= dt;
|
||||
if(this.timer <= 0){
|
||||
if(this.stop_cd > 0){
|
||||
this.stop_cd -= dt;
|
||||
if(this.stop_cd <= 0){
|
||||
this.speed = this.ospeed;
|
||||
this.timer = 0;
|
||||
this.stop_cd = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,12 +218,12 @@ export class MonsterViewComp extends CCComp {
|
||||
switch (this.camp) {
|
||||
case -1:
|
||||
if(this.node.position.x < BoxSet.LETF_END){
|
||||
this.reset();
|
||||
this.toDestroy();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(this.node.position.x > BoxSet.RIGHT_END){
|
||||
this.reset();
|
||||
this.toDestroy();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -188,25 +235,38 @@ export class MonsterViewComp extends CCComp {
|
||||
}
|
||||
});
|
||||
}
|
||||
load_skill(){
|
||||
load_skill(skill_name){
|
||||
// console.log("load_skill");
|
||||
let skill = ecs.getEntity<Skill>(Skill);
|
||||
let pos = v3(0,0)
|
||||
let speed =200
|
||||
let speed =150
|
||||
let scale = this.camp
|
||||
let range = 80
|
||||
skill.load(pos,speed,range,scale,this.node);
|
||||
skill.load(pos,speed,range,scale,this.node,skill_name,this.atk);
|
||||
}
|
||||
in_atked() {
|
||||
var path = "game/skills/atked";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
|
||||
let pos = v3(0,0)
|
||||
node.setPosition(pos)
|
||||
node.parent = this.node;
|
||||
}
|
||||
dead(){
|
||||
var path = "game/skills/dead";
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.setPosition(this.node.position)
|
||||
node.parent = this.node.parent;
|
||||
}
|
||||
toDestroy(){
|
||||
this.dead();
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.ent.destroy();
|
||||
}
|
||||
reset() {
|
||||
// console.log("node destroy:",this.node,this.ent)
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
|
||||
this.is_dead = false;
|
||||
this.node.destroy();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user