Game for OLC Code Jam 2022
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cloud.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  20. draw() {
  21. const { x, y, w, h } = this.getScreenCoords();
  22. for (let particle of this.particles) {
  23. const px = x + particle.x * w;
  24. const py = y + particle.y * h;
  25. const pw = particle.w * w;
  26. const ph = particle.h * w;
  27. const now = Date.now() / 1000;
  28. const a = mapNumber(
  29. noise.simplex3(particle.n, now / 2, 0),
  30. -1, 1,
  31. 0, 0.7,
  32. );
  33. const r = mapNumber(
  34. noise.simplex3(particle.n, now / 10, 1),
  35. -1, 1,
  36. 0, Math.PI,
  37. );
  38. const z = mapNumber(
  39. noise.simplex3(particle.n, now / 2, 2),
  40. -1, 1,
  41. 0.5, 1.5,
  42. );
  43. CTX.fillStyle = `rgba(255, 255, 255, ${a})`;
  44. CTX.beginPath();
  45. CTX.ellipse(px, py, pw / 2 * z, ph / 2 * z, particle.r + r, 0, 2 * Math.PI);
  46. CTX.fill();
  47. }
  48. }
  49. static reset() {
  50. this.shootProbability = SHOOT_PROBABILITY;
  51. }
  52. update(direction) {
  53. if (this.alive) {
  54. this.x += VELOCITY[0] * direction;
  55. this.y += VELOCITY[1];
  56. if (Math.random() < Cloud.shootProbability) {
  57. const raindrop = new RainDrop(this.x, this.y + 0.009);
  58. bullets.add(raindrop);
  59. }
  60. }
  61. }
  62. destroy() {
  63. super.destroy();
  64. Cloud.shootProbability += 0.0001;
  65. }
  66. }