dd
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
62
assets/script/game/monster/bossComp.ts
Normal file
62
assets/script/game/monster/bossComp.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
assets/script/game/monster/bossComp.ts.meta
Normal file
9
assets/script/game/monster/bossComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "28f753af-37cc-4e46-b100-445408bc547e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user