LordXido commited on
Commit
54f4763
·
verified ·
1 Parent(s): ed4ca56

Update agents.js

Browse files
Files changed (1) hide show
  1. agents.js +13 -7
agents.js CHANGED
@@ -1,16 +1,22 @@
1
- // agents.js — v9.2
2
  export class Agents {
3
- constructor() {
4
- this.list = [];
 
5
  }
6
 
7
- spawn(type = "observer") {
8
- this.list.push({ type, t: 0 });
 
 
9
  }
10
 
11
  update(dt) {
12
- for (const a of this.list) {
13
- a.t += dt;
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
  }