summaryrefslogtreecommitdiff
path: root/src/entities
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-11 16:55:16 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-11 16:55:16 -0600
commit491f532750da38f17e2891042bcb03f095ec4d92 (patch)
tree8319ee79d4ea65afd8f6eaf75c5a94d9a72ea1a1 /src/entities
parentec7b01918cc2aec22d4c408bdd460bf767377fbc (diff)
downloadbbiy-491f532750da38f17e2891042bcb03f095ec4d92.tar.gz
bbiy-491f532750da38f17e2891042bcb03f095ec4d92.zip
Move particle stuff to a system to simplify spawning particles
Diffstat (limited to 'src/entities')
-rw-r--r--src/entities/.borderParticles.js.swpbin0 -> 12288 bytes
-rw-r--r--src/entities/borderParticles.js74
2 files changed, 29 insertions, 45 deletions
diff --git a/src/entities/.borderParticles.js.swp b/src/entities/.borderParticles.js.swp
new file mode 100644
index 0000000..c55b959
--- /dev/null
+++ b/src/entities/.borderParticles.js.swp
Binary files differ
diff --git a/src/entities/borderParticles.js b/src/entities/borderParticles.js
index 34512bc..260071d 100644
--- a/src/entities/borderParticles.js
+++ b/src/entities/borderParticles.js
@@ -1,56 +1,40 @@
-game.createBorderParticles = ({colors, maxAmount, minAmount, minLife, maxLife, minRadius, maxRadius, maxSpeed}) => {
- const particles = game.Entity();
- let particleSpecs = Array(randomInRange(minAmount, maxAmount)).fill(0).map(() => {
- const particle = {
- x: Math.random(),
- y: Math.random(),
- dx: Math.random() * maxSpeed - maxSpeed / 2,
- dy: Math.random() * maxSpeed - maxSpeed / 2,
- radius: randomInRange(minRadius, maxRadius),
- color: colors[randomInRange(0, colors.length-1)],
- lifetime: randomInRange(minLife, maxLife),
- elapsed: 0,
- };
+game.createBorderParticles = () => {
+ const particleSpawner = game.Entity();
+ const spawnFunction = (particleSpec) => {
switch (Math.floor(Math.random() * 4)) {
case 0:
- particle.y = 0;
- particle.dy = -Math.abs(particle.dy);
+ particleSpec.y = 0;
+ particleSpec.dy = -Math.abs(particleSpec.dy);
break;
case 1:
- particle.x = 1;
- particle.dx = Math.abs(particle.dx);
+ particleSpec.x = 1;
+ particleSpec.dx = Math.abs(particleSpec.dx);
break;
case 2:
- particle.y = 1;
- particle.dy = Math.abs(particle.dy);
+ particleSpec.y = 1;
+ particleSpec.dy = Math.abs(particleSpec.dy);
break;
case 3:
- particle.x = 0;
- particle.dx = -Math.abs(particle.dx);
+ particleSpec.x = 0;
+ particleSpec.dx = -Math.abs(particleSpec.dx);
break;
}
- return particle;
- });
- game.sprites.borderParticle = game.graphics.Sprite({
- drawFunction: (elapsedTime, {x, y, width, height}, context) => {
- particleSpecs.map((spec) => spec.elapsed += elapsedTime);
- particleSpecs = particleSpecs.filter((spec) => spec.lifetime > spec.elapsed);
- if (particleSpecs.length === 0) {
- particles.removeComponent("alive");
- }
- particleSpecs.map((spec) => {
- const position = {x: (spec.x * width) + x + spec.dx * spec.elapsed, y: (spec.y * height) + y + spec.dy * spec.elapsed};
- const fill = context.fillStyle;
- context.fillStyle = spec.color;
- context.beginPath();
- context.arc(position.x, position.y, spec.radius, 0, 2 * Math.PI);
- context.fill();
- context.fillStyle = fill;
- });
+ return particleSpec;
+ };
+ particleSpawner.addComponent(game.components.Particles({
+ spec: {
+ spawnFunction,
+ colors: ["#16f7c9", "#0d6e5a", "#2fa18a", "#48cfb4", "#58877d", "#178054", "#2cdb92"],
+ maxSpeed: 0.20,
+ minRadius: 1,
+ maxRadius: 3,
+ minLife: 100,
+ maxLife: 300,
+ minAmount: 20,
+ maxAmount: 50,
}
- })
- particles.addComponent(game.components.LoadPriority({priority: 1}));
- particles.addComponent(game.components.Alive());
- particles.addComponent(game.components.Sprite({spriteName: "borderParticle"}))
- return particles;
-} \ No newline at end of file
+ }));
+ particleSpawner.addComponent(game.components.LoadPriority({priority: 1}));
+ particleSpawner.addComponent(game.components.Alive());
+ return particleSpawner;
+}