Spaces:
Running
Running
Update agents.js
Browse files
agents.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
| 1 |
-
// agents.js — v9.2
|
| 2 |
export class Agents {
|
| 3 |
-
constructor() {
|
| 4 |
-
this.
|
|
|
|
| 5 |
}
|
| 6 |
|
| 7 |
-
spawn(
|
| 8 |
-
this.
|
|
|
|
|
|
|
| 9 |
}
|
| 10 |
|
| 11 |
update(dt) {
|
| 12 |
-
for (const a of this.
|
| 13 |
-
|
| 14 |
}
|
| 15 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
|
|
|
|
|
|
| 1 |
export class Agents {
|
| 2 |
+
constructor(world) {
|
| 3 |
+
this.world = world;
|
| 4 |
+
this.agents = [];
|
| 5 |
}
|
| 6 |
|
| 7 |
+
spawn() {
|
| 8 |
+
this.agents.push({
|
| 9 |
+
v: Math.random() * 0.5 - 0.25
|
| 10 |
+
});
|
| 11 |
}
|
| 12 |
|
| 13 |
update(dt) {
|
| 14 |
+
for (const a of this.agents) {
|
| 15 |
+
this.world.power += a.v * dt;
|
| 16 |
}
|
| 17 |
}
|
| 18 |
+
|
| 19 |
+
apply(cmd) {
|
| 20 |
+
if (cmd.action === "spawn") this.spawn();
|
| 21 |
+
}
|
| 22 |
}
|