dd
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { _decorator,v3 } from "cc";
|
||||
import { _decorator,Label,resources,Sprite,SpriteAtlas,v3 } 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 { smc } from "../common/SingletonModuleComp";
|
||||
@@ -15,6 +15,12 @@ const { ccclass, property } = _decorator;
|
||||
export class CardControllerComp extends CCComp {
|
||||
card_level:number = 1;
|
||||
in_load:boolean = false
|
||||
card1:any ={x:0,y:0,uuid:1101,type:1,active:false}
|
||||
card2:any ={x:0,y:0,uuid:1102,type:1,active:false}
|
||||
card3:any ={x:0,y:0,uuid:1103,type:1,active:false}
|
||||
card4:any ={x:0,y:0,uuid:1104,type:1,active:false}
|
||||
card5:any ={x:0,y:0,uuid:1105,type:1,active:false}
|
||||
card6:any ={x:0,y:0,uuid:1106,type:1,active:false}
|
||||
start() {
|
||||
this.load_cards()
|
||||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||||
@@ -76,40 +82,54 @@ export class CardControllerComp extends CCComp {
|
||||
}
|
||||
load_cards() {
|
||||
this.in_load = true
|
||||
let old_cards = ecs.query(ecs.allOf(HeroCardViewComp))
|
||||
if (old_cards.length > 0) {
|
||||
old_cards.forEach(element => {
|
||||
if (!element.get(HeroCardViewComp).in_destroy) {
|
||||
element.destroy();
|
||||
}
|
||||
let card:any=null
|
||||
for (let index = 1; index <= 6; index++) {
|
||||
card=RandomManager.instance.getRandomByObjectList(CardList, 1);
|
||||
this['card'+index].uuid=card[0].uuid
|
||||
this['card'+index].type=card[0].type
|
||||
let url: string = "";
|
||||
let pathName: string = "";
|
||||
let name: string = "";
|
||||
let level: number = 0;
|
||||
let { uuid, type } = card[0];
|
||||
switch (type) {
|
||||
case 1:
|
||||
url = "game/heros/heros";
|
||||
({ path: pathName, name, level } = smc.heros[uuid]);
|
||||
break;
|
||||
case 2:
|
||||
url = "game/heros/skill";
|
||||
({ path: pathName, name, level } = smc.skills[uuid]);
|
||||
break;
|
||||
case 3:
|
||||
default:
|
||||
url = "game/heros/skill";
|
||||
({ path: pathName, name, level } = smc.skills[uuid]);
|
||||
}
|
||||
let node=this.node.getChildByName('cards').getChildByName('card'+index)
|
||||
node.getChildByName('cost').getComponent(Label).string=level.toString()
|
||||
node.getChildByName('name').getComponent(Label).string=name
|
||||
// const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
// console.log(this['card'+index],url,pathName,sprite)
|
||||
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("item").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
||||
});
|
||||
this['card'+index].active=true
|
||||
}
|
||||
// console.log(old_cards)
|
||||
let cards_node= this.node.getChildByName("front")
|
||||
let x=0
|
||||
let y=0
|
||||
let lists = this.get_card_list()
|
||||
lists.forEach(element => {
|
||||
let card = ecs.getEntity<HeroCard>(HeroCard);
|
||||
let pos = v3(x,y)
|
||||
card.load(pos,element[0].uuid,cards_node,element[0].type);
|
||||
x=x+142
|
||||
});
|
||||
this.in_load = false;
|
||||
|
||||
|
||||
}
|
||||
load_card(){
|
||||
|
||||
}
|
||||
/** 转场 */
|
||||
protected update(dt: number): void {
|
||||
this.shuaxin(dt)
|
||||
}
|
||||
|
||||
get_card_list(){
|
||||
let lists:any = []
|
||||
for (let index = 0; index < 5; index++) {
|
||||
let list = RandomManager.instance.getRandomByObjectList(CardList[smc.vm_data.cards.level], 1);
|
||||
lists.push(list)
|
||||
}
|
||||
return lists
|
||||
let list = RandomManager.instance.getRandomByObjectList(CardList, 1);
|
||||
return list
|
||||
}
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ControllerComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
|
||||
@@ -11,6 +11,10 @@ import { MissionSet,MissionNum,MonsetList } from "../common/config/MissionSet";
|
||||
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
|
||||
import { Role } from "../Role/Role";
|
||||
import { Hero } from "../monster/Hero";
|
||||
import { HeroModelComp } from "../monster/HeroModelComp";
|
||||
import { MonsterModelComp } from "../monster/MonsterModelComp";
|
||||
import { MonsterViewComp } from "../monster/MonsterViewComp";
|
||||
import { Mon } from "../mon/Mon";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@@ -31,7 +35,8 @@ export class MapMonsterComp extends CCComp {
|
||||
cur_mission:number = 1; //当前关卡方案
|
||||
mission_list:any = []
|
||||
setp_timer: Timer = new Timer(0.5);
|
||||
setp_num:number = 3;
|
||||
target_timer: Timer = new Timer(0.1);
|
||||
setp_num:number = 1;
|
||||
onLoad(){
|
||||
// 监听全局事件
|
||||
oops.message.on("other_add_monster", this.on_other_add_monster, this);
|
||||
@@ -57,17 +62,62 @@ 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 = 1
|
||||
}
|
||||
if (this.mission_up_timer.update(dt)) {
|
||||
// 刷新怪物定时器
|
||||
this.cur_count += 1;
|
||||
}
|
||||
// if(this.target_timer.update(dt)){
|
||||
// this.target_update()
|
||||
// }
|
||||
// if (this.game_timer.update(dt)) {
|
||||
// smc.vm_data.game.g_time += 1;
|
||||
// }
|
||||
// this.shuaxin(dt)
|
||||
}
|
||||
target_update(){
|
||||
console.log("map ",smc.t_hero,smc.t_monster)
|
||||
let heros:any = ecs.query(ecs.allOf(HeroModelComp));
|
||||
let monsters:any =ecs.query(ecs.allOf(MonsterModelComp));
|
||||
let h_x=-1000
|
||||
let m_x=1000
|
||||
let thi=9999
|
||||
let tmi=9999
|
||||
for (let i = 0; i < heros.length; i++) {
|
||||
const hero = heros[i];
|
||||
if(hero.MonsterView.node.position.x > h_x){
|
||||
h_x = hero.MonsterView.node.position.x
|
||||
thi = i
|
||||
if(smc.t_hero.eid == hero.MonsterView.eid){
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < monsters.length; i++) {
|
||||
const monster = monsters[i];
|
||||
if(monster.MonsterView.node.position.x < m_x){
|
||||
m_x = monster.MonsterView.node.position.x
|
||||
tmi = i
|
||||
if(smc.t_monster.eid == monster.MonsterView.eid){
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if(thi==9999){
|
||||
smc.t_hero={eid:0,pos:v3(0,0,0)}
|
||||
}else{
|
||||
smc.t_hero = {eid:heros[thi].MonsterView.eid,pos:v3(heros[thi].MonsterView.node.position,heros[thi].MonsterView.node.position.y)}
|
||||
|
||||
}
|
||||
|
||||
if(tmi==9999){
|
||||
smc.t_monster={eid:0,pos:v3(0,0,0)}
|
||||
}else{
|
||||
smc.t_monster ={eid:monsters[tmi].MonsterView.eid,pos:v3(monsters[tmi].MonsterView.node.position,monsters[tmi].MonsterView.node.position.y)}
|
||||
}
|
||||
|
||||
}
|
||||
load_role(){
|
||||
let role = ecs.getEntity<Role>(Role);
|
||||
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
|
||||
@@ -93,15 +143,26 @@ export class MapMonsterComp extends CCComp {
|
||||
// console.log("当前波数",this.cur_count)
|
||||
// console.log("当前怪物池",this.mission_list[this.monster_level])
|
||||
let m:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],1)
|
||||
let m1:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],1)
|
||||
let m2:any = RandomManager.instance.getRandomByObjectList(this.mission_list[this.monster_level],1)
|
||||
// console.log("刷怪",m)
|
||||
this.addMonster(m[0])
|
||||
var scene = smc.map.MapView.scene;
|
||||
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
|
||||
let pos1:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE+60)
|
||||
let pos2:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE-60)
|
||||
|
||||
let monster_layer = scene.entityLayer!.node!
|
||||
let monster_layer1 = scene.entityLayer1!.node!;
|
||||
let monster_layer2 = scene.entityLayer2!.node!;
|
||||
this.addMonster(m[0],monster_layer,pos)
|
||||
this.addMonster(m1[0],monster_layer1,pos1)
|
||||
this.addMonster(m2[0],monster_layer2,pos2)
|
||||
this.setp_num -= 1
|
||||
}
|
||||
private addMonster(uuid:number=1101) {
|
||||
let monster = ecs.getEntity<Monster>(Monster);
|
||||
private addMonster(uuid:number=1001,layer:any,pos:Vec3=v3(0,0,0)) {
|
||||
let monster = ecs.getEntity<Mon>(Mon);
|
||||
let scale = -1
|
||||
let {pos,monster_layer}=this.set_layer(BoxSet.MONSTER_START)
|
||||
monster.load(pos,scale,uuid,monster_layer);
|
||||
monster.load(pos,scale,uuid,layer);
|
||||
}
|
||||
set_layer(start:number=0){
|
||||
var scene = smc.map.MapView.scene;
|
||||
@@ -122,7 +183,10 @@ export class MapMonsterComp extends CCComp {
|
||||
return {pos,monster_layer}
|
||||
}
|
||||
private on_other_add_monster(event: string, args: any) {
|
||||
this.addMonster(args.uuid)
|
||||
var scene = smc.map.MapView.scene;
|
||||
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
|
||||
let monster_layer = scene.entityLayer!.node!
|
||||
this.addMonster(args.uuid,monster_layer,pos)
|
||||
}
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import { Monster } from "../../monster/Monster";
|
||||
import { MapViewScene } from "./MapViewScene";
|
||||
import { Timer } from "../../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer";
|
||||
import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { CardSet } from "../../common/config/CardSet";
|
||||
import { Role } from "../../Role/Role";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user