basic logic

This commit is contained in:
azykov@mail.ru
2026-08-31 22:01:35 +03:00
parent 2860bb837a
commit d96a6e2e92
6 changed files with 66 additions and 88 deletions
+17 -1
View File
@@ -26,8 +26,24 @@ export class Game {
public tick(deltaTime: number) {
this.time += deltaTime;
const behavioursById = new Map(this.nodes.map((node) => [node.behaviour.id, node.behaviour]));
for (const node of this.nodes)
node.behaviour.tick(deltaTime);
node.behaviour.produce(deltaTime);
for (const node of this.nodes)
node.behaviour.pull(deltaTime, (id) => behavioursById.get(id));
}
public reset() {
this.time = 0;
for (const node of this.nodes)
node.behaviour.reset();
}
/** Shallow copy with a new identity, so React sees a change after in-place mutations like `tick`. */
public clone(): Game {
return Object.assign(Object.create(Game.prototype), this);
}
}