新增基础实体系统
This commit is contained in:
7
demo/src/game/MainScene.ts
Normal file
7
demo/src/game/MainScene.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
class MainScene extends Scene {
|
||||
constructor(displayContent: egret.DisplayObject){
|
||||
super(displayContent);
|
||||
|
||||
this.addEntityProcessor(new SpawnerSystem(new Matcher()));
|
||||
}
|
||||
}
|
||||
25
demo/src/game/SpawnerComponent.ts
Normal file
25
demo/src/game/SpawnerComponent.ts
Normal 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
|
||||
}
|
||||
29
demo/src/game/SpawnerSystem.ts
Normal file
29
demo/src/game/SpawnerSystem.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user