basic logic
This commit is contained in:
+17
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user