Spaces:
Running
Running
| export class Agents { | |
| constructor(world) { | |
| this.world = world; | |
| this.agents = []; | |
| } | |
| spawn() { | |
| this.agents.push({ | |
| v: Math.random() * 0.5 - 0.25 | |
| }); | |
| } | |
| update(dt) { | |
| for (const a of this.agents) { | |
| this.world.power += a.v * dt; | |
| } | |
| } | |
| apply(cmd) { | |
| if (cmd.action === "spawn") this.spawn(); | |
| } | |
| } |