diff options
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/.borderParticles.js.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | src/entities/borderParticles.js | 74 |
2 files changed, 29 insertions, 45 deletions
diff --git a/src/entities/.borderParticles.js.swp b/src/entities/.borderParticles.js.swp Binary files differnew file mode 100644 index 0000000..c55b959 --- /dev/null +++ b/src/entities/.borderParticles.js.swp 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; +} |