role 也转为使用hero 预制体

This commit is contained in:
2024-09-02 17:15:30 +08:00
parent 83bd06334f
commit 8b9c04eae3
15 changed files with 299 additions and 223 deletions

View File

@@ -39,8 +39,14 @@
{ {
"__id__": 109 "__id__": 109
}, },
{
"__id__": 115
},
{ {
"__id__": 121 "__id__": 121
},
{
"__id__": 127
} }
], ],
"_active": true, "_active": true,
@@ -123,7 +129,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 5, "y": 1.714,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -998,12 +1004,12 @@
"_offset": { "_offset": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": 0, "x": 0,
"y": 0 "y": 40
}, },
"_size": { "_size": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 120, "width": 1000,
"height": 80 "height": 500
}, },
"_id": "" "_id": ""
}, },
@@ -2041,8 +2047,8 @@
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -30.643, "x": 0,
"y": 70.444, "y": 86.875,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -2444,33 +2450,29 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "hp_max", "_name": "life2",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": { "_parent": {
"__id__": 1 "__id__": 1
}, },
"_children": [ "_children": [],
{
"__id__": 110
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 116 "__id__": 110
}, },
{ {
"__id__": 118 "__id__": 112
} }
], ],
"_prefab": { "_prefab": {
"__id__": 120 "__id__": 114
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -23.203, "x": -36.00100000000003,
"y": 24.334, "y": 24.333999999999946,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -2496,67 +2498,17 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.Node",
"_name": "life2",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 109
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 111
},
{
"__id__": 113
}
],
"_prefab": {
"__id__": 115
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -12.798,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 110 "__id__": 109
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 112 "__id__": 111
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@@ -2580,11 +2532,11 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 110 "__id__": 109
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 114 "__id__": 113
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@@ -2632,13 +2584,63 @@
"targetOverrides": null, "targetOverrides": null,
"nestedPrefabInstanceRoots": null "nestedPrefabInstanceRoots": null
}, },
{
"__type__": "cc.Node",
"_name": "hp_max",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 116
},
{
"__id__": 118
}
],
"_prefab": {
"__id__": 120
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -23.203,
"y": 24.334,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1.0000000000000002,
"y": 1.0000000000000002,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 109 "__id__": 115
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
@@ -2666,7 +2668,7 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 109 "__id__": 115
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
@@ -2743,32 +2745,28 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "atk", "_name": "Heroes_icon",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"_parent": { "_parent": {
"__id__": 1 "__id__": 1
}, },
"_children": [ "_children": [],
{
"__id__": 122
}
],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 128 "__id__": 122
}, },
{ {
"__id__": 130 "__id__": 124
} }
], ],
"_prefab": { "_prefab": {
"__id__": 132 "__id__": 126
}, },
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 21.38304655140837, "x": 37.16004655140836,
"y": 102.51707115199474, "y": 102.51707115199474,
"z": 0 "z": 0
}, },
@@ -2795,67 +2793,17 @@
}, },
"_id": "" "_id": ""
}, },
{
"__type__": "cc.Node",
"_name": "Heroes_icon",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 121
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 123
},
{
"__id__": 125
}
],
"_prefab": {
"__id__": 127
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 15.777,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 122 "__id__": 121
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 124 "__id__": 123
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@@ -2879,11 +2827,11 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 122 "__id__": 121
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
"__id__": 126 "__id__": 125
}, },
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@@ -2931,13 +2879,63 @@
"targetOverrides": null, "targetOverrides": null,
"nestedPrefabInstanceRoots": null "nestedPrefabInstanceRoots": null
}, },
{
"__type__": "cc.Node",
"_name": "atk",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 128
},
{
"__id__": 130
}
],
"_prefab": {
"__id__": 132
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 21.38304655140837,
"y": 102.51707115199474,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1.0000000000000002,
"y": 1.0000000000000002,
"z": 1
},
"_mobility": 0,
"_layer": 1,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 121 "__id__": 127
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
@@ -2965,7 +2963,7 @@
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {}, "__editorExtras__": {},
"node": { "node": {
"__id__": 121 "__id__": 127
}, },
"_enabled": true, "_enabled": true,
"__prefab": { "__prefab": {
@@ -3228,13 +3226,13 @@
"_restitution": 0, "_restitution": 0,
"_offset": { "_offset": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
"x": -0.4, "x": 2,
"y": 65.2 "y": 59.3
}, },
"_size": { "_size": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 89.8, "width": 61.9,
"height": 104.5 "height": 40.9
}, },
"_id": "" "_id": ""
}, },

View File

@@ -78,7 +78,7 @@
"__id__": 1 "__id__": 1
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 3 "__id__": 3

View File

@@ -78,7 +78,7 @@
"__id__": 1 "__id__": 1
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 3 "__id__": 3

View File

@@ -16,6 +16,9 @@ import { RoleSpine } from "./RoleSpine";
import { RoleViewComp } from "./RoleViewComp"; import { RoleViewComp } from "./RoleViewComp";
import { RoleSet } from "../common/config/RoleSet"; import { RoleSet } from "../common/config/RoleSet";
import { MoveToComp } from "../common/ecs/position/MoveTo"; import { MoveToComp } from "../common/ecs/position/MoveTo";
import { MonsterViewComp } from "../monster/MonsterViewComp";
import { MonsterBuffComp } from "../monster/MonsterBuffComp";
import { BoxSet } from "../common/config/BoxSet";
/** 角色实体 */ /** 角色实体 */
@ecs.register(`Role`) @ecs.register(`Role`)
export class Role extends ecs.Entity { export class Role extends ecs.Entity {
@@ -24,7 +27,7 @@ export class Role extends ecs.Entity {
RoleMoveTo!: MoveToComp; // 移动 RoleMoveTo!: MoveToComp; // 移动
// 视图层 // 视图层
RoleView!: RoleViewComp; MonsterView!: MonsterViewComp;
protected init() { protected init() {
this.addComponents<ecs.Comp>( this.addComponents<ecs.Comp>(
@@ -32,42 +35,62 @@ export class Role extends ecs.Entity {
} }
destroy(): void { destroy(): void {
this.remove(RoleViewComp); this.remove(MonsterViewComp);
super.destroy(); super.destroy();
} }
/** 加载角色 */ /** 加载角色 */
load(pos: Vec3 = Vec3.ZERO,uuid:number=101) { load(pos: Vec3 = Vec3.ZERO,uuid:number=101) {
// var path = "game/monster/"+prefab_path; // var path = "game/monster/"+prefab_path;
var path = "game/heros/role"; var path = "game/heros/hero";
var prefab: Prefab = oops.res.get(path, Prefab)!; var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab); var node = instantiate(prefab);
var scene = smc.map.MapView.scene; var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!; node.parent = scene.entityLayer!.node!;
node.setScale(1.5*node.scale.x, 1.5*node.scale.y, node.scale.z);
// var as = node.getComponent(MonsterSpine); // var as = node.getComponent(MonsterSpine);
node.setPosition(pos) node.setPosition(pos)
console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
// const url = 'game/heros/player'; const url = 'game/heros/player';
// resources.load(url, SpriteAtlas, (err: any, atlas) => { resources.load(url, SpriteAtlas, (err: any, atlas) => {
// const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
// sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path); sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path);
// }); });
var rv = node.getComponent(RoleViewComp)!; // var rv = node.getComponent(MonsterViewComp)!;
this.add(rv); // this.add(rv);
this.hero_init(uuid,node) this.hero_init(uuid,node)
} }
move(target: Vec3) { move(target: Vec3) {
var move = this.get(MoveToComp) || this.add(MoveToComp); var move = this.get(MoveToComp) || this.add(MoveToComp);
move.target = target; move.target = target;
move.node = this.RoleView.node; move.node = this.MonsterView.node;
move.speed = 300; move.speed = 300;
} }
hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){ hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(MonsterViewComp)!;
var buff =node.getComponent(MonsterBuffComp)!;
mv.is_role=true;
mv.hero_uuid=uuid;
mv.speed =mv.ospeed = 0;
mv.hero_name= "role";
buff.group= mv.box_group= BoxSet.HERO;
mv.hp= mv.hp_max = 1000;
mv.level = 1;
mv.atk = 5;
mv.atk_cd = 0.5;
mv.power = 300;
mv.type = 1;
mv.skill_uuid = 9001;
mv.max_skill_uuid = 9001;
mv.Tpos = v3(0,0,0);
mv.scale = 1;
mv.atk_range=800;
// mv.change_name(smc.heros[uuid].name,1)
this.add(mv);
this.add(buff);
} }
} }

View File

@@ -21,15 +21,19 @@ export class SingletonModuleComp extends ecs.Comp {
initialize: Initialize = null!; initialize: Initialize = null!;
/** 游戏地图 */ /** 游戏地图 */
map: GameMap = null!; map: GameMap = null!;
player_skills: any = [
];
player_buffs: any = [ player_buffs: any = [
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0}, {x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0},
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y+110,eid:0},
{x:-BoxSet.CSKILL_X+55,y:BoxSet.CSKILL_Y,eid:0}, {x:-BoxSet.CSKILL_X+55,y:BoxSet.CSKILL_Y,eid:0},
{x:-BoxSet.CSKILL_X+110,y:BoxSet.CSKILL_Y,eid:0},
{x:-BoxSet.CSKILL_X+165,y:BoxSet.CSKILL_Y,eid:0},
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X+55,y:BoxSet.CSKILL_Y+55,eid:0}, {x:-BoxSet.CSKILL_X+55,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X+55,y:BoxSet.CSKILL_Y+110,eid:0}, {x:-BoxSet.CSKILL_X+110,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0}, {x:-BoxSet.CSKILL_X+165,y:BoxSet.CSKILL_Y+55,eid:0},
{x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0},
]; ];
monster_buffs: any = []; monster_buffs: any = [];
/** 游戏主角 */ /** 游戏主角 */

View File

@@ -24,14 +24,14 @@ export enum BoxSet {
LETF_END = -420, LETF_END = -420,
RIGHT_END = 420, RIGHT_END = 420,
HERO_START = -260, HERO_START = -260,
MONSTER_START = 300, MONSTER_START = 400,
END_POINT = 360, END_POINT = 360,
//游戏地平线 //游戏地平线
GAME_LINE = 120, GAME_LINE = 100,
CSKILL_X = 320, CSKILL_X = 320,
CSKILL_Y = 200, CSKILL_Y = 400,
//攻击距离 //攻击距离
ATK_RANGE_X = 85, ATK_RANGE_X = 150,
MOVE_RANGE_X = 20, MOVE_RANGE_X = 20,
MAX_SKILL_SY = 50, MAX_SKILL_SY = 50,
MAX_SKILL_BY = 80, MAX_SKILL_BY = 80,

View File

@@ -26,8 +26,8 @@ export const SkillSet={
1002:{uuid: 1002,path: "1002",type: 1,level: 1,name: "寒冰箭",sp_name:"ice",dis:720,count:1,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,}, 1002:{uuid: 1002,path: "1002",type: 1,level: 1,name: "寒冰箭",sp_name:"ice",dis:720,count:1,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,},
4011:{uuid: 4011,path: "1011",type: 1,level: 3,name: "火焰风暴",sp_name:"fire",dis:720,count:5,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,}, 4011:{uuid: 4011,path: "1011",type: 1,level: 3,name: "火焰风暴",sp_name:"fire",dis:720,count:5,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,},
4012:{uuid: 4012,path: "1012",type: 1,level: 3,name: "冰晶风暴",sp_name:"ice",dis:720,count:5,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,}, 4012:{uuid: 4012,path: "1012",type: 1,level: 3,name: "冰晶风暴",sp_name:"ice",dis:720,count:5,atk:10,hp:0,shield:0,sd:10,cd:1,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:350,},
9001:{uuid: 9001,path: "1001",type: 1,level: 1,name: "基础攻击1",sp_name:"base",dis:70,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,}, 9001:{uuid: 9001,path: "1001",type: 1,level: 1,name: "基础攻击1",sp_name:"base",dis:720,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,},
9002:{uuid: 9002,path: "1001",type: 1,level: 1,name: "基础攻击2",sp_name:"base2",dis:70,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,}, 9002:{uuid: 9002,path: "1001",type: 1,level: 1,name: "基础攻击2",sp_name:"base2",dis:720,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,},
9003:{uuid: 9003,path: "1001",type: 2,level: 1,name: "基础攻击3",sp_name:"base3",dis:720,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,}, 9003:{uuid: 9003,path: "1001",type: 2,level: 1,name: "基础攻击3",sp_name:"base3",dis:720,count:1,atk:0,hp:0,shield:0,sd:10,cd:3,bsd:10,bcd:1,sk_uuid:1001,sk_count:0,speed:450,},
6001:{uuid: 6001,path: "6001",type: 92,level: 1,name: "普通单手剑",sp_name:"",dis:720,count:1,atk:10,hp:0,shield:0,sd:30,cd:1,bsd:5,bcd:1,sk_uuid:1001,sk_count:0,speed:350,}, 6001:{uuid: 6001,path: "6001",type: 92,level: 1,name: "普通单手剑",sp_name:"",dis:720,count:1,atk:10,hp:0,shield:0,sd:30,cd:1,bsd:5,bcd:1,sk_uuid:1001,sk_count:0,speed:350,},

View File

@@ -9,13 +9,15 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
import { MapViewScene } from "./view/MapViewScene"; import { MapViewScene } from "./view/MapViewScene";
import { MissionSet,MissionNum,MonsetList } from "../common/config/MissionSet"; import { MissionSet,MissionNum,MonsetList } from "../common/config/MissionSet";
import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager"; import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager";
import { Role } from "../Role/Role";
import { Hero } from "../monster/Hero";
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
/** 视图层对象 */ /** 视图层对象 */
@ccclass('MapMonsterComp') @ccclass('MapMonsterComp')
@ecs.register('MapMonster', false) @ecs.register('MapMonster', false)
export class MapMonsterComp extends CCComp { export class MapMonsterComp extends CCComp {
// scene: MapViewScene = null; scene: MapViewScene = null;
max_count: number = 99 ; //最大波次 max_count: number = 99 ; //最大波次
cur_count: number = 1; //波次 cur_count: number = 1; //波次
boss_count: number = 10; //boss波次间隔 boss_count: number = 10; //boss波次间隔
@@ -33,9 +35,13 @@ export class MapMonsterComp extends CCComp {
onLoad(){ onLoad(){
// 监听全局事件 // 监听全局事件
oops.message.on("other_add_monster", this.on_other_add_monster, this); oops.message.on("other_add_monster", this.on_other_add_monster, this);
oops.message.on("do_add_hero", this.on_do_add_hero, this);
} }
start() { start() {
// this.scene = this.getComponent(MapViewScene);
// this.scene.node.active = true
// this.scene = this.getComponent(MapViewScene); // this.scene = this.getComponent(MapViewScene);
let num =RandomManager.instance.getRandomByObjectList(MissionNum,1) let num =RandomManager.instance.getRandomByObjectList(MissionNum,1)
this.cur_mission = num[0] this.cur_mission = num[0]
@@ -43,6 +49,8 @@ export class MapMonsterComp extends CCComp {
// console.log("当前关卡方案",this.cur_mission,this.mission_list) // console.log("当前关卡方案",this.cur_mission,this.mission_list)
this.refresh_timer= new Timer(smc.vm_data.gold.cd*5); this.refresh_timer= new Timer(smc.vm_data.gold.cd*5);
this.monster_refresh() this.monster_refresh()
this.load_role()
} }
protected update(dt: number): void { protected update(dt: number): void {
if(this.setp_timer.update(dt)){ if(this.setp_timer.update(dt)){
@@ -60,6 +68,24 @@ export class MapMonsterComp extends CCComp {
// } // }
// this.shuaxin(dt) // this.shuaxin(dt)
} }
load_role(){
let role = ecs.getEntity<Role>(Role);
let pos = v3(BoxSet.HERO_START-50,BoxSet.GAME_LINE)
role.load(pos,108)
smc.Role=role
console.log("加载玩家",role)
}
private on_do_add_hero(event: string, args: any) {
this.addHero(args.uuid)
}
/** 添加玩家 */
private addHero(uuid:number=1001) {
let hero = ecs.getEntity<Hero>(Hero);
let {pos,monster_layer}=this.set_layer(BoxSet.HERO_START)
let scale = 1
hero.load(pos,scale,uuid,monster_layer);
}
monster_refresh(){ monster_refresh(){
if (this.setp_num <= 0){ if (this.setp_num <= 0){
return return
@@ -73,26 +99,28 @@ export class MapMonsterComp extends CCComp {
} }
private addMonster(uuid:number=1101) { private addMonster(uuid:number=1101) {
let monster = ecs.getEntity<Monster>(Monster); let monster = ecs.getEntity<Monster>(Monster);
let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE)
let scale = -1 let scale = -1
let {pos,monster_layer}=this.set_layer(BoxSet.MONSTER_START)
monster.load(pos,scale,uuid,monster_layer);
}
set_layer(start:number=0){
var scene = smc.map.MapView.scene; var scene = smc.map.MapView.scene;
let pos:Vec3 = v3(start,BoxSet.GAME_LINE)
let x = RandomManager.instance.getRandomInt(0,2, 2); let x = RandomManager.instance.getRandomInt(0,2, 2);
let monster_layer = scene.entityLayer!.node! let monster_layer = scene.entityLayer!.node!
switch (x) { switch (x) {
case 1: case 1:
monster_layer = scene.entityLayer1!.node!; // monster_layer = scene.entityLayer1!.node!;
pos.y=pos.y+100; pos.y=pos.y+95;
break; break;
case 2: case 2:
monster_layer= scene.entityLayer2!.node!; // monster_layer= scene.entityLayer2!.node!;
pos.y=pos.y-100; pos.y=pos.y-95;
default:
break; break;
}
monster.load(pos,scale,uuid,monster_layer);
} }
return {pos,monster_layer}
}
private on_other_add_monster(event: string, args: any) { private on_other_add_monster(event: string, args: any) {
this.addMonster(args.uuid) this.addMonster(args.uuid)
} }

View File

@@ -16,21 +16,15 @@ const { ccclass, property } = _decorator;
@ecs.register('MapView', false) @ecs.register('MapView', false)
export class MapViewComp extends CCComp { export class MapViewComp extends CCComp {
scene: MapViewScene = null!; scene: MapViewScene = null!;
current_map: any;
private game_timer: Timer = new Timer(1); private game_timer: Timer = new Timer(1);
private mapLoaded() { private mapLoaded() {
} }
async onLoad(){ async onLoad(){
// 监听全局事件 // 监听全局事件
oops.message.on("do_add_hero", this.on_do_add_hero, this);
} }
/**监听do_add_hero 添加hero,通过uuid */
private on_do_add_hero(event: string, args: any) {
// console.log("do_add_hero",args.uuid)
this.addHero(args.uuid)
}
reset(): void { reset(): void {
//撤销监听 //撤销监听
// oops.message.off("do_add_hero", this.on_do_add_hero, this); // oops.message.off("do_add_hero", this.on_do_add_hero, this);
@@ -41,12 +35,7 @@ export class MapViewComp extends CCComp {
this.load_data() this.load_data()
// this.load_role() // this.load_role()
} }
load_role(){
let role = ecs.getEntity<Role>(Role);
let pos = v3(BoxSet.HERO_START-50,BoxSet.GAME_LINE)
role.load(pos,108)
smc.Role=role
}
load_data(){ load_data(){
// let heros = oops.res.get("config/game/heros") // let heros = oops.res.get("config/game/heros")
// console.log("heros",heros) // console.log("heros",heros)
@@ -79,14 +68,7 @@ export class MapViewComp extends CCComp {
smc.vm_data.shuaxin.min = 0; smc.vm_data.shuaxin.min = 0;
} }
} }
/** 添加玩家 */
private addHero(uuid:number=1001) {
this.scene.node.active = true
let hero = ecs.getEntity<Hero>(Hero);
let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE)
let scale = 1
hero.load(pos,scale,uuid);
}
} }

View File

@@ -15,12 +15,13 @@ export class BoxRangComp extends CCComp {
box_group:number = BoxSet.DEFAULT; box_group:number = BoxSet.DEFAULT;
box_tag:number = BoxSet.ATK_RANGE; box_tag:number = BoxSet.ATK_RANGE;
offset_x:number = 0; offset_x:number = 0;
atk_range:number = 150;
/** 视图层逻辑代码分离演示 */ /** 视图层逻辑代码分离演示 */
start() { start() {
let collider = this.getComponent(Collider2D); let collider = this.getComponent(Collider2D);
collider.group = this.box_group; collider.group = this.box_group;
collider.tag = this.box_tag; collider.tag = this.box_tag;
collider.offset = v2(this.offset_x,0); // collider.offset = v2(this.offset_x,40);
this.Hero_node = this.node.parent; this.Hero_node = this.node.parent;
this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp); this.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp);
// console.log("range box",this.MonsterViewComp); // console.log("range box",this.MonsterViewComp);
@@ -42,9 +43,11 @@ export class BoxRangComp extends CCComp {
// } // }
} }
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){ if(selfCollider.group != otherCollider.group&&otherCollider.tag == 0 ){
// console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag); // console.log(this.node.name+"onEndContact: seft:"+selfCollider.group+"|other:"+otherCollider.group+"| tag: seft:"+selfCollider.tag+"|other:"+otherCollider.tag);
this.MonsterViewComp.is_atking = false; this.MonsterViewComp.is_atking = false;
this.MonsterViewComp.enemy = null;
} }
} }
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
@@ -53,9 +56,17 @@ export class BoxRangComp extends CCComp {
let other_pos = otherCollider.node.getWorldPosition() ; let other_pos = otherCollider.node.getWorldPosition() ;
let self_pos = this.node.getWorldPosition(); let self_pos = this.node.getWorldPosition();
// console.log("onPreSolve:",self_pos,other_pos); // console.log("onPreSolve:",self_pos,other_pos);
if(Math.abs(other_pos.x-self_pos.x) < BoxSet.ATK_RANGE_X){ if(this.MonsterViewComp.enemy==null){
this.MonsterViewComp.enemy = otherCollider.node;
}else{
if(this.MonsterViewComp.enemy.isValid==false){
this.MonsterViewComp.enemy = otherCollider.node;
}
}
if(Math.abs(other_pos.x-self_pos.x) < this.atk_range){
this.MonsterViewComp.is_atking = true; this.MonsterViewComp.is_atking = true;
// this.MonsterViewComp.stop_cd = 0.1 this.MonsterViewComp.stop_cd = 0.1
} }
} }

View File

@@ -37,7 +37,12 @@ export class CSkill extends ecs.Entity {
node.parent = scene.entityLayer!.node!; node.parent = scene.entityLayer!.node!;
node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z); node.getChildByName("skill").setScale(node.getChildByName("skill").scale.x*scale, node.getChildByName("skill").scale.y, node.getChildByName("skill").scale.z);
// let cskills = ecs.query(ecs.allOf(CSkillComp)) // let cskills = ecs.query(ecs.allOf(CSkillComp))
if(SkillSet[uuid].type >= 90){
pos = this.add_buff() pos = this.add_buff()
}else{
pos = this.add_skill()
}
// console.log("load skill",pos,smc.player_buffs) // console.log("load skill",pos,smc.player_buffs)
node.setPosition(pos.x*scale,pos.y,pos.z) node.setPosition(pos.x*scale,pos.y,pos.z)
// console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite))
@@ -52,7 +57,7 @@ export class CSkill extends ecs.Entity {
} }
add_buff(){ add_buff(){
let pos = v3(0,0,0) let pos = v3(0,0,0)
for (let index = 0; index < 8; index++) { for (let index = 0; index < 4; index++) {
if(smc.player_buffs[index].eid == 0){ if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y pos.y=smc.player_buffs[index].y
@@ -63,6 +68,18 @@ export class CSkill extends ecs.Entity {
} }
return pos return pos
} }
add_skill(){
let pos = v3(0,0,0)
for (let index = 4; index < 8; index++) {
if(smc.player_buffs[index].eid == 0){
pos.x=smc.player_buffs[index].x
pos.y=smc.player_buffs[index].y
smc.player_buffs[index].eid=this.eid
break
}
}
return pos
}
skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){ skill_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){
var mv = node.getComponent(CSkillComp) var mv = node.getComponent(CSkillComp)
mv.scale = 1; mv.scale = 1;

View File

@@ -98,7 +98,7 @@ export class CSkillComp extends CCComp {
// 94role 临时buff // 94role 临时buff
// 95role 永久buff // 95role 永久buff
let uuid= this.skill_uuid; let uuid= this.skill_uuid;
let atk:number=smc.Role.RoleView.atk let atk:number=smc.Role.MonsterView.atk
let args:any = { let args:any = {
atk:atk*GameSet.ATK_TO_ATK_RATIO, atk:atk*GameSet.ATK_TO_ATK_RATIO,
hp:atk*GameSet.ATK_TO_HP_RATIO, hp:atk*GameSet.ATK_TO_HP_RATIO,

View File

@@ -38,16 +38,12 @@ export class Hero 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/monster/"+prefab_path;
var path = "game/heros/hero"; var path = "game/heros/hero";
var prefab: Prefab = oops.res.get(path, Prefab)!; var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab); var node = instantiate(prefab);
var scene = smc.map.MapView.scene; node.parent=layer
node.parent = scene.entityLayer!.node!;
// var as = node.getComponent(MonsterSpine);
let ratio=this.set_ratio(uuid); let ratio=this.set_ratio(uuid);
node.setScale(ratio*node.scale.x, ratio*node.scale.y, node.scale.z); node.setScale(ratio*node.scale.x, ratio*node.scale.y, node.scale.z);

View File

@@ -37,7 +37,9 @@ export class MonsterViewComp extends CCComp {
BoxRang:Node =null! BoxRang:Node =null!
buff:MonsterBuffComp =null! buff:MonsterBuffComp =null!
is_role:boolean = false;
enemy_pos:Vec3=null!;
enemy:any=null!;
/** 角色动画 */ /** 角色动画 */
as: MonsterSpine = null!; as: MonsterSpine = null!;
hero_uuid:number = 1001; hero_uuid:number = 1001;
@@ -74,7 +76,7 @@ export class MonsterViewComp extends CCComp {
shield_time:number = 0; //护盾持续时间 shield_time:number = 0; //护盾持续时间
box_group:number = 2; box_group:number = 2;
atk_range:number = 150;
private timer:Timer = new Timer(0.1); //计时器 private timer:Timer = new Timer(0.1); //计时器
is_dead:boolean = false; //是否摧毁 is_dead:boolean = false; //是否摧毁
is_stop:boolean = false; is_stop:boolean = false;
@@ -88,10 +90,15 @@ export class MonsterViewComp extends CCComp {
start () { start () {
this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); this.sprite = this.node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite);
this.node.getChildByName("top").setScale(this.scale,1); this.node.getChildByName("top").setScale(this.scale,1);
this.node.getChildByName("atk").setScale(this.scale,1);
this.node.getChildByName("hp_max").setScale(this.scale,1);
this.orginalFlashMaterial = this.sprite.getRenderMaterial(0); this.orginalFlashMaterial = this.sprite.getRenderMaterial(0);
this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group; this.BoxRang.getComponent(BoxRangComp).box_group = this.box_group;
this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis; this.BoxRang.getComponent(BoxRangComp).atk_range = this.atk_range
// this.BoxRang.getComponent(BoxRangComp).offset_x = this.scale*smc.skills[this.skill_uuid].dis/3;
// console.log("monseter ",this.BoxRang); // console.log("monseter ",this.BoxRang);
this.buff.group=this.box_group this.buff.group=this.box_group
@@ -139,7 +146,6 @@ export class MonsterViewComp extends CCComp {
if(self_pos.x < other_pos.x){ if(self_pos.x < other_pos.x){
this.stop_cd=0.1 this.stop_cd=0.1
} }
this.stop_cd=0.1
break; break;
case BoxSet.MONSTER: case BoxSet.MONSTER:
if(self_pos.x > other_pos.x){ if(self_pos.x > other_pos.x){
@@ -188,12 +194,23 @@ export class MonsterViewComp extends CCComp {
// console.log("monster shoot"); // console.log("monster shoot");
let skill = ecs.getEntity<Skill>(Skill); let skill = ecs.getEntity<Skill>(Skill);
let x=32 let x=32
let pos = v3(35*this.scale,40) let pos = v3(35*this.scale,50)
let scale = this.scale let scale = this.scale
let speed =smc.skills[skill_uuid].speed; let speed =smc.skills[skill_uuid].speed;
let dis = smc.skills[skill_uuid].dis; let dis = smc.skills[skill_uuid].dis;
let atk = smc.skills[skill_uuid].atk+this.atk; let atk = smc.skills[skill_uuid].atk+this.atk;
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk); let angle=0
let t_pos:Vec3 = v3(0,0)
if(this.enemy){
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){
angle = angle +180
}
}else{
t_pos=null
}
skill.load(pos,speed,dis,scale,this.node,skill_uuid,atk,angle,t_pos);
// this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid); // this.tooltip(3,smc.skills[skill_uuid].name,this.skill_uuid);
} }
//使用max_skill //使用max_skill

View File

@@ -108,7 +108,7 @@ export class SkillCom extends CCComp {
} }
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
if(otherCollider.group != selfCollider.group&&otherCollider.tag !=BoxSet.ATK_RANGE&&otherCollider.tag !=BoxSet.SKILL_TAG){ if(otherCollider.group != selfCollider.group&&otherCollider.tag ==0){
this.atk_count+=1 this.atk_count+=1
// console.log("skill onBeginContact",selfCollider.group,otherCollider.group) // console.log("skill onBeginContact",selfCollider.group,otherCollider.group)
if(this.type==1 ){ if(this.type==1 ){
@@ -148,7 +148,7 @@ export class SkillCom extends CCComp {
// this.move(deltaTime) // this.move(deltaTime)
this.toDestroy() this.toDestroy()
// this.t_move(deltaTime) // this.t_move(deltaTime)
if (this.node.position.x > 400||this.node.position.x < -400||this.node.position.y > 1000||this.node.position.y < BoxSet.GAME_LINE) { if (this.node.position.x > 400||this.node.position.x < -400||this.node.position.y > 1000||this.node.position.y < -100) {
this.is_destroy=true this.is_destroy=true
} }
} }