/** * Enemigos «de poder»: cada uno exige usar un EmojiPower concreto (o una combinación). * * · 🔥 enemy.ember — Chispa. Llama flotante: los golpes, la FURIA y el FUEGO no le hacen nada y quema al * tocarla. Se apaga con AGUA (pistola), con la LLUVIA cerca o congelándola con HIELO * (y luego un golpe la rompe). Es «caliente»: revienta las burbujas y derrite el hielo. * · 🪲 enemy.beetle — Escarabajo acorazado. Su caparazón desvía golpes, fuego y hielo. Solo la embestida de * FURIA lo voltea panza arriba; entonces cualquier golpe le hace daño. * · 🧊 enemy.frost — Gólem de escarcha. Armadura de hielo: el HIELO lo cura y los golpes rebotan. Una bola de * FUEGO derrite la armadura y queda vulnerable. Golpea el suelo y lanza una ola de pinchos. * · 🔮 enemy.turret — Torreta de cristal. Fija; dispara esquirlas que se detienen con muros o BLOQUES DE HIELO * (HIELO + LLUVIA), que las DEVUELVEN: 3 cristales devueltos la destruyen para siempre. * Si no, es invulnerable salvo cuando el COOL la aturde o el HIELO la congela. * · enemy.shard — proyectil de la torreta. */ import * as THREE from 'three'; import { Entity } from '../../core/entity'; import { createChibi } from '../../characters/chibi'; import type { Hit, Props } from '../../core/types'; import { isToolOn } from '../../core/slots'; import { isRainingAt } from '../../world/weather'; import { Enemy, approach, clampPatrol, groundAhead, wallAhead } from './base'; import { meshOf, rigBody, sharedGeo, sharedMat, sphereGeo } from './shared'; const coneGeo = () => sharedGeo('el.cone', () => new THREE.ConeGeometry(1, 1, 14)); const hemiGeo = () => sharedGeo('el.hemi', () => new THREE.SphereGeometry(1, 22, 12, 0, Math.PI * 2, 0, Math.PI / 2)); const octaGeo = () => sharedGeo('el.octa', () => new THREE.OctahedronGeometry(1, 0)); /** Aviso de inmunidad (con límite para no llenar la pantalla). */ function immune(e: Enemy & { lastImmune?: number }, text: string, color = '#ffe3a8'): void { const g = e.game; if (g.time - (e.lastImmune ?? -9) < 0.6) return; e.lastImmune = g.time; g.vfx.floatText(text, e.x, e.y + e.hh + 0.6, color); g.audio.sfx('error', { volume: 0.25, x: e.x }); } // ───────────────────────────── 🔥 Chispa ───────────────────────────── export const EMBER = { hp: 2, hw: 0.34, hh: 0.36, size: 0.78, range: 6.5, hover: 1.4, chase: 2.6, lunge: 6, heat: 1.7 }; export class Ember extends Enemy { readonly heatRadius = EMBER.heat; lastImmune = -9; private homeX = 0; private homeY = 0; private flame: THREE.Group | null = null; private dousedT = 0; private trailT = 0; constructor(props: Props) { super(props); this.hw = EMBER.hw; this.hh = EMBER.hh; this.maxHp = EMBER.hp; this.flying = true; this.burnable = false; this.freezable = true; this.waterWeak = true; this.stompable = false; this.contactElement = 'fire'; this.shadowRadius = 0.3; this.drop = 'star'; this.baseColor = 0xff8a1e; this.state = 'hover'; this.tags.add('hot'); } protected spawnCenterY(y: number): number { return y + (this.props.hover ?? EMBER.hover); } protected afterAdded(): void { this.homeX = this.x; this.homeY = this.y; } protected build(): void { const rig = createChibi({ color: 0xff8a1e, size: EMBER.size, expression: 'fierce', feet: false, hands: true, handColor: 0xffc928, emissive: 0xff5a00, emissiveIntensity: 0.35, }); this.rig = rig; // llama sobre la cabeza: tres lenguas que ondulan const f = new THREE.Group(); const outer = sharedMat('ember.flame', { color: 0xff8a1a, emissive: 0xff5a10, emissiveIntensity: 1.6, gloss: 0.4, rim: 1 }); const core = sharedMat('ember.core', { color: 0xffe066, emissive: 0xffd000, emissiveIntensity: 1.9, gloss: 0.4 }); const a = meshOf(coneGeo(), outer, false); a.scale.set(0.32, 0.62, 0.32); a.position.set(0, 0.62, 0); const b = meshOf(coneGeo(), outer, false); b.scale.set(0.2, 0.42, 0.2); b.position.set(-0.2, 0.5, 0.05); b.rotation.z = 0.5; const c = meshOf(coneGeo(), outer, false); c.scale.set(0.2, 0.42, 0.2); c.position.set(0.2, 0.5, -0.05); c.rotation.z = -0.5; const d = meshOf(coneGeo(), core, false); d.scale.set(0.16, 0.36, 0.16); d.position.set(0, 0.52, 0.12); f.add(a, b, c, d); rigBody(rig).add(f); this.flame = f; } protected restoreExpression(): void { this.rig?.setExpression('fierce'); } takeHit(hit: Hit): boolean { if (!this.frozen && (hit.element === 'none' || hit.element === 'fury' || hit.element === 'fire')) { immune(this, hit.element === 'fire' ? '¡Más fuego!' : '¡Quema! Usa agua o hielo', '#ffb15a'); if (hit.element === 'fire') { this.game.vfx.burst('fire', this.x, this.y, { count: 6 }); return true; } return false; } return super.takeHit(hit); } protected think(dt: number): void { const g = this.game; const b = this.body; // ── la lluvia cercana la apaga poco a poco ── const h = this.hero; if ((isToolOn(g.state, 'rain') && h && Math.abs(h.x - this.x) < 11) || isRainingAt(g, this.x, this.y)) { this.dousedT += dt; this.trailT -= dt; if (this.trailT <= 0) { this.trailT = 0.12; g.vfx.trail('smoke', this.x, this.y + 0.4, { scale: 0.7, color: 0xd8e0e8 }); } if (this.dousedT > 1.6) { g.audio.sfx('splash', { x: this.x, pitch: 1.4 }); g.vfx.floatText('¡Apagada!', this.x, this.y + 0.8, '#9fdcff'); this.die('water'); return; } } else this.dousedT = Math.max(0, this.dousedT - dt); const d = this.heroDelta(); const P = this.props; switch (this.state) { case 'hover': { const tx = this.homeX + Math.sin(this.t * 0.9) * 1.6; const ty = this.homeY + Math.sin(this.t * 2.1) * 0.35; b.vx = approach(b.vx, (tx - this.x) * 2, 10 * dt); b.vy = approach(b.vy, (ty - this.y) * 2.5, 10 * dt); if (d && d.dist < (P.range ?? EMBER.range) && this.stateT > 1) { this.setState('wind'); this.rig?.squash(-0.3); g.audio.sfx('fire', { x: this.x, volume: 0.5, pitch: 1.4 }); } break; } case 'wind': { b.vx = approach(b.vx, 0, 12 * dt); b.vy = approach(b.vy, 0, 12 * dt); if (this.stateT > 0.55 && d) { const k = EMBER.lunge / Math.max(0.5, d.dist); b.vx = d.dx * k; b.vy = d.dy * k; this.facing = d.dx > 0 ? 1 : -1; this.setState('lunge'); } break; } case 'lunge': { this.trailT -= dt; if (this.trailT <= 0) { this.trailT = 0.05; g.vfx.trail('fire', this.x, this.y, { scale: 0.7 }); } if (this.stateT > 0.6) this.setState('back'); break; } case 'back': { b.vx = approach(b.vx, (this.homeX - this.x) * 1.5, 8 * dt); b.vy = approach(b.vy, (this.homeY - this.y) * 1.5, 8 * dt); if (this.stateT > 1.6) this.setState('hover'); break; } default: this.setState('hover'); } } protected animate(dt: number): void { super.animate(dt); if (this.flame) { const s = 1 + Math.sin(this.t * 7 + this.homeX) * 0.07; this.flame.scale.set(1 / Math.sqrt(s), s * (this.frozen ? 0.4 : 1), 1); this.flame.visible = !this.frozen; } const k = Math.max(0.35, 1 - this.dousedT / 1.6); this.visual.scale.setScalar(k); } } // ───────────────────────────── 🪲 Escarabajo acorazado ───────────────────────────── export const BEETLE = { hp: 2, hw: 0.5, hh: 0.42, size: 1.05, walk: 1.4, charge: 6.5, range: 6, flipped: 3.6 }; export class Beetle extends Enemy { lastImmune = -9; private shell: THREE.Group | null = null; private flipK = 0; constructor(props: Props) { super(props); this.hw = BEETLE.hw; this.hh = BEETLE.hh; this.maxHp = BEETLE.hp; this.freezable = false; this.burnable = false; this.baseColor = 0x3fbf8f; this.shadowRadius = 0.6; this.state = 'patrol'; } protected build(): void { const rig = createChibi({ color: 0x3fbf8f, size: BEETLE.size, expression: 'angry', handColor: 0x2b6b55, footColor: 0x2b2430, }); this.rig = rig; const body = rigBody(rig); // caparazón metálico en cúpula con dos élitros y brillo const s = new THREE.Group(); const shellMat = sharedMat('beetle.shell', { color: 0x2f5fb8, gloss: 0.95, rim: 0.9, emissive: 0x10204a, emissiveIntensity: 0.25 }); const lineMat = sharedMat('beetle.line', { color: 0x14203e, gloss: 0.5 }); const dome = meshOf(hemiGeo(), shellMat); dome.scale.set(0.6, 0.5, 0.56); dome.position.set(0, 0.02, -0.06); dome.rotation.x = -0.35; const seam = meshOf(sphereGeo(), lineMat, false); seam.scale.set(0.02, 0.38, 0.5); seam.position.set(0, 0.25, -0.06); seam.rotation.x = -0.35; // cuernecito delante const horn = meshOf(coneGeo(), shellMat); horn.scale.set(0.09, 0.28, 0.09); horn.position.set(0, 0.5, 0.18); horn.rotation.x = 0.4; s.add(dome, seam, horn); body.add(s); this.shell = s; } get flipped(): boolean { return this.state === 'flipped'; } protected harmful(): boolean { return this.active && !this.flipped; } protected onStomp(): void { const h = this.game.hero; if (!h) return; if (!this.flipped) { h.body.vy = 11; this.game.audio.sfx('bounce', { x: this.x, pitch: 0.8 }); immune(this, '¡Clang!', '#bfd8ff'); return; } super.onStomp(); } takeHit(hit: Hit): boolean { if (this.defeated) return false; if (this.flipped) return super.takeHit({ ...hit, damage: Math.max(1, hit.damage) }); if (hit.element === 'fury') { this.setState('flipped'); this.body.vy = 7; this.body.vx = (hit.dirX || 1) * 3; this.rig?.setExpression('hurt'); this.game.audio.sfx('hit', { x: this.x, pitch: 0.6 }); this.game.gfx.cam.shake(0.25, 0.2); this.game.vfx.burst('star', this.x, this.y + 0.4, { count: 6 }); this.game.vfx.floatText('¡Volteado!', this.x, this.y + 1.1, '#ff8a5a'); return true; } if (hit.element === 'cool') return super.takeHit(hit); this.game.vfx.burst('spark', this.x + (hit.dirX || 0) * 0.4, this.y + 0.3, { count: 6, color: 0xbfd8ff }); immune(this, hit.element === 'fire' || hit.element === 'ice' ? '¡El caparazón lo aguanta!' : '¡Clang! Usa la FURIA', '#bfd8ff'); return true; } protected think(dt: number): void { const b = this.body; const P = this.props; switch (this.state) { case 'patrol': { const dir = this.facing; if (b.onGround && (wallAhead(this, dir) || !groundAhead(this, dir) || clampPatrol(this, P.patrol, dir))) { this.facing = -dir as 1 | -1; b.vx = 0; } b.vx = approach(b.vx, this.facing * BEETLE.walk, 10 * dt); const d = this.heroDelta(); if (d && Math.abs(d.dx) < (P.range ?? BEETLE.range) && Math.abs(d.dy) < 1.5 && this.stateT > 1.2) { this.facing = d.dx > 0 ? 1 : -1; this.setState('wind'); b.vx = 0; this.rig?.squash(-0.25); } break; } case 'wind': b.vx = approach(b.vx, 0, 30 * dt); if (this.stateT > 0.5) this.setState('charge'); break; case 'charge': { const dir = this.facing; b.vx = approach(b.vx, dir * BEETLE.charge, 24 * dt); if ((b.onGround && (wallAhead(this, dir) || !groundAhead(this, dir, 0.3))) || this.stateT > 1.1) { b.vx = 0; this.setState('patrol'); } break; } case 'flipped': b.vx = approach(b.vx, 0, 10 * dt); if (this.stateT > BEETLE.flipped) { this.setState('patrol'); this.rig?.setExpression('angry'); this.body.vy = 5; } break; default: this.setState('patrol'); } } protected animate(dt: number): void { super.animate(dt); const target = this.flipped ? Math.PI : 0; this.flipK += (target - this.flipK) * Math.min(1, dt * 10); this.visual.rotation.z = this.flipK * this.facing; this.visual.position.y = Math.sin(this.flipK) * 0.1 + (this.flipped ? -0.05 : 0); if (this.flipped) this.visual.rotation.y = Math.sin(this.t * 14) * 0.15; else this.visual.rotation.y = 0; if (this.shell) this.shell.position.y = this.state === 'wind' ? -0.04 : 0; } } // ───────────────────────────── 🧊 Gólem de escarcha ───────────────────────────── export const FROST = { hp: 3, hw: 0.62, hh: 0.66, size: 1.45, walk: 1.1, range: 6, slamWind: 0.75, slamCd: 2.6 }; export class FrostGolem extends Enemy { lastImmune = -9; private armored = true; private armor: THREE.Group | null = null; private cd = 1.5; constructor(props: Props) { super(props); this.hw = FROST.hw; this.hh = FROST.hh; this.maxHp = FROST.hp; this.freezable = false; this.burnable = true; this.baseColor = 0xa9daf7; this.shadowRadius = 0.8; this.contactElement = 'ice'; this.state = 'patrol'; } protected build(): void { const rig = createChibi({ color: 0xa9daf7, size: FROST.size, expression: 'cold', handColor: 0x7fbfe8, footColor: 0x5a86b8, emissive: 0x2a8cff, emissiveIntensity: 0.08, }); this.rig = rig; const body = rigBody(rig); const a = new THREE.Group(); const ice = sharedMat('frost.armor', { color: 0xd8f3ff, emissive: 0x6fc8ff, emissiveIntensity: 0.25, gloss: 1, rim: 1, transparent: true, opacity: 0.8, }); // cristales que le salen de los hombros y la coronilla const spikes: Array<[number, number, number, number, number]> = [ [0, 0.5, -0.05, 0.13, 0], [-0.3, 0.38, -0.05, 0.11, 0.6], [0.3, 0.38, -0.05, 0.11, -0.6], [-0.42, 0.05, -0.1, 0.1, 1.1], [0.42, 0.05, -0.1, 0.1, -1.1], [0.15, 0.45, -0.2, 0.08, -0.3], ]; for (const [x, y, z, r, rot] of spikes) { const s = meshOf(octaGeo(), ice); s.scale.set(r, r * 2.6, r); s.position.set(x, y, z); s.rotation.z = rot; a.add(s); } const plate = meshOf(sphereGeo(), ice); plate.scale.set(0.42, 0.3, 0.2); plate.position.set(0, -0.18, 0.38); a.add(plate); body.add(a); this.armor = a; } protected restoreExpression(): void { this.rig?.setExpression(this.armored ? 'cold' : 'angry'); } takeHit(hit: Hit): boolean { if (this.defeated) return false; if (this.armored) { if (hit.element === 'fire') { this.armored = false; if (this.armor) this.armor.visible = false; this.game.audio.sfx('shatter', { x: this.x }); this.game.vfx.burst('ice', this.x, this.y + 0.3, { count: 22, scale: 1.4 }); this.game.vfx.burst('smoke', this.x, this.y + 0.6, { count: 10 }); this.game.vfx.floatText('¡Armadura derretida!', this.x, this.y + 1.4, '#ff9a5a'); this.rig?.setExpression('angry'); this.daze(1.4); return true; } if (hit.element === 'ice') { if (this.hp < this.maxHp) this.hp++; immune(this, '¡El hielo lo fortalece!', '#bfeaff'); return true; } if (hit.element === 'cool') return super.takeHit(hit); this.game.vfx.burst('ice', this.x + (hit.dirX || 0) * 0.5, this.y + 0.3, { count: 6, scale: 0.7 }); immune(this, 'Armadura de hielo: ¡usa FUEGO!', '#bfeaff'); return true; } return super.takeHit(hit); } protected think(dt: number): void { const b = this.body; const P = this.props; this.cd = Math.max(0, this.cd - dt); switch (this.state) { case 'patrol': { const dir = this.facing; if (b.onGround && (wallAhead(this, dir) || !groundAhead(this, dir) || clampPatrol(this, P.patrol, dir))) { this.facing = -dir as 1 | -1; b.vx = 0; } b.vx = approach(b.vx, this.facing * FROST.walk, 6 * dt); const d = this.heroDelta(); if (d && this.cd <= 0 && Math.abs(d.dx) < (P.range ?? FROST.range) && Math.abs(d.dy) < 2.5) { this.facing = d.dx > 0 ? 1 : -1; this.setState('wind'); b.vx = 0; this.rig?.play('special', { speed: 0.8 }); this.game.audio.sfx('freeze', { x: this.x, pitch: 0.6 }); } break; } case 'wind': b.vx = 0; this.visual.position.y = Math.min(0.25, this.stateT * 0.4); if (this.stateT > FROST.slamWind) this.slam(); break; case 'recover': b.vx = approach(b.vx, 0, 20 * dt); if (this.stateT > 0.6) this.setState('patrol'); break; default: this.setState('patrol'); } } private slam(): void { const g = this.game; this.visual.position.y = 0; this.rig?.squash(-0.4); g.gfx.cam.shake(0.35, 0.25); g.audio.sfx('shatter', { x: this.x, pitch: 0.7 }); const feet = this.body.y - this.hh; // ola de pinchos de hielo a lo largo del suelo, hacia el héroe const dir = this.facing; for (let i = 1; i <= 5; i++) { g.after(i * 0.09, () => { if (this.defeated) return; const x = this.x + dir * (0.6 + i * 0.85); const gy = g.physics.groundBelow(x, feet + 0.6, 1.5); if (gy === null) return; g.vfx.burst('ice', x, gy + 0.3, { count: 5, scale: 0.9 }); g.hitArea({ x, y: gy + 0.45, hw: 0.4, hh: 0.45 }, { damage: 1, element: 'ice', dirX: dir, knock: 7, source: this }, 'enemy'); }); } this.cd = FROST.slamCd; this.setState('recover'); } } // ───────────────────────────── 🔮 Torreta de cristal ───────────────────────────── export const TURRET = { hp: 3, hw: 0.45, hh: 0.5, period: 2.6, charge: 0.7, speed: 7, reflectSpeed: 12, range: 13, stunned: 4.5 }; export class CrystalTurret extends Enemy { lastImmune = -9; private shotT = 1.2; private gem: THREE.Mesh | null = null; private charging = 0; /** Bandera de torreta destruida con sus propios cristales (no reaparece). */ private brokenFlag = ''; constructor(props: Props) { super(props); this.hw = TURRET.hw; this.hh = TURRET.hh; this.maxHp = TURRET.hp; this.flying = true; this.freezable = true; this.burnable = false; this.stompable = false; this.shadowRadius = 0; this.baseColor = 0xb07cff; this.state = 'idle'; } protected build(): void { const base = sharedMat('turret.base', { color: 0x5a4a8a, gloss: 0.6, rim: 0.6 }); const crystal = sharedMat('turret.gem', { color: 0xc8a8ff, emissive: 0x8f5bff, emissiveIntensity: 0.45, gloss: 1, rim: 1 }); const pedestal = meshOf(sharedGeo('turret.ped', () => new THREE.CylinderGeometry(0.42, 0.52, 0.42, 16)), base); pedestal.position.y = -0.3; const gem = meshOf(octaGeo(), crystal); gem.scale.set(0.36, 0.52, 0.36); gem.position.y = 0.2; // ojo: un cristal pequeño que apunta const eye = meshOf(sphereGeo(), sharedMat('turret.eye', { color: 0x2b2430, gloss: 0.8 }), false); eye.scale.setScalar(0.09); eye.position.set(0, 0.24, 0.3); gem.add(eye); eye.position.set(0, 0.05, 0.85); this.visual.add(pedestal, gem); this.gem = gem; } protected afterAdded(): void { this.brokenFlag = `turret.broken.${this.game.zone?.id ?? 'x'}.${Math.round(this.x)}_${Math.round(this.y)}`; if (this.game.state.has(this.brokenFlag)) { this.defeated = true; this.kill(); } } /** Un cristal propio devuelto por una barrera de hielo atraviesa su escudo. */ reflectedHit(dir: number): void { if (this.defeated) return; const g = this.game; g.vfx.burst('shatter', this.x, this.y + 0.2, { count: 14, color: 0xd8c0ff, scale: 1.1 }); g.audio.sfx('shatter', { x: this.x }); g.gfx.cam.shake(0.25, 0.2); this.damage(1, dir, '#e0ccff'); if (!this.defeated) { g.vfx.floatText(`¡Agrietada! ${this.hp}/${this.maxHp}`, this.x, this.y + 1.3, '#e0ccff'); return; } g.state.set(this.brokenFlag, true); g.state.save(); g.vfx.burst('explosion', this.x, this.y + 0.3, { scale: 1.2 }); g.vfx.floatText('¡Disparador destruido!', this.x, this.y + 1.4, '#ffe066'); } protected spawnCenterY(y: number): number { return y + this.hh; } /** Solo es vulnerable aturdida (COOL) o congelada (HIELO). */ takeHit(hit: Hit): boolean { if (this.defeated) return false; if (hit.element === 'cool') { this.daze(TURRET.stunned); this.game.vfx.floatText('¡Detenida!', this.x, this.y + 1.2, '#ffe066'); return true; } if (this.frozen || this.stunT > 0 || hit.element === 'ice') return super.takeHit(hit); this.game.vfx.burst('spark', this.x, this.y + 0.3, { count: 5, color: 0xd8c0ff }); immune(this, 'Escudo: ¡usa COOL o devuélvele sus cristales con hielo!', '#d8c0ff'); return true; } protected think(dt: number): void { const b = this.body; b.vx = 0; b.vy = 0; const d = this.heroDelta(); if (!d || Math.abs(d.dx) > (this.props.range ?? TURRET.range) || Math.abs(d.dy) > 6) { this.charging = 0; return; } this.facing = d.dx > 0 ? 1 : -1; this.shotT -= dt; if (this.shotT <= TURRET.charge) this.charging = 1 - Math.max(0, this.shotT) / TURRET.charge; if (this.shotT <= 0) { this.shotT = this.props.period ?? TURRET.period; this.charging = 0; const dir = this.facing; const vy = Math.max(-0.4, Math.min(0.4, d.dy / Math.max(1, Math.abs(d.dx)))) * TURRET.speed; this.game.spawn('enemy.shard', this.x + dir * 0.6, this.y + 0.2, { vx: dir * TURRET.speed, vy, owner: this }); this.game.audio.sfx('laser', { x: this.x, pitch: 1.8, volume: 0.5 }); this.rig?.squash(0.2); } } protected animate(dt: number): void { super.animate(dt); if (!this.gem) return; const stopped = this.stunT > 0 || this.frozen; this.gem.rotation.y = stopped ? this.gem.rotation.y : this.gem.rotation.y + dt * (1.2 + this.charging * 8); this.gem.rotation.y = Math.atan2(Math.sin(this.gem.rotation.y), Math.cos(this.gem.rotation.y)); const s = 1 + this.charging * 0.25; this.gem.scale.set(0.36 * s, 0.52 * s, 0.36 * s); this.gem.position.y = 0.2 + Math.sin(this.t * 2) * 0.05; } } /** Esquirla de cristal: viaja recta; la detienen muros y golpes. Los BLOQUES DE HIELO la devuelven a su torreta. */ export class Shard extends Entity { private vx: number; private vy: number; private t = 0; private readonly mesh: THREE.Mesh; private readonly owner: CrystalTurret | null; private reflected = false; constructor(props: Props) { super(); this.owner = props.owner ?? null; this.vx = props.vx ?? 6; this.vy = props.vy ?? 0; this.team = 'enemy'; this.tags.add('projectile'); this.mesh = meshOf(octaGeo(), sharedMat('turret.shard', { color: 0xe0ccff, emissive: 0xa070ff, emissiveIntensity: 0.9, gloss: 1, rim: 1 }), false); this.mesh.scale.set(0.34, 0.13, 0.13); this.mesh.rotation.z = Math.atan2(this.vy, this.vx); this.view.add(this.mesh); } takeHit(_hit: Hit): boolean { if (this.reflected) return false; this.burst(); return true; } private burst(): void { if (this.dead) return; this.game.vfx.burst('shatter', this.x, this.y, { count: 6, color: 0xd8c0ff, scale: 0.6 }); this.game.audio.sfx('shatter', { x: this.x, volume: 0.4, pitch: 1.6 }); this.kill(); } update(dt: number): void { this.t += dt; this.x += this.vx * dt; this.y += this.vy * dt; const g = this.game; if (this.reflected) { this.flyBack(dt); return; } if (this.iceAhead()) { this.reflect(); return; } if (this.t > 3 || g.physics.query({ x: this.x, y: this.y, hw: 0.15, hh: 0.12 }, (c) => !c.oneWay && c.enabled !== false).length) { this.burst(); return; } const h = g.hero; if (h && Math.abs(h.x - this.x) < h.body.hw + 0.18 && Math.abs(h.y - this.y) < h.body.hh + 0.14) { if (h.takeHit({ damage: 1, element: 'none', dirX: Math.sign(this.vx) || 1, knock: 6, source: this })) this.burst(); } } private iceAhead(): boolean { return this.game.physics.query( { x: this.x, y: this.y, hw: 0.2, hh: 0.16 }, (c) => c.tag === 'iceblock' && c.enabled !== false, ).length > 0; } private reflect(): void { const o = this.owner; if (!o || o.dead || o.defeated) { this.burst(); return; } const g = this.game; this.reflected = true; this.team = 'hero'; this.t = 0; g.audio.sfx('bounce', { x: this.x, pitch: 1.8 }); g.audio.sfx('freeze', { x: this.x, pitch: 1.5, volume: 0.5 }); g.vfx.ring(this.x, this.y, 0xbfeaff, 0.9); g.vfx.floatText('¡Devuelto!', this.x, this.y + 0.8, '#bfeaff'); this.mesh.scale.set(0.46, 0.18, 0.18); } /** Cristal devuelto: vuelve directo a la torreta que lo disparó. */ private flyBack(dt: number): void { const o = this.owner; if (!o || o.dead || o.defeated || this.t > 4) { this.burst(); return; } const dx = o.x - this.x, dy = o.y + 0.15 - this.y; const d = Math.hypot(dx, dy); const step = TURRET.reflectSpeed * dt; if (d <= Math.max(step, 0.55)) { o.reflectedHit(Math.sign(dx) || 1); this.burst(); return; } this.x += (dx / d) * step; this.y += (dy / d) * step; this.mesh.rotation.z = Math.atan2(dy, dx); this.game.vfx.trail('ice', this.x, this.y, { scale: 0.6 }); } render(alpha: number, dt: number): void { super.render(alpha, dt); this.mesh.rotation.x += dt * 12; } }