From cde0be7bccae6b6874d291ad9fb58e65c66d5373 Mon Sep 17 00:00:00 2001 From: "pan@work" Date: Mon, 29 Jul 2024 17:04:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A2=B0=E6=92=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resources/game/heros/heath.prefab | 80 +++++++++++++++++- assets/resources/game/heros/magic.prefab | 82 ++++++++++++++++++- assets/resources/game/heros/war.prefab | 18 ++-- assets/resources/game/monster/monster.prefab | 18 ++-- assets/script/Main.ts | 20 ++--- .../script/game/common/SingletonModuleComp.ts | 4 + assets/script/game/heros/Hero.ts | 8 +- assets/script/game/heros/HeroSpineAnimator.ts | 2 +- assets/script/game/heros/HeroViewComp.ts | 32 +++++++- assets/script/game/map/view/MapViewComp.ts | 2 +- assets/script/game/monster/Monster.ts | 3 +- .../game/monster/MonsterSpineAnimator.ts | 2 +- assets/script/game/monster/MonsterViewComp.ts | 25 +++++- settings/v2/packages/project.json | 2 +- 14 files changed, 245 insertions(+), 53 deletions(-) diff --git a/assets/resources/game/heros/heath.prefab b/assets/resources/game/heros/heath.prefab index 92474de8..82a031e6 100644 --- a/assets/resources/game/heros/heath.prefab +++ b/assets/resources/game/heros/heath.prefab @@ -41,10 +41,16 @@ }, { "__id__": 36 + }, + { + "__id__": 38 + }, + { + "__id__": 40 } ], "_prefab": { - "__id__": 38 + "__id__": 42 }, "_lpos": { "__type__": "cc.Vec3", @@ -250,8 +256,8 @@ }, "_lscale": { "__type__": "cc.Vec3", - "x": 0.25, - "y": 0.25, + "x": 0.2, + "y": 0.2, "z": 1 }, "_mobility": 0, @@ -790,6 +796,74 @@ "__type__": "cc.CompPrefabInfo", "fileId": "37VIdk5BVNxqSq7DlGbRu2" }, + { + "__type__": "cc.RigidBody2D", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 39 + }, + "enabledContactListener": true, + "bullet": true, + "awakeOnLoad": true, + "_group": 4, + "_type": 2, + "_allowSleep": false, + "_gravityScale": 0, + "_linearDamping": 0, + "_angularDamping": 0, + "_linearVelocity": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_angularVelocity": 0, + "_fixedRotation": false, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "capWEt+gNO1olaQ3b/bJvS" + }, + { + "__type__": "cc.BoxCollider2D", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 41 + }, + "tag": 0, + "_group": 4, + "_density": 1, + "_sensor": true, + "_friction": 0.2, + "_restitution": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": -1.5, + "y": -2.5 + }, + "_size": { + "__type__": "cc.Size", + "width": 49, + "height": 55 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "79jbcosJ9D6oZt2TJpZIO2" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/resources/game/heros/magic.prefab b/assets/resources/game/heros/magic.prefab index 99fb8b37..daea68f2 100644 --- a/assets/resources/game/heros/magic.prefab +++ b/assets/resources/game/heros/magic.prefab @@ -41,10 +41,16 @@ }, { "__id__": 36 + }, + { + "__id__": 38 + }, + { + "__id__": 40 } ], "_prefab": { - "__id__": 38 + "__id__": 42 }, "_lpos": { "__type__": "cc.Vec3", @@ -250,8 +256,8 @@ }, "_lscale": { "__type__": "cc.Vec3", - "x": 0.25, - "y": 0.25, + "x": 0.2, + "y": 0.2, "z": 1 }, "_mobility": 0, @@ -689,7 +695,7 @@ "node": { "__id__": 1 }, - "_enabled": true, + "_enabled": false, "__prefab": { "__id__": 31 }, @@ -790,6 +796,74 @@ "__type__": "cc.CompPrefabInfo", "fileId": "37VIdk5BVNxqSq7DlGbRu2" }, + { + "__type__": "cc.RigidBody2D", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 39 + }, + "enabledContactListener": true, + "bullet": true, + "awakeOnLoad": true, + "_group": 4, + "_type": 2, + "_allowSleep": false, + "_gravityScale": 0, + "_linearDamping": 0, + "_angularDamping": 0, + "_linearVelocity": { + "__type__": "cc.Vec2", + "x": 0, + "y": 0 + }, + "_angularVelocity": 0, + "_fixedRotation": false, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "13SqotxrBONYCFGINKqG8F" + }, + { + "__type__": "cc.BoxCollider2D", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 1 + }, + "_enabled": true, + "__prefab": { + "__id__": 41 + }, + "tag": 0, + "_group": 4, + "_density": 1, + "_sensor": true, + "_friction": 0.2, + "_restitution": 0, + "_offset": { + "__type__": "cc.Vec2", + "x": -2.5, + "y": -2 + }, + "_size": { + "__type__": "cc.Size", + "width": 57, + "height": 52 + }, + "_id": "" + }, + { + "__type__": "cc.CompPrefabInfo", + "fileId": "9dz9ACoHpDcJCuJCyRkKh+" + }, { "__type__": "cc.PrefabInfo", "root": { diff --git a/assets/resources/game/heros/war.prefab b/assets/resources/game/heros/war.prefab index 3de7aba9..593a1341 100644 --- a/assets/resources/game/heros/war.prefab +++ b/assets/resources/game/heros/war.prefab @@ -256,8 +256,8 @@ }, "_lscale": { "__type__": "cc.Vec3", - "x": 0.25, - "y": 0.25, + "x": 0.2, + "y": 0.2, "z": 1 }, "_mobility": 0, @@ -695,7 +695,7 @@ "node": { "__id__": 1 }, - "_enabled": true, + "_enabled": false, "__prefab": { "__id__": 31 }, @@ -816,13 +816,13 @@ "_restitution": 0, "_offset": { "__type__": "cc.Vec2", - "x": -2.7, - "y": -2.5 + "x": -2.4, + "y": -0.9 }, "_size": { "__type__": "cc.Size", - "width": 87.4, - "height": 77.5 + "width": 56.4, + "height": 53 }, "_id": "" }, @@ -843,11 +843,11 @@ "__id__": 41 }, "enabledContactListener": true, - "bullet": true, + "bullet": false, "awakeOnLoad": true, "_group": 4, "_type": 2, - "_allowSleep": true, + "_allowSleep": false, "_gravityScale": 0, "_linearDamping": 0, "_angularDamping": 0, diff --git a/assets/resources/game/monster/monster.prefab b/assets/resources/game/monster/monster.prefab index 2c7e0c14..30df22ce 100644 --- a/assets/resources/game/monster/monster.prefab +++ b/assets/resources/game/monster/monster.prefab @@ -256,8 +256,8 @@ }, "_lscale": { "__type__": "cc.Vec3", - "x": -0.25, - "y": 0.25, + "x": -0.2, + "y": 0.2, "z": 1 }, "_mobility": 0, @@ -695,7 +695,7 @@ "node": { "__id__": 1 }, - "_enabled": true, + "_enabled": false, "__prefab": { "__id__": 31 }, @@ -816,13 +816,13 @@ "_restitution": 0, "_offset": { "__type__": "cc.Vec2", - "x": 3.6, - "y": -2.5 + "x": 1.6, + "y": -3 }, "_size": { "__type__": "cc.Size", - "width": 75.1, - "height": 70 + "width": 59.1, + "height": 55 }, "_id": "" }, @@ -843,11 +843,11 @@ "__id__": 41 }, "enabledContactListener": true, - "bullet": true, + "bullet": false, "awakeOnLoad": true, "_group": 2, "_type": 2, - "_allowSleep": true, + "_allowSleep": false, "_gravityScale": 0, "_linearDamping": 0, "_angularDamping": 0, diff --git a/assets/script/Main.ts b/assets/script/Main.ts index 8f813700..d9e8ff45 100644 --- a/assets/script/Main.ts +++ b/assets/script/Main.ts @@ -4,7 +4,7 @@ * @LastEditors: dgflash * @LastEditTime: 2022-08-17 13:43:02 */ -import { profiler, _decorator } from 'cc'; +import { profiler, _decorator ,PhysicsSystem2D} from 'cc'; import { DEBUG } from 'cc/env'; import { oops } from '../../extensions/oops-plugin-framework/assets/core/Oops'; import { Root } from '../../extensions/oops-plugin-framework/assets/core/Root'; @@ -20,20 +20,20 @@ export class Main extends Root { start() { if (DEBUG) profiler.showStats(); } - + protected async run() { smc.initialize = ecs.getEntity(Initialize); smc.monsters = [ - {profession:'m1',speed:60}, - {profession:'m2',speed:600}, - {profession:'m3',speed:200}, - {profession:'m4',speed:100}, + {profession:'m1',speed:50}, + {profession:'m2',speed:50}, + {profession:'m3',speed:50}, + {profession:'m4',speed:50}, ] smc.heros = [ - {profession:'war',speed:60}, - {profession:'magic',speed:60}, - {profession:'heath',speed:60}, - {profession:'war',speed:60}, + {profession:'war',speed:50}, + {profession:'magic',speed:50}, + {profession:'heath',speed:50}, + {profession:'war',speed:50}, ] console.log("Game start"); } diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 94e60273..c5c082fa 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -25,6 +25,10 @@ export class SingletonModuleComp extends ecs.Comp { monsters = [] /**heros 数据 */ heros = []; + monsters_in=[] + heros_in = [] + monsters_dead = [] + heros_dead = [] reset() { } } diff --git a/assets/script/game/heros/Hero.ts b/assets/script/game/heros/Hero.ts index 10503af4..28df35a0 100644 --- a/assets/script/game/heros/Hero.ts +++ b/assets/script/game/heros/Hero.ts @@ -46,13 +46,9 @@ export class Hero extends ecs.Entity { node.setPosition(pos) node.setScale(1, 1, 1); var mv = node.getComponent(HeroViewComp)!; + mv.speed=smc.heros[0].speed; this.add(mv); - let speed = smc.heros[0].speed; - tween(node).to(speed/60, { position: new Vec3(0, -60, 0) }, { - onComplete: () => { - // this.as.walk(); - } - }).start(); + //移除全局列表 smc.heros.splice(0,1) // console.log(ecs.query(ecs.allOf(HeroViewComp))) diff --git a/assets/script/game/heros/HeroSpineAnimator.ts b/assets/script/game/heros/HeroSpineAnimator.ts index f3776b29..48766bb1 100644 --- a/assets/script/game/heros/HeroSpineAnimator.ts +++ b/assets/script/game/heros/HeroSpineAnimator.ts @@ -15,7 +15,7 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator; @disallowMultiple @requireComponent(sp.Skeleton) export default class HeroSpineAnimator extends Component { - private animName: string = "idle"; + private animName: string = "move"; private loop: boolean = true; private spine!: sp.Skeleton; start() { diff --git a/assets/script/game/heros/HeroViewComp.ts b/assets/script/game/heros/HeroViewComp.ts index c9f94e24..bb003a25 100644 --- a/assets/script/game/heros/HeroViewComp.ts +++ b/assets/script/game/heros/HeroViewComp.ts @@ -5,11 +5,12 @@ * @LastEditTime: 2022-08-17 12:36:18 */ -import { Vec3, _decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact} from "cc"; +import { Vec3, v3,_decorator ,Collider2D,Contact2DType,PhysicsSystem2D,IPhysics2DContact,EPhysics2DDrawFlags} 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 { HeroSpine } from "./HeroSpine"; import {BoxSet} from "../common/config/BoxSet" +import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; /** 角色显示组件 */ @@ -19,14 +20,15 @@ export class HeroViewComp extends CCComp { /** 角色动画 */ as: HeroSpine = null!; /** 角色控制器 */ - + speed: number = 100; + Tpos: Vec3 = v3(0,-60,0); start () { // 注册单个碰撞体的回调函数 // console.log('MonsterViewComp start'); let collider = this.getComponent(Collider2D); - // console.log('hero collider',collider); if (collider) { + // console.log('hero collider',collider); collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); } @@ -58,7 +60,29 @@ export class HeroViewComp extends CCComp { } - + update(dt: number){ + if(this.node.position.x < 360){ + this.move(dt); + + } + if(this.node.position.x > 360){ + smc.heros_in = smc.heros_in.filter(element => element.eid !== this.ent.eid); + this.node.destroy(); + } + this.update_pos(); + + } + move(dt: number){ + this.node.setPosition(this.node.position.x+dt*this.speed, this.node.position.y, this.node.position.z); + } + update_pos(){ + smc.heros_in.forEach(element => { + if(element.eid == this.ent.eid){ + element.pos_x = this.node.position.x; + } + }); + // console.log('smc.heros_in',smc.heros_in); + } reset() { this.node.destroy(); diff --git a/assets/script/game/map/view/MapViewComp.ts b/assets/script/game/map/view/MapViewComp.ts index 6b4592fd..4d8a5379 100644 --- a/assets/script/game/map/view/MapViewComp.ts +++ b/assets/script/game/map/view/MapViewComp.ts @@ -43,7 +43,7 @@ export class MapViewComp extends CCComp { /** 转场 */ protected update(dt: number): void { if (this.timer.update(dt)) { - console.log('每2秒触发一次'); + // console.log('每2秒触发一次'); this.addHero(); } } diff --git a/assets/script/game/monster/Monster.ts b/assets/script/game/monster/Monster.ts index 7396d0fd..6178d876 100644 --- a/assets/script/game/monster/Monster.ts +++ b/assets/script/game/monster/Monster.ts @@ -47,11 +47,10 @@ export class Monster extends ecs.Entity { var mv = node.getComponent(MonsterViewComp)!; mv.speed = speed; - // console.log("speed:"+mv.speed) mv.Tpos = v3(0,0,0); this.add(mv); + smc.monsters_in.push({name:mv.ent.name,eid:mv.ent.eid,pos_x:0}), // node.setScale(-1, 1, 1); - oops.message.dispatchEvent("monster_load",this) } diff --git a/assets/script/game/monster/MonsterSpineAnimator.ts b/assets/script/game/monster/MonsterSpineAnimator.ts index ea449be8..8139295a 100644 --- a/assets/script/game/monster/MonsterSpineAnimator.ts +++ b/assets/script/game/monster/MonsterSpineAnimator.ts @@ -15,7 +15,7 @@ const { ccclass, property, requireComponent, disallowMultiple } = _decorator; @disallowMultiple @requireComponent(sp.Skeleton) export default class MonsterSpineAnimator extends Component { - private animName: string = "idle"; + private animName: string = "move"; private loop: boolean = true; private spine!: sp.Skeleton; start() { diff --git a/assets/script/game/monster/MonsterViewComp.ts b/assets/script/game/monster/MonsterViewComp.ts index 4216bb28..05774720 100644 --- a/assets/script/game/monster/MonsterViewComp.ts +++ b/assets/script/game/monster/MonsterViewComp.ts @@ -12,6 +12,7 @@ import { MonsterSpine } from "./MonsterSpine"; import { Monster } from "./Monster"; import { MonsterModelComp } from "./MonsterModelComp"; import { BoxSet } from "../common/config/BoxSet"; +import { smc } from "../common/SingletonModuleComp"; const { ccclass, property } = _decorator; @@ -41,7 +42,7 @@ export class MonsterViewComp extends CCComp { } onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) { // 只在两个碰撞体开始接触时被调用一次 - // console.log('monster Contact,selfCollider',selfCollider); + // console.log('monster Contact,otherCollider',otherCollider); switch (otherCollider.group) { case BoxSet.HERO: @@ -57,12 +58,32 @@ export class MonsterViewComp extends CCComp { onLoad() { this.as = this.getComponent(MonsterSpine); + + } update(dt: number){ + if(this.node.position.x > -360){ + this.move(dt); + } + if(this.node.position.x < -360){ + smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid); + this.node.destroy(); + } + this.update_pos(); + + } + move(dt: number){ this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z); } - + update_pos(){ + smc.monsters_in.forEach(element => { + if(element.eid == this.ent.eid){ + element.pos_x = this.node.position.x; + } + }); + // console.log('smc.monsters_in',smc.monsters_in); + } reset() { this.node.destroy(); } diff --git a/settings/v2/packages/project.json b/settings/v2/packages/project.json index a91a218b..3a58fe59 100644 --- a/settings/v2/packages/project.json +++ b/settings/v2/packages/project.json @@ -43,7 +43,7 @@ } ], "collisionMatrix": { - "0": 0, + "0": 1, "1": 20, "2": 10, "3": 4,