class Bullet extends Entity { constructor(x, y) { super(x, y, 0.001, 0.02); this.color = 'yellow'; } update() { if (this.alive) { this.y -= 0.01; if (this.y < -0.1) { this.destroy(); } for (let cloud of clouds) { if (this.isOverlapped(cloud)) { cloud.destroy(); this.destroy(); } } } } } class RainDrop extends Bullet { constructor(x, y) { super(x, y); this.color = 'cyan'; } update() { if (this.alive) { this.y += 0.01; if (this.y > 1.1) { this.destroy(); } else if (this.isOverlapped(shootingPad)) { shootingPad.lifeOver(); this.destroy(); } } } } const currentAngle = () => { const x = Date.now() / 10000; const n = noise.simplex2(x, 0); return mapNumber(n, -1, 1, 45, 135); }; class BackgroundRaindrop extends Bullet { constructor(x, y, speed) { super(x, y); this.speed = speed; } draw() { CTX.save(); const { x, y, w, h } = this.getScreenCoords(); CTX.translate(x, y); CTX.rotate(toRadians(currentAngle() - 90)); CTX.fillStyle = `rgba(200, 255, 255, 0.2)`; CTX.fillRect(0, 0, w, h); CTX.restore(); } update() { const cs = Math.cos(toRadians(currentAngle())); const sn = Math.sin(toRadians(currentAngle())); this.x += this.speed * cs; this.y += this.speed * sn; if (this.y > 1.1) { this.y = randRange(-1, -0.1); this.x = randRange(-0.5, 1.5); } } }