更新demo

This commit is contained in:
YHH
2025-10-09 17:43:46 +08:00
parent fdaa94a61d
commit e724e5a1ba
3 changed files with 62 additions and 69 deletions

View File

@@ -447,20 +447,18 @@ class RenderSystem extends EntitySystem {
private ctx: CanvasRenderingContext2D;
constructor(canvas: HTMLCanvasElement) {
super(Matcher.empty().all(Position, Renderable));
super(Matcher.all(Position, Renderable));
this.canvas = canvas;
this.ctx = canvas.getContext('2d')!;
}
protected override process(entities: Entity[]): void {
protected override process(entities: readonly Entity[]): void {
this.ctx.fillStyle = '#000';
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
for (const entity of entities) {
const position = entity.getComponent(Position);
const renderable = entity.getComponent(Renderable);
if (!position || !renderable) continue;
const position = this.requireComponent(entity, Position);
const renderable = this.requireComponent(entity, Renderable);
this.ctx.fillStyle = renderable.color;
this.ctx.beginPath();
@@ -473,15 +471,14 @@ class RenderSystem extends EntitySystem {
@ECSSystem('LifetimeSystem')
class LifetimeSystem extends EntitySystem {
constructor() {
super(Matcher.empty().all(Lifetime));
super(Matcher.all(Lifetime));
}
protected override process(entities: Entity[]): void {
protected override process(entities: readonly Entity[]): void {
const deltaTime = Time.deltaTime;
for (const entity of entities) {
const lifetime = entity.getComponent(Lifetime);
if (!lifetime) continue;
const lifetime = this.requireComponent(entity, Lifetime);
lifetime.currentAge += deltaTime;
if (lifetime.isDead()) {