新增基础实体系统

This commit is contained in:
yhh
2020-06-08 18:26:05 +08:00
parent 7939253622
commit 57efc5b0e6
18 changed files with 551 additions and 28 deletions

View File

@@ -0,0 +1,7 @@
class MainScene extends Scene {
constructor(displayContent: egret.DisplayObject){
super(displayContent);
this.addEntityProcessor(new SpawnerSystem(new Matcher()));
}
}

View File

@@ -0,0 +1,25 @@
class SpawnComponent extends Component {
public cooldown = -1;
public minInterval = 2;
public maxInterval = 60;
public enemyType = EnemyType.worm;
public numSpawned = 0;
public numAlive = 0;
constructor(enemyType: EnemyType) {
super();
this.enemyType = enemyType;
}
public initialize() {
// console.log("initialize");
}
public update() {
// console.log("update");
}
}
enum EnemyType {
worm
}

View File

@@ -0,0 +1,29 @@
class SpawnerSystem extends EntityProcessingSystem {
constructor(matcher: Matcher){
super(matcher);
}
public processEntity(entity: Entity){
let spawner = entity.getComponent<SpawnComponent>();
if (spawner.numAlive <= 0)
spawner.enabled = true;
if (!spawner.enabled)
return;
console.log("cooldown", spawner.cooldown);
if (spawner.cooldown == -1){
spawner.cooldown /= 4;
}
spawner.cooldown -= 0.001;
if (spawner.cooldown <= 0){
// CreateEnemy
spawner.numSpawned ++;
spawner.numAlive ++;
if (spawner.numAlive > 0)
spawner.enabled = false;
}
}
}

View File

@@ -1,14 +0,0 @@
class TestComponent extends Component {
constructor(displayRender: egret.DisplayObject){
super();
this.bind(displayRender);
}
public initialize(){
// console.log("initialize");
}
public update(){
// console.log("update");
}
}