summaryrefslogtreecommitdiff
path: root/src/entities/borderParticles.js
blob: e1a7e9850c7864021e1b15ab4fb95b56c3874ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
game.createBorderParticles = (spawnerSpec) => {
  const particleSpawner = game.Entity();
  const spawnFunction = (particleSpec) => {
    switch (Math.floor(Math.random() * 4)) {
      case 0:
        particleSpec.y = 0;
        particleSpec.dy = -Math.abs(particleSpec.dy);
        break;
      case 1:
        particleSpec.x = 1;
        particleSpec.dx = Math.abs(particleSpec.dx);
        break;
      case 2:
        particleSpec.y = 1;
        particleSpec.dy = Math.abs(particleSpec.dy);
        break;
      case 3:
        particleSpec.x = 0;
        particleSpec.dx = -Math.abs(particleSpec.dx);
        break;
    }
    return particleSpec;
  };
  particleSpawner.addComponent(game.components.Particles({
    spec: {
      spawnFunction,
      colors: ["#666666", "#777777", "#888888", "#999999"],
      maxSpeed: 0.20,
      minRadius: 1,
      maxRadius: 3,
      minLife: 100,
      maxLife: 300,
      minAmount: 20,
      maxAmount: 50,
      ...spawnerSpec,
    }
  }));
  particleSpawner.addComponent(game.components.LoadPriority({priority: 1}));
  particleSpawner.addComponent(game.components.Alive());
  return particleSpawner;
}