Game for OLC Code Jam 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloud.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.element.className = 'cloud';
  8. for (let i = 0; i < 10; i++) {
  9. const cloudParticle = document.createElement('div');
  10. cloudParticle.className = 'cloud-particle';
  11. cloudParticle.style.width = `${randRange(50, 80)}%`;
  12. cloudParticle.style.height = `${randRange(60, 100)}%`;
  13. cloudParticle.style.left = `${randRange(2, 98)}%`;
  14. cloudParticle.style.top = `${randRange(2, 98)}%`;
  15. cloudParticle.style.animationDelay = `${randRange(-10, 0)}s`;
  16. cloudParticle.style.animationDuration = `${randRange(0.5, 3)}s`;
  17. this.element.appendChild(cloudParticle);
  18. }
  19. }
  20. static reset() {
  21. this.shootProbability = SHOOT_PROBABILITY;
  22. }
  23. update(direction) {
  24. if (this.alive) {
  25. this.x += VELOCITY[0] * direction;
  26. this.y += VELOCITY[1];
  27. if (Math.random() < Cloud.shootProbability) {
  28. const raindrop = new RainDrop(this.x, this.y + 0.009);
  29. bullets.add(raindrop);
  30. }
  31. }
  32. }
  33. destroy() {
  34. super.destroy();
  35. Cloud.shootProbability += 0.0001;
  36. }
  37. }