This commit is contained in:
2024-07-30 10:55:31 +08:00
parent 76b400885c
commit d85ed9e6b6
13 changed files with 663 additions and 55 deletions

View File

@@ -31,9 +31,9 @@ export class Main extends Root {
]
smc.heros = [
{profession:'war',speed:50},
{profession:'magic',speed:50},
{profession:'heath',speed:50},
{profession:'war',speed:50},
// {profession:'magic',speed:50},
// {profession:'heath',speed:50},
// {profession:'war',speed:50},
]
console.log("Game start");
}

View File

@@ -65,6 +65,7 @@ export class MoveToSystem extends ecs.ComblockSystem<ecs.Entity> implements ecs.
entityEnter(e: ecs.Entity): void {
e.add(VariableMoveToComponent);
console.log("MoveToSystem entityEnter");
}
entityRemove(e: ecs.Entity): void {

View File

@@ -15,7 +15,8 @@ const { ccclass, property } = _decorator;
@ecs.register('MapView', false)
export class MapViewComp extends CCComp {
scene: MapViewScene = null!;
@property(Prefab)
boss: Prefab = null!;
/** 是否正在转场 */
@@ -23,7 +24,7 @@ export class MapViewComp extends CCComp {
current_map: any;
/** 转场碰撞点对象集合 */
private timer: Timer = new Timer(2);
private timer: Timer = new Timer(3);
onLoad(){
// 监听全局事件
oops.message.on("monster_load", this.onMonsterLoaded, this);
@@ -63,18 +64,12 @@ export class MapViewComp extends CCComp {
}
if (smc.monsters.length>0){
var path = "game/monster/monster";
var prefab: Prefab = oops.res.get(path, Prefab)!;
var node = instantiate(prefab);
var scene = smc.map.MapView.scene;
node.parent = scene.entityLayer!.node!;
node.setPosition(v3(360,-60))
this.node.addChild(node);
// let monster = ecs.getEntity<Monster>(Monster);
// monster.load(v3(360,-60),smc.monsters[0].speed);
// monster.move(v3(0,-60));
// smc.monsters.splice(0,1)
let monster = ecs.getEntity<Monster>(Monster);
monster.load(v3(360,-60),smc.monsters[0].speed);
monster.move(v3(0,-60));
smc.monsters.splice(0,1)
}
}

View File

@@ -22,7 +22,7 @@ export class Monster extends ecs.Entity {
MonsterModel!: MonsterModelComp;
// 视图层
MonsterView!: MonsterViewComp;
RoleMoveTo!: MoveToComp; // 移动
MoveToComp!: MoveToComp; // 移动
protected init() {
this.addComponents<ecs.Comp>(
@@ -46,10 +46,8 @@ export class Monster extends ecs.Entity {
node.setPosition(pos)
var mv = node.getComponent(MonsterViewComp)!;
mv.speed = speed;
mv.ospeed = speed;
mv.Tpos = v3(0,0,0);
// this.add(mv);
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

@@ -28,37 +28,14 @@ export class MonsterViewComp extends CCComp {
timer: number = 0;
/** 视图层逻辑代码分离演示 */
start () {
// 注册单个碰撞体的回调函数
// console.log('MonsterViewComp start');
let collider = this.getComponent(Collider2D);
// console.log('Monster collider',collider);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
// 注册全局碰撞回调函数
if (PhysicsSystem2D.instance) {
// console.log('PhysicsSystem2D.instance');
PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
// console.log('monster Contact,otherCollider',otherCollider);
this.speed = 0;
this.timer = 1;
switch (otherCollider.group) {
case BoxSet.HERO_SKILL:
// console.log('monster coolider hero skill');
break;
default:
break;
}
}
onLoad() {
this.as = this.getComponent(MonsterSpine);
console.log('this.ospeed:',this);
console.log('this.ent:',this);
}
update(dt: number){
@@ -72,7 +49,7 @@ export class MonsterViewComp extends CCComp {
if(this.node.position.x > -360){
this.move(dt);
}
if(this.node.position.x < -360){
if(this.node.position.x < -300){
smc.monsters_in = smc.monsters_in.filter(element => element.eid !== this.ent.eid);
this.node.destroy();
}

View File

@@ -0,0 +1,62 @@
import { _decorator, Component, Node,Collider2D ,Contact2DType,PhysicsSystem2D,IPhysics2DContact} from 'cc';
const { ccclass, property } = _decorator;
@ccclass('bossCom')
export class bossCom extends Component {
@property(Number)
private speed: number = 100;
@property(Number)
private ospeed: number = 100;
@property(Number)
private timer: number = 0;
protected onLoad(): void {
this.speed = this.ospeed = 100;
}
start () {
// 注册单个碰撞体的回调函数
// console.log('MonsterViewComp start');
let collider = this.getComponent(Collider2D);
// console.log('Monster collider',collider);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
// 注册全局碰撞回调函数
if (PhysicsSystem2D.instance) {
// console.log('PhysicsSystem2D.instance');
PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
// console.log('monster Contact,otherCollider',otherCollider);
this.speed = 0;
this.timer = 1;
}
update(dt: number){
if(this.timer > 0){
this.timer -= dt;
if(this.timer <= 0){
this.speed = this.ospeed;
this.timer = 0;
}
}
if(this.node.position.x > -360){
this.move(dt);
}
if(this.node.position.x < -360){
this.node.destroy();
}
}
move(dt: number){
this.node.setPosition(this.node.position.x-dt*this.speed, this.node.position.y, this.node.position.z);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "28f753af-37cc-4e46-b100-445408bc547e",
"files": [],
"subMetas": {},
"userData": {}
}