const keys = {}; document.addEventListener('keydown', (e) => { keys[e.key] = true; }); document.addEventListener('keyup', (e) => { keys[e.key] = false; }); const MAX_LIVES = 3; class ShootingPad extends Entity { constructor() { super(0.5, 0.95, 0.04, 0.03); this.element.className = 'shooting-pad'; this.lastShootTime = Date.now(); this.invulnerable = false; this.lives = MAX_LIVES; this.initLives(); this.element.addEventListener('animationend', () => { this.element.style.animationName = null; this.invulnerable = false; }); } update() { if (keys['ArrowLeft']) { this.x -= VELOCITY[0] * 2; } if (keys['ArrowRight']) { this.x += VELOCITY[0] * 2; } if (this.x < X_BOUND) { this.x = X_BOUND; } if (this.x > 1 - X_BOUND) { this.x = 1 - X_BOUND; } if (keys[' '] && Date.now() - this.lastShootTime >= 300) { this.lastShootTime = Date.now(); const bullet = new Bullet(this.x, this.y - 0.009); bullets.add(bullet); } } initLives() { $('#lives').textContent = `× ${this.lives}`; } lifeOver() { if (this.invulnerable) return; this.lives--; this.initLives(); if (this.lives === 0) { return gameOver('Game over'); } else { this.invulnerable = true; this.element.style.animationName = 'blink'; } } }