From 007b85fe7fcf8b865a425f327ee6e2d4558de342 Mon Sep 17 00:00:00 2001 From: walkpan Date: Tue, 27 Aug 2024 13:23:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0buff=20comp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/game/heros/hero.prefab | 121 ++++++++++-------- assets/script/game/monster/Monster.ts | 7 +- assets/script/game/monster/MonsterBuffComp.ts | 93 ++++++++++++++ .../game/monster/MonsterBuffComp.ts.meta | 1 + assets/script/game/monster/MonsterViewComp.ts | 1 + assets/script/game/skills/SkillCom.ts | 10 +- 6 files changed, 177 insertions(+), 56 deletions(-) create mode 100644 assets/script/game/monster/MonsterBuffComp.ts create mode 100644 assets/script/game/monster/MonsterBuffComp.ts.meta diff --git a/assets/resources/game/heros/hero.prefab b/assets/resources/game/heros/hero.prefab index 6b620d91..8c26f24e 100644 --- a/assets/resources/game/heros/hero.prefab +++ b/assets/resources/game/heros/hero.prefab @@ -59,10 +59,13 @@ }, { "__id__": 85 + }, + { + "__id__": 87 } ], "_prefab": { - "__id__": 87 + "__id__": 89 }, "_lpos": { "__type__": "cc.Vec3", @@ -1673,7 +1676,7 @@ "fileId": "14OhXRCixNOaApgow/hFbp" }, { - "__type__": "sp.Skeleton", + "__type__": "482c2FsvvZJ+5BgN3d7gY+D", "_name": "", "_objFlags": 0, "__editorExtras__": {}, @@ -1684,6 +1687,70 @@ "__prefab": { "__id__": 78 }, + "animator": { + "__id__": 24 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "6cDIo6gXFNnbPNuWVAqhBD" + }, + { + "__type__": "dc1b7IQTVxHfIHFfWu0u4I/", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 80 + }, + "hitFlashMaterial": { + "__uuid__": "a8f34051-ccff-4050-b9d9-234f62977264", + "__expectedType__": "cc.Material" + }, + "BoxRang": { + "__id__": 65 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "88a6VdbQBB7YwXovYCN2Sy" + }, + { + "__type__": "26574P1wEtBHZdyLJvQFWoJ", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 82 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "5fIwQdqmtEi7HN7Oz8K15G" + }, + { + "__type__": "sp.Skeleton", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 84 + }, "_customMaterial": null, "_srcBlendFactor": 2, "_dstBlendFactor": 4, @@ -1714,52 +1781,6 @@ "__type__": "cc.CompPrefabInfo", "fileId": "3dWWGO2rFK4LL+PeQ7ANRn" }, - { - "__type__": "482c2FsvvZJ+5BgN3d7gY+D", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 80 - }, - "animator": { - "__id__": 24 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "6cDIo6gXFNnbPNuWVAqhBD" - }, - { - "__type__": "dc1b7IQTVxHfIHFfWu0u4I/", - "_name": "", - "_objFlags": 0, - "__editorExtras__": {}, - "node": { - "__id__": 1 - }, - "_enabled": true, - "__prefab": { - "__id__": 82 - }, - "hitFlashMaterial": { - "__uuid__": "a8f34051-ccff-4050-b9d9-234f62977264", - "__expectedType__": "cc.Material" - }, - "BoxRang": { - "__id__": 65 - }, - "_id": "" - }, - { - "__type__": "cc.CompPrefabInfo", - "fileId": "88a6VdbQBB7YwXovYCN2Sy" - }, { "__type__": "cc.RigidBody2D", "_name": "", @@ -1770,7 +1791,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 84 + "__id__": 86 }, "enabledContactListener": true, "bullet": true, @@ -1804,7 +1825,7 @@ }, "_enabled": true, "__prefab": { - "__id__": 86 + "__id__": 88 }, "tag": 0, "_group": 2, diff --git a/assets/script/game/monster/Monster.ts b/assets/script/game/monster/Monster.ts index 7aab502e..39408959 100644 --- a/assets/script/game/monster/Monster.ts +++ b/assets/script/game/monster/Monster.ts @@ -17,13 +17,15 @@ import { MonsterViewComp } from "./MonsterViewComp"; import { CardSet } from "../common/config/CardSet"; import { BoxSet } from "../common/config/BoxSet"; import { RandomManager } from "../../../../extensions/oops-plugin-framework/assets/core/common/random/RandomManager"; +import { MonsterBuffComp } from "./MonsterBuffComp"; /** 角色实体 */ @ecs.register(`Monster`) export class Monster extends ecs.Entity { // 数据层 MonsterModel!: MonsterModelComp; // 视图层 - MonsterView!: MonsterViewComp; // 移动 + MonsterView!: MonsterViewComp; + MonsterBuff!: MonsterBuffComp; // 移动 protected init() { this.addComponents( @@ -34,6 +36,7 @@ export class Monster extends ecs.Entity { destroy(): void { this.remove(MonsterViewComp); + this.remove(MonsterBuffComp); super.destroy(); } @@ -81,6 +84,7 @@ export class Monster extends ecs.Entity { } hero_init(uuid:number=1001,node:Node,pos:Vec3=v3(0,0,0)){ var mv = node.getComponent(MonsterViewComp)!; + var buff = node.getComponent(MonsterBuffComp)!; mv.speed =mv.ospeed = smc.heros[uuid].speed; mv.hero_name= smc.heros[uuid].name; mv.box_group= BoxSet.MONSTER; @@ -95,6 +99,7 @@ export class Monster extends ecs.Entity { mv.scale = -1; mv.Tpos = v3(0,0,0); this.add(mv); + this.add(buff) } } \ No newline at end of file diff --git a/assets/script/game/monster/MonsterBuffComp.ts b/assets/script/game/monster/MonsterBuffComp.ts new file mode 100644 index 00000000..ebabc3ef --- /dev/null +++ b/assets/script/game/monster/MonsterBuffComp.ts @@ -0,0 +1,93 @@ +/* + * @Author: dgflash + * @Date: 2021-11-18 17:42:59 + * @LastEditors: dgflash + * @LastEditTime: 2022-08-17 12:36:18 + */ + +import { Vec3, _decorator , v3,Collider2D,Contact2DType,Label,Node,Prefab,instantiate,ProgressBar, Component, Material, Sprite} 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"; +import { Monster } from "./Monster"; +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 { Skill } from "../skills/Skill"; +import { Timer } from "../../../../extensions/oops-plugin-framework/assets/core/common/timer/Timer"; +import { SkillCom } from "../skills/SkillCom"; +import { SkillSet } from "../common/config/SkillSet"; +import { BoxRangComp } from "./BoxRangComp"; +import { Tooltip } from "../skills/Tooltip"; +const { ccclass, property } = _decorator; + +/** 角色显示组件 */ +@ccclass('MonsterBuffComp') // 定义为 Cocos Creator 组件 +@ecs.register('MonsterBuff', false) // 定义为 ECS 组件 +export class MonsterBuffComp extends CCComp { + /** 角色动画 */ + as: MonsterSpine = null!; + num:number=0; + timer:Timer = new Timer(0.5); + + onLoad() { + this.as = this.getComponent(MonsterSpine); + + } /** 视图层逻辑代码分离演示 */ + start () { + console.log("MonsterBuffComp start nmu:"+this.num); + // 注册单个碰撞体的回调函数 + let collider = this.getComponent(Collider2D); + if (collider) { + collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); + collider.on(Contact2DType.END_CONTACT, this.onEndContact, this); + collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this); + collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this); + } + // this.node.getChildByName("level").getChildByName("level").getComponent(Label).string = this.level.toString(); + + + } + onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D) { + if(otherCollider.tag==BoxSet.SKILL_TAG &&selfCollider.tag!=BoxSet.SKILL_TAG){ + if(selfCollider.group != otherCollider.group){ + + } + } + } + onEndContact (selfCollider: Collider2D, otherCollider: Collider2D) { } + onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D) { + + } + onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D) { + if(selfCollider.group == otherCollider.group&&otherCollider.tag == 0&&selfCollider.tag == 0){ + let self_pos=selfCollider.node.getPosition(); + let other_pos=otherCollider.node.getPosition(); + // console.log('monster view group 相同'); + switch (selfCollider.group) { + case BoxSet.HERO: + + break; + case BoxSet.MONSTER: + + break + } + } + } + + + update(dt: number){ + if (this.timer.update(dt)) { + this.num++; + + } + } + + reset() { + + this.node.destroy(); + } + +} \ No newline at end of file diff --git a/assets/script/game/monster/MonsterBuffComp.ts.meta b/assets/script/game/monster/MonsterBuffComp.ts.meta new file mode 100644 index 00000000..c0cdc087 --- /dev/null +++ b/assets/script/game/monster/MonsterBuffComp.ts.meta @@ -0,0 +1 @@ +{"ver":"4.0.23","importer":"typescript","imported":true,"uuid":"265743f5-c04b-411d-9772-2c9bd0156a09","files":[],"subMetas":{},"userData":{}} diff --git a/assets/script/game/monster/MonsterViewComp.ts b/assets/script/game/monster/MonsterViewComp.ts index 693d9226..d36ddc6f 100644 --- a/assets/script/game/monster/MonsterViewComp.ts +++ b/assets/script/game/monster/MonsterViewComp.ts @@ -138,6 +138,7 @@ export class MonsterViewComp extends CCComp { if(self_pos.x > other_pos.x&&Math.abs(self_pos.x-other_pos.x) <= BoxSet.MOVE_RANGE_X && self_pos.y==other_pos.y){ this.stop_cd=0.1 } + break } } } diff --git a/assets/script/game/skills/SkillCom.ts b/assets/script/game/skills/SkillCom.ts index 04b52a9f..99866151 100644 --- a/assets/script/game/skills/SkillCom.ts +++ b/assets/script/game/skills/SkillCom.ts @@ -123,16 +123,16 @@ export class SkillCom extends CCComp { // this.node.setScale(v3(this.scale,this.node.scale.y,this.node.scale.z)) // this.move(deltaTime) this.toDestroy() - // if(this.t_pos){ - // this.t_move(deltaTime) - // }else{ - // this.line_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) { this.is_destroy=true } } t_move(dt: number){ + if(!this.t_pos){ + return + } this.node.setPosition(v3(this.node.position.x+this.x_speed*dt*this.scale,this.node.position.y+this.y_speed*dt)) } line_move(dt: number) {