From 8b9c04eae3ed70374c6cc3d28f7951d3ef944c6c Mon Sep 17 00:00:00 2001 From: "pan@work" Date: Mon, 2 Sep 2024 17:15:30 +0800 Subject: [PATCH] =?UTF-8?q?role=20=E4=B9=9F=E8=BD=AC=E4=B8=BA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8hero=20=E9=A2=84=E5=88=B6=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/game/heros/hero.prefab | 284 +++++++++--------- assets/resources/game/skills/base.prefab | 2 +- assets/resources/game/skills/base2.prefab | 2 +- assets/script/game/Role/Role.ts | 49 ++- .../script/game/common/SingletonModuleComp.ts | 14 +- assets/script/game/common/config/BoxSet.ts | 8 +- assets/script/game/common/config/SkillSet.ts | 4 +- assets/script/game/map/MapMonsterComp.ts | 48 ++- assets/script/game/map/view/MapViewComp.ts | 24 +- assets/script/game/monster/BoxRangComp.ts | 17 +- assets/script/game/monster/CSkill.ts | 21 +- assets/script/game/monster/CSkillComp.ts | 2 +- assets/script/game/monster/Hero.ts | 12 +- assets/script/game/monster/MonsterViewComp.ts | 31 +- assets/script/game/skills/SkillCom.ts | 4 +- 15 files changed, 299 insertions(+), 223 deletions(-) diff --git a/assets/resources/game/heros/hero.prefab b/assets/resources/game/heros/hero.prefab index 0256562d..c5d3560e 100644 --- a/assets/resources/game/heros/hero.prefab +++ b/assets/resources/game/heros/hero.prefab @@ -39,8 +39,14 @@ { "__id__": 109 }, + { + "__id__": 115 + }, { "__id__": 121 + }, + { + "__id__": 127 } ], "_active": true, @@ -123,7 +129,7 @@ "_lpos": { "__type__": "cc.Vec3", "x": 0, - "y": 5, + "y": 1.714, "z": 0 }, "_lrot": { @@ -998,12 +1004,12 @@ "_offset": { "__type__": "cc.Vec2", "x": 0, - "y": 0 + "y": 40 }, "_size": { "__type__": "cc.Size", - "width": 120, - "height": 80 + "width": 1000, + "height": 500 }, "_id": "" }, @@ -2041,8 +2047,8 @@ }, "_lpos": { "__type__": "cc.Vec3", - "x": -30.643, - "y": 70.444, + "x": 0, + "y": 86.875, "z": 0 }, "_lrot": { @@ -2444,33 +2450,29 @@ }, { "__type__": "cc.Node", - "_name": "hp_max", + "_name": "life2", "_objFlags": 0, "__editorExtras__": {}, "_parent": { "__id__": 1 }, - "_children": [ - { - "__id__": 110 - } - ], + "_children": [], "_active": true, "_components": [ { - "__id__": 116 + "__id__": 110 }, { - "__id__": 118 + "__id__": 112 } ], "_prefab": { - "__id__": 120 + "__id__": 114 }, "_lpos": { "__type__": "cc.Vec3", - "x": -23.203, - "y": 24.334, + "x": -36.00100000000003, + "y": 24.333999999999946, "z": 0 }, "_lrot": { @@ -2496,67 +2498,17 @@ }, "_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", "_name": "", "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 110 + "__id__": 109 }, "_enabled": true, "__prefab": { - "__id__": 112 + "__id__": 111 }, "_contentSize": { "__type__": "cc.Size", @@ -2580,11 +2532,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 110 + "__id__": 109 }, "_enabled": true, "__prefab": { - "__id__": 114 + "__id__": 113 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -2632,13 +2584,63 @@ "targetOverrides": 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", "_name": "", "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 109 + "__id__": 115 }, "_enabled": true, "__prefab": { @@ -2666,7 +2668,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 109 + "__id__": 115 }, "_enabled": true, "__prefab": { @@ -2743,32 +2745,28 @@ }, { "__type__": "cc.Node", - "_name": "atk", + "_name": "Heroes_icon", "_objFlags": 0, "__editorExtras__": {}, "_parent": { "__id__": 1 }, - "_children": [ - { - "__id__": 122 - } - ], + "_children": [], "_active": true, "_components": [ { - "__id__": 128 + "__id__": 122 }, { - "__id__": 130 + "__id__": 124 } ], "_prefab": { - "__id__": 132 + "__id__": 126 }, "_lpos": { "__type__": "cc.Vec3", - "x": 21.38304655140837, + "x": 37.16004655140836, "y": 102.51707115199474, "z": 0 }, @@ -2795,67 +2793,17 @@ }, "_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", "_name": "", "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 122 + "__id__": 121 }, "_enabled": true, "__prefab": { - "__id__": 124 + "__id__": 123 }, "_contentSize": { "__type__": "cc.Size", @@ -2879,11 +2827,11 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 122 + "__id__": 121 }, "_enabled": true, "__prefab": { - "__id__": 126 + "__id__": 125 }, "_customMaterial": null, "_srcBlendFactor": 2, @@ -2931,13 +2879,63 @@ "targetOverrides": 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", "_name": "", "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 121 + "__id__": 127 }, "_enabled": true, "__prefab": { @@ -2965,7 +2963,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 121 + "__id__": 127 }, "_enabled": true, "__prefab": { @@ -3228,13 +3226,13 @@ "_restitution": 0, "_offset": { "__type__": "cc.Vec2", - "x": -0.4, - "y": 65.2 + "x": 2, + "y": 59.3 }, "_size": { "__type__": "cc.Size", - "width": 89.8, - "height": 104.5 + "width": 61.9, + "height": 40.9 }, "_id": "" }, diff --git a/assets/resources/game/skills/base.prefab b/assets/resources/game/skills/base.prefab index 2864f40a..2c13c23d 100644 --- a/assets/resources/game/skills/base.prefab +++ b/assets/resources/game/skills/base.prefab @@ -78,7 +78,7 @@ "__id__": 1 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 3 diff --git a/assets/resources/game/skills/base2.prefab b/assets/resources/game/skills/base2.prefab index 3181cd78..e08718ef 100644 --- a/assets/resources/game/skills/base2.prefab +++ b/assets/resources/game/skills/base2.prefab @@ -78,7 +78,7 @@ "__id__": 1 }, "_children": [], - "_active": false, + "_active": true, "_components": [ { "__id__": 3 diff --git a/assets/script/game/Role/Role.ts b/assets/script/game/Role/Role.ts index 67ad8d69..069833e4 100644 --- a/assets/script/game/Role/Role.ts +++ b/assets/script/game/Role/Role.ts @@ -16,6 +16,9 @@ import { RoleSpine } from "./RoleSpine"; import { RoleViewComp } from "./RoleViewComp"; import { RoleSet } from "../common/config/RoleSet"; 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`) export class Role extends ecs.Entity { @@ -24,7 +27,7 @@ export class Role extends ecs.Entity { RoleMoveTo!: MoveToComp; // 移动 // 视图层 - RoleView!: RoleViewComp; + MonsterView!: MonsterViewComp; protected init() { this.addComponents( @@ -32,42 +35,62 @@ export class Role extends ecs.Entity { } destroy(): void { - this.remove(RoleViewComp); + this.remove(MonsterViewComp); super.destroy(); } /** 加载角色 */ load(pos: Vec3 = Vec3.ZERO,uuid:number=101) { // 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 node = instantiate(prefab); var scene = smc.map.MapView.scene; 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); node.setPosition(pos) console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) - // const url = 'game/heros/player'; - // resources.load(url, SpriteAtlas, (err: any, atlas) => { - // const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); + const url = 'game/heros/player'; + resources.load(url, SpriteAtlas, (err: any, atlas) => { + const sprite = node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite); - // sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path); - // }); - var rv = node.getComponent(RoleViewComp)!; - this.add(rv); + sprite.spriteFrame = atlas.getSpriteFrame(RoleSet[uuid].path); + }); + // var rv = node.getComponent(MonsterViewComp)!; + // this.add(rv); this.hero_init(uuid,node) } move(target: Vec3) { var move = this.get(MoveToComp) || this.add(MoveToComp); move.target = target; - move.node = this.RoleView.node; + move.node = this.MonsterView.node; move.speed = 300; } 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); } - } \ No newline at end of file diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 8be223bc..b4659b89 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -21,15 +21,19 @@ export class SingletonModuleComp extends ecs.Comp { initialize: Initialize = null!; /** 游戏地图 */ map: GameMap = null!; + player_skills: any = [ + ]; player_buffs: any = [ + {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+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+110,eid:0}, - {x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0}, - {x:-BoxSet.CSKILL_X,y:BoxSet.CSKILL_Y,eid:0}, + {x:-BoxSet.CSKILL_X+110,y:BoxSet.CSKILL_Y+55,eid:0}, + {x:-BoxSet.CSKILL_X+165,y:BoxSet.CSKILL_Y+55,eid:0}, ]; monster_buffs: any = []; /** 游戏主角 */ diff --git a/assets/script/game/common/config/BoxSet.ts b/assets/script/game/common/config/BoxSet.ts index d8768ac3..9d74042d 100644 --- a/assets/script/game/common/config/BoxSet.ts +++ b/assets/script/game/common/config/BoxSet.ts @@ -24,14 +24,14 @@ export enum BoxSet { LETF_END = -420, RIGHT_END = 420, HERO_START = -260, - MONSTER_START = 300, + MONSTER_START = 400, END_POINT = 360, //游戏地平线 - GAME_LINE = 120, + GAME_LINE = 100, CSKILL_X = 320, - CSKILL_Y = 200, + CSKILL_Y = 400, //攻击距离 - ATK_RANGE_X = 85, + ATK_RANGE_X = 150, MOVE_RANGE_X = 20, MAX_SKILL_SY = 50, MAX_SKILL_BY = 80, diff --git a/assets/script/game/common/config/SkillSet.ts b/assets/script/game/common/config/SkillSet.ts index 06df5ca7..725bf9bd 100644 --- a/assets/script/game/common/config/SkillSet.ts +++ b/assets/script/game/common/config/SkillSet.ts @@ -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,}, 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,}, - 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,}, - 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,}, + 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: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,}, diff --git a/assets/script/game/map/MapMonsterComp.ts b/assets/script/game/map/MapMonsterComp.ts index bb22b04b..969e9b05 100644 --- a/assets/script/game/map/MapMonsterComp.ts +++ b/assets/script/game/map/MapMonsterComp.ts @@ -9,13 +9,15 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O import { MapViewScene } from "./view/MapViewScene"; 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"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MapMonsterComp') @ecs.register('MapMonster', false) export class MapMonsterComp extends CCComp { - // scene: MapViewScene = null; + scene: MapViewScene = null; max_count: number = 99 ; //最大波次 cur_count: number = 1; //波次 boss_count: number = 10; //boss波次间隔 @@ -33,9 +35,13 @@ export class MapMonsterComp extends CCComp { onLoad(){ // 监听全局事件 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() { + // this.scene = this.getComponent(MapViewScene); + // this.scene.node.active = true // this.scene = this.getComponent(MapViewScene); let num =RandomManager.instance.getRandomByObjectList(MissionNum,1) this.cur_mission = num[0] @@ -43,6 +49,8 @@ export class MapMonsterComp extends CCComp { // console.log("当前关卡方案",this.cur_mission,this.mission_list) this.refresh_timer= new Timer(smc.vm_data.gold.cd*5); this.monster_refresh() + this.load_role() + } protected update(dt: number): void { if(this.setp_timer.update(dt)){ @@ -60,6 +68,24 @@ export class MapMonsterComp extends CCComp { // } // this.shuaxin(dt) } + load_role(){ + let role = ecs.getEntity(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); + let {pos,monster_layer}=this.set_layer(BoxSet.HERO_START) + + let scale = 1 + hero.load(pos,scale,uuid,monster_layer); + } monster_refresh(){ if (this.setp_num <= 0){ return @@ -73,26 +99,28 @@ export class MapMonsterComp extends CCComp { } private addMonster(uuid:number=1101) { let monster = ecs.getEntity(Monster); - let pos:Vec3 = v3(BoxSet.MONSTER_START,BoxSet.GAME_LINE) 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; + let pos:Vec3 = v3(start,BoxSet.GAME_LINE) let x = RandomManager.instance.getRandomInt(0,2, 2); let monster_layer = scene.entityLayer!.node! switch (x) { case 1: - monster_layer = scene.entityLayer1!.node!; - pos.y=pos.y+100; + // monster_layer = scene.entityLayer1!.node!; + pos.y=pos.y+95; break; case 2: - monster_layer= scene.entityLayer2!.node!; - pos.y=pos.y-100; - default: + // monster_layer= scene.entityLayer2!.node!; + pos.y=pos.y-95; break; + } - monster.load(pos,scale,uuid,monster_layer); - + return {pos,monster_layer} } - private on_other_add_monster(event: string, args: any) { this.addMonster(args.uuid) } diff --git a/assets/script/game/map/view/MapViewComp.ts b/assets/script/game/map/view/MapViewComp.ts index d6c02345..d19328fb 100644 --- a/assets/script/game/map/view/MapViewComp.ts +++ b/assets/script/game/map/view/MapViewComp.ts @@ -16,21 +16,15 @@ const { ccclass, property } = _decorator; @ecs.register('MapView', false) export class MapViewComp extends CCComp { scene: MapViewScene = null!; - current_map: any; private game_timer: Timer = new Timer(1); private mapLoaded() { } 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 { //撤销监听 // 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_role() } - load_role(){ - let role = ecs.getEntity(Role); - let pos = v3(BoxSet.HERO_START-50,BoxSet.GAME_LINE) - role.load(pos,108) - smc.Role=role - } + load_data(){ // let heros = oops.res.get("config/game/heros") // console.log("heros",heros) @@ -79,14 +68,7 @@ export class MapViewComp extends CCComp { smc.vm_data.shuaxin.min = 0; } } - /** 添加玩家 */ - private addHero(uuid:number=1001) { - this.scene.node.active = true - let hero = ecs.getEntity(Hero); - let pos = v3(BoxSet.HERO_START,BoxSet.GAME_LINE) - let scale = 1 - hero.load(pos,scale,uuid); - } + } diff --git a/assets/script/game/monster/BoxRangComp.ts b/assets/script/game/monster/BoxRangComp.ts index ca7089fc..1a79e8a6 100644 --- a/assets/script/game/monster/BoxRangComp.ts +++ b/assets/script/game/monster/BoxRangComp.ts @@ -15,12 +15,13 @@ export class BoxRangComp extends CCComp { box_group:number = BoxSet.DEFAULT; box_tag:number = BoxSet.ATK_RANGE; offset_x:number = 0; + atk_range:number = 150; /** 视图层逻辑代码分离演示 */ start() { let collider = this.getComponent(Collider2D); collider.group = this.box_group; 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.MonsterViewComp=this.Hero_node.getComponent(MonsterViewComp); // console.log("range box",this.MonsterViewComp); @@ -42,9 +43,11 @@ export class BoxRangComp extends CCComp { // } } onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { + 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); this.MonsterViewComp.is_atking = false; + this.MonsterViewComp.enemy = 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 self_pos = this.node.getWorldPosition(); // 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.stop_cd = 0.1 + this.MonsterViewComp.stop_cd = 0.1 } } diff --git a/assets/script/game/monster/CSkill.ts b/assets/script/game/monster/CSkill.ts index b13de8b6..fbf06671 100644 --- a/assets/script/game/monster/CSkill.ts +++ b/assets/script/game/monster/CSkill.ts @@ -37,7 +37,12 @@ export class CSkill extends ecs.Entity { 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); // let cskills = ecs.query(ecs.allOf(CSkillComp)) - pos = this.add_buff() + if(SkillSet[uuid].type >= 90){ + pos = this.add_buff() + }else{ + pos = this.add_skill() + } + // console.log("load skill",pos,smc.player_buffs) node.setPosition(pos.x*scale,pos.y,pos.z) // console.log(node.getChildByName("avatar").getChildByName("TNode").getChildByName("bb").getComponent(Sprite)) @@ -52,7 +57,7 @@ export class CSkill extends ecs.Entity { } add_buff(){ 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){ pos.x=smc.player_buffs[index].x pos.y=smc.player_buffs[index].y @@ -63,6 +68,18 @@ export class CSkill extends ecs.Entity { } 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)){ var mv = node.getComponent(CSkillComp) mv.scale = 1; diff --git a/assets/script/game/monster/CSkillComp.ts b/assets/script/game/monster/CSkillComp.ts index 3bd26a2b..e2f72a35 100644 --- a/assets/script/game/monster/CSkillComp.ts +++ b/assets/script/game/monster/CSkillComp.ts @@ -98,7 +98,7 @@ export class CSkillComp extends CCComp { // 94:role 临时buff // 95:role 永久buff let uuid= this.skill_uuid; - let atk:number=smc.Role.RoleView.atk + let atk:number=smc.Role.MonsterView.atk let args:any = { atk:atk*GameSet.ATK_TO_ATK_RATIO, hp:atk*GameSet.ATK_TO_HP_RATIO, diff --git a/assets/script/game/monster/Hero.ts b/assets/script/game/monster/Hero.ts index c30d2300..89e76488 100644 --- a/assets/script/game/monster/Hero.ts +++ b/assets/script/game/monster/Hero.ts @@ -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/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 let ratio=this.set_ratio(uuid); node.setScale(ratio*node.scale.x, ratio*node.scale.y, node.scale.z); @@ -76,8 +72,8 @@ export class Hero extends ecs.Entity { ratio=1.3 break; case 5: - ratio=1.4 - break; + ratio=1.4 + break; default: ratio=1 } diff --git a/assets/script/game/monster/MonsterViewComp.ts b/assets/script/game/monster/MonsterViewComp.ts index 4e4f3b68..b761aaff 100644 --- a/assets/script/game/monster/MonsterViewComp.ts +++ b/assets/script/game/monster/MonsterViewComp.ts @@ -37,7 +37,9 @@ export class MonsterViewComp extends CCComp { BoxRang:Node =null! buff:MonsterBuffComp =null! - + is_role:boolean = false; + enemy_pos:Vec3=null!; + enemy:any=null!; /** 角色动画 */ as: MonsterSpine = null!; hero_uuid:number = 1001; @@ -74,7 +76,7 @@ export class MonsterViewComp extends CCComp { shield_time:number = 0; //护盾持续时间 box_group:number = 2; - + atk_range:number = 150; private timer:Timer = new Timer(0.1); //计时器 is_dead:boolean = false; //是否摧毁 is_stop:boolean = false; @@ -87,11 +89,16 @@ export class MonsterViewComp extends CCComp { } /** 视图层逻辑代码分离演示 */ start () { 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.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); this.buff.group=this.box_group @@ -139,7 +146,6 @@ export class MonsterViewComp extends CCComp { if(self_pos.x < other_pos.x){ this.stop_cd=0.1 } - this.stop_cd=0.1 break; case BoxSet.MONSTER: if(self_pos.x > other_pos.x){ @@ -188,12 +194,23 @@ export class MonsterViewComp extends CCComp { // console.log("monster shoot"); let skill = ecs.getEntity(Skill); let x=32 - let pos = v3(35*this.scale,40) + let pos = v3(35*this.scale,50) let scale = this.scale let speed =smc.skills[skill_uuid].speed; let dis = smc.skills[skill_uuid].dis; 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); } //使用max_skill diff --git a/assets/script/game/skills/SkillCom.ts b/assets/script/game/skills/SkillCom.ts index 8edc7b35..797e9211 100644 --- a/assets/script/game/skills/SkillCom.ts +++ b/assets/script/game/skills/SkillCom.ts @@ -108,7 +108,7 @@ export class SkillCom extends CCComp { } 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 // console.log("skill onBeginContact",selfCollider.group,otherCollider.group) if(this.type==1 ){ @@ -148,7 +148,7 @@ export class SkillCom extends CCComp { // this.move(deltaTime) this.toDestroy() // 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 } }