Game for OLC Code Jam 2022
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cloud.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. const VELOCITY = [0.002, 0.0001];
  2. const SHOOT_PROBABILITY = 0.0007;
  3. class Cloud extends Entity {
  4. static shootProbability = SHOOT_PROBABILITY;
  5. constructor(...args) {
  6. super(...args);
  7. this.particles = new Set();
  8. for (let i = 0; i < 3; i++) {
  9. const cloudParticle = {
  10. w: randRange(0.3, 0.8),
  11. h: randRange(0.3, 0.8),
  12. x: randRange(0.2, 0.8),
  13. y: randRange(0.2, 0.8),
  14. r: randRange(-Math.PI, Math.PI),
  15. n: randRange(-10000, 10000),
  16. }
  17. this.particles.add(cloudParticle);
  18. }
  19. this.sound = new Audio();
  20. this.sound.src = 'snd/click.ogg';
  21. }
  22. draw() {
  23. const { x, y, w, h } = this.getScreenCoords();
  24. for (let particle of this.particles) {
  25. const px = x + particle.x * w;
  26. const py = y + particle.y * h;
  27. const pw = particle.w * w;
  28. const ph = particle.h * w;
  29. const now = Date.now() / 1000;
  30. const a = mapNumber(
  31. noise.simplex3(particle.n, now / 2, 0),
  32. -1, 1,
  33. 0, 0.7,
  34. );
  35. const r = mapNumber(
  36. noise.simplex3(particle.n, now / 10, 1),
  37. -1, 1,
  38. 0, Math.PI,
  39. );
  40. const z = mapNumber(
  41. noise.simplex3(particle.n, now / 2, 2),
  42. -1, 1,
  43. 0.5, 1.5,
  44. );
  45. CTX.fillStyle = `rgba(255, 255, 255, ${a})`;
  46. CTX.beginPath();
  47. CTX.ellipse(px, py, pw / 2 * z, ph / 2 * z, particle.r + r, 0, 2 * Math.PI);
  48. CTX.fill();
  49. }
  50. }
  51. static reset() {
  52. this.shootProbability = SHOOT_PROBABILITY;
  53. }
  54. update(direction) {
  55. if (this.alive) {
  56. this.x += VELOCITY[0] * direction;
  57. this.y += VELOCITY[1];
  58. if (Math.random() < Cloud.shootProbability) {
  59. const raindrop = new RainDrop(this.x, this.y + 0.009);
  60. bullets.add(raindrop);
  61. if (soundEnabled) {
  62. this.sound.currentTime = 0;
  63. this.sound.play().catch(() => { });
  64. }
  65. }
  66. }
  67. }
  68. destroy() {
  69. super.destroy();
  70. Cloud.shootProbability += 0.0001;
  71. }
  72. }