import { Zombie } from './Zombie.js'; export class Boss extends Zombie { constructor( x, y, target, { container, viewport, speed = 38, size = 90, color = [0.45, 0.05, 0.1, 1], health = 80, knockback = 40, scoreValue = 50, spawnInterval = 5, spawnCount = 1, spawnZombie = () => {}, onDeath = null, } = {}, ) { super(x, y, target, { container, viewport, speed, size, color, health, knockback, scoreValue, onDeath, }); this.spawnInterval = spawnInterval; this.spawnCount = spawnCount; this.spawnTimer = 3; this.spawnZombie = spawnZombie; this._time = 0; this._hurt = 0; } hit(impulse, damage = 1) { const dead = super.hit(impulse, damage); this._flash = 0.18; this._hurt = 0.18; return dead; } update(dt) { super.update(dt); this._time += dt; this._hurt = Math.max(0, this._hurt - dt); this.spawnTimer -= dt; if (this.spawnTimer <= 0) { this.spawnTimer = this.spawnInterval; const minions = this.container.filter( (obj) => obj instanceof Zombie && !(obj instanceof Boss), ); if (minions.length < 15) { for (let i = 0; i < this.spawnCount; i += 1) { const angle = (i / this.spawnCount) * Math.PI * 2 + Math.random() * 0.6; this.spawnZombie( this.pos.x + Math.cos(angle) * 70, this.pos.y + Math.sin(angle) * 70, this.target, this.container, ); } } } } draw(renderer) { this.width = this.size; this.height = this.size; const pulse = 1 + 0.05 * Math.sin(this._time * 4); const hurtRatio = this._hurt / 0.18; const s = this.size * pulse * (1 + hurtRatio * 0.14); const hpRatio = Math.max(0, this.health / this.maxHealth); const color = [ Math.min(1, this.baseColor[0] + (1 - hpRatio) * 0.3), this.baseColor[1] * hpRatio, this.baseColor[2] * hpRatio, 1, ]; renderer.drawTexture( renderer.whiteTexture, this.pos.x - s / 2, this.pos.y - s / 2, s, s, this._flash > 0 ? [1, 1, 1, 1] : color, ); const core = s * (0.35 + (1 - hpRatio) * 0.4); renderer.drawTexture( renderer.whiteTexture, this.pos.x - core / 2, this.pos.y - core / 2, core, core, [0.12, 0.02, 0.03, 0.9], ); } }