This commit is contained in:
2024-07-29 17:04:03 +08:00
parent 5fa8794c09
commit cde0be7bcc
14 changed files with 245 additions and 53 deletions

View File

@@ -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": {

View File

@@ -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": {

View File

@@ -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,

View File

@@ -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,

View File

@@ -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>(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");
}

View File

@@ -25,6 +25,10 @@ export class SingletonModuleComp extends ecs.Comp {
monsters = []
/**heros 数据 */
heros = [];
monsters_in=[]
heros_in = []
monsters_dead = []
heros_dead = []
reset() { }
}

View File

@@ -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)))

View File

@@ -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() {

View File

@@ -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();

View File

@@ -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();
}
}

View File

@@ -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)
}

View File

@@ -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() {

View File

@@ -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();
}

View File

@@ -43,7 +43,7 @@
}
],
"collisionMatrix": {
"0": 0,
"0": 1,
"1": 20,
"2": 10,
"3": 4,