/** * Jefes del castillo. * * 🗿 boss.stone — Jefe Piedra. Su coraza no se rompe a golpes. Alterna AURA de FUEGO y de HIELO: * · con aura de fuego: el HIELO la enfría (queda «templada»); con aura de hielo: el FUEGO la calienta. * · mientras está templada/caliente, el elemento CONTRARIO provoca un choque térmico → se agrieta y * queda ATURDIDA. Entonces la FURIA (embestida o golpe con FURIA) le hace daño. * · el mismo elemento de su aura la alimenta (no sirve). Ataques: pisotón con ondas por el suelo * (salta) y rocas que caen del techo (las marca una sombra). * * 🧙‍♂️ boss.wizard — el Hechicero (jefe final, azotea). Escudo violeta permanente salvo cuando: * · la onda COOL lo aturde, o * · le devuelves de un puñetazo uno de sus orbes. * Fases: orbes perseguidores → lluvia de meteoros (con Chispas) → rayo rasante. Los BLOQUES DE HIELO * (HIELO + LLUVIA) paran orbes, meteoros y rayos. */ import * as THREE from 'three'; import { Entity } from '../../core/entity'; import { createChibi } from '../../characters/chibi'; import type { Hit, Props } from '../../core/types'; import { Enemy, approach } from './base'; import { meshOf, sharedGeo, sharedMat, sphereGeo } from './shared'; const boxGeo = () => sharedGeo('cb.box', () => new THREE.BoxGeometry(1, 1, 1)); const coneGeo = () => sharedGeo('cb.cone', () => new THREE.ConeGeometry(1, 1, 12)); const ringGeo = () => sharedGeo('cb.ring', () => new THREE.TorusGeometry(1, 0.06, 8, 40)); const dodecaGeo = () => sharedGeo('cb.dodeca', () => new THREE.DodecahedronGeometry(1, 0)); function solidAt(e: Entity, x: number, y: number, hw: number, hh: number): boolean { return e.game.physics.query({ x, y, hw, hh }, (c) => !c.oneWay && c.enabled !== false && c.tag !== 'arena-wall').length > 0; } function iceBlockAt(e: Entity, x: number, y: number, r: number): Entity | null { for (const b of e.game.allByTag('iceblock')) { if (!b.dead && Math.abs(b.x - x) < 0.5 + r && Math.abs(b.y - y) < 0.5 + r) return b; } return null; } // ───────────────────────────── 🗿 Jefe Piedra ───────────────────────────── export const STONE = { hp: 6, hw: 1.15, hh: 1.4, auraTime: 9, softTime: 3.6, stunTime: 4.2, walk: 1.6 }; type Aura = 'fire' | 'ice'; export class StoneBoss extends Enemy { aura: Aura = 'fire'; private auraT = STONE.auraTime; private softT = 0; // templada (fuego→hielo) o caliente (hielo→fuego) private stunned = 0; private atkT = 2.2; private lastImmune = -9; private head = new THREE.Group(); private auraMesh: THREE.Mesh | null = null; private cracks: THREE.Mesh[] = []; private announced = false; constructor(props: Props) { super(props); this.hw = STONE.hw; this.hh = STONE.hh; this.maxHp = STONE.hp; this.freezable = false; this.burnable = false; this.stompable = false; this.shadowRadius = 1.4; this.drop = 'none'; this.contactDamage = 1; this.tags.add('boss'); this.state = 'idle'; } protected build(): void { // Cabeza de piedra estilo 🗿: alargada, ceño pesado, nariz larga y labios planos const stone = sharedMat('stone.body', { color: 0x9a96a8, gloss: 0.2, rim: 0.4 }); const dark = sharedMat('stone.dark', { color: 0x5e5a6e, gloss: 0.2, rim: 0.3 }); const h = this.head; const skull = meshOf(boxGeo(), stone); skull.scale.set(1.9, 2.7, 1.6); skull.position.y = 0.1; h.add(skull); const top = meshOf(sphereGeo(), stone); top.scale.set(0.98, 0.5, 0.82); top.position.y = 1.42; h.add(top); const brow = meshOf(boxGeo(), dark); brow.scale.set(2.0, 0.38, 0.5); brow.position.set(0, 0.62, 0.72); h.add(brow); for (const s of [-1, 1]) { const eye = meshOf(boxGeo(), sharedMat('stone.eye', { color: 0x2b2430, gloss: 0.4 })); eye.scale.set(0.42, 0.2, 0.2); eye.position.set(s * 0.45, 0.36, 0.78); h.add(eye); const ear = meshOf(boxGeo(), stone); ear.scale.set(0.24, 0.9, 0.42); ear.position.set(s * 1.04, 0.2, 0); h.add(ear); } const nose = meshOf(boxGeo(), stone); nose.scale.set(0.42, 1.05, 0.52); nose.position.set(0, -0.05, 0.92); nose.rotation.x = -0.12; h.add(nose); const lip = meshOf(boxGeo(), dark); lip.scale.set(0.9, 0.18, 0.4); lip.position.set(0, -0.75, 0.82); h.add(lip); const chin = meshOf(boxGeo(), stone); chin.scale.set(1.3, 0.42, 1.0); chin.position.set(0, -1.12, 0.36); h.add(chin); // grietas (aparecen al aturdirlo) for (let i = 0; i < 4; i++) { const c = meshOf(boxGeo(), sharedMat('stone.crack', { color: 0xffd28a, emissive: 0xff9a3a, emissiveIntensity: 0.8 }), false); c.scale.set(0.06, 0.7, 0.05); c.position.set(-0.6 + i * 0.4, 0.1 + (i % 2) * 0.3, 0.82); c.rotation.z = (i % 2 ? 0.5 : -0.4); c.visible = false; h.add(c); this.cracks.push(c); } // aura const aura = meshOf(sphereGeo(), sharedMat('stone.auraFire', { color: 0xff8a2a, emissive: 0xff5a10, emissiveIntensity: 0.35, transparent: true, opacity: 0.1, depthWrite: false }), false); aura.scale.set(1.75, 2.15, 1.5); h.add(aura); this.auraMesh = aura; this.visual.add(h); } protected afterAdded(): void { this.applyAura(); } private applyAura(): void { if (!this.auraMesh) return; this.auraMesh.material = this.aura === 'fire' ? sharedMat('stone.auraFire', { color: 0xff8a2a, emissive: 0xff5a10, emissiveIntensity: 0.35, transparent: true, opacity: 0.1, depthWrite: false }) : sharedMat('stone.auraIce', { color: 0x9fdcff, emissive: 0x2a8cff, emissiveIntensity: 0.35, transparent: true, opacity: 0.1, depthWrite: false }); if (this.aura === 'fire') this.tags.add('hot'); else this.tags.delete('hot'); this.game.ui.bossBar({ name: `Jefe Piedra · aura de ${this.aura === 'fire' ? 'FUEGO 🔥' : 'HIELO 🥶'}`, emoji: '🗿', frac: Math.max(0, this.hp / this.maxHp) }); } private immune(text: string, color = '#ffe3a8'): void { if (this.game.time - this.lastImmune < 0.7) return; this.lastImmune = this.game.time; this.game.vfx.floatText(text, this.x, this.y + this.hh + 0.8, color); } get active(): boolean { return !this.defeated && this.stunned <= 0; } protected harmful(): boolean { return !this.defeated && this.stunned <= 0; } takeHit(hit: Hit): boolean { if (this.defeated) return false; const g = this.game; const el = hit.element; if (this.stunned > 0) { if (el === 'fury') { this.hp -= 1; g.hitstop(0.08); g.gfx.cam.shake(0.45, 0.3); g.audio.sfx('boss_hit', { x: this.x }); g.vfx.burst('shatter', this.x, this.y + 0.6, { count: 14, color: 0x9a96a8, scale: 1.4 }); g.vfx.floatText('-1', this.x, this.y + this.hh + 0.6, '#ff6a4a'); this.applyAura(); if (this.hp <= 0) this.defeat(); else { // tras un golpe vuelve en sí con el aura contraria this.stunned = Math.min(this.stunned, 0.6); } return true; } this.immune('¡Ahora! Embiste con FURIA 😡', '#ff8a5a'); return true; } const opposite: Aura = this.aura === 'fire' ? 'ice' : 'fire'; // ya templado/caliente por el contrario: su propio elemento provoca el choque térmico if (this.softT > 0 && el === this.aura) { this.softT = 0; this.stunned = STONE.stunTime; this.setState('stunned'); g.audio.sfx('shatter', { x: this.x, pitch: 0.7 }); g.gfx.cam.shake(0.5, 0.35); g.vfx.burst('smoke', this.x, this.y + 0.8, { count: 20, scale: 1.6 }); g.vfx.floatText('¡Choque térmico! ¡FURIA!', this.x, this.y + this.hh + 1, '#ffb15a'); for (const c of this.cracks) c.visible = true; return true; } if (el === this.aura) { this.immune(this.aura === 'fire' ? '¡El fuego lo alimenta!' : '¡El hielo lo alimenta!', '#ffd28a'); return true; } if (el === opposite) { this.softT = STONE.softTime; g.audio.sfx(opposite === 'ice' ? 'freeze' : 'fire', { x: this.x }); g.vfx.burst(opposite === 'ice' ? 'ice' : 'fire', this.x, this.y + 0.4, { count: 16, scale: 1.4 }); this.immune(opposite === 'ice' ? '¡Templado! Ahora FUEGO 🔥' : '¡Caliente! Ahora HIELO 🥶', '#bfeaff'); return true; } g.vfx.burst('spark', this.x + (hit.dirX || 0) * 1, this.y + 0.4, { count: 6, color: 0xd0ccdf }); this.immune(`Coraza de piedra: usa ${opposite === 'ice' ? 'HIELO 🥶' : 'FUEGO 🔥'}`, '#d0ccdf'); return true; } private defeat(): void { const g = this.game; this.defeated = true; g.ui.bossBar(null); g.audio.sfx('boss_die'); g.gfx.cam.shake(0.8, 0.8); g.vfx.burst('shatter', this.x, this.y + 0.5, { count: 40, color: 0x9a96a8, scale: 2 }); g.vfx.burst('confetti', this.x, this.y + 1, { count: 30 }); g.state.set('castle.stone.defeated', true); g.state.save(); g.events.emit('boss:defeated', { id: 'stone' }); g.ui.banner('¡Jefe Piedra derrotado!', 'El salón de armas es tuyo', '🗿'); g.after(0.6, () => this.kill()); } update(dt: number): void { if (this.defeated) return; if (!this.announced) { this.announced = true; this.applyAura(); } if (this.stunned > 0) { this.stunned -= dt; this.body.vx = approach(this.body.vx, 0, 20 * dt); if (this.stunned <= 0) { for (const c of this.cracks) c.visible = false; this.aura = this.aura === 'fire' ? 'ice' : 'fire'; this.auraT = STONE.auraTime; this.applyAura(); this.setState('idle'); } } else { this.softT = Math.max(0, this.softT - dt); this.auraT -= dt; if (this.auraT <= 0 && this.softT <= 0) { this.aura = this.aura === 'fire' ? 'ice' : 'fire'; this.auraT = STONE.auraTime; this.applyAura(); this.game.audio.sfx('boss_roar', { x: this.x, volume: 0.6 }); } } super.update(dt); } protected think(dt: number): void { const b = this.body; const d = this.heroDelta(); this.atkT -= dt; switch (this.state) { case 'idle': if (d) { this.facing = d.dx > 0 ? 1 : -1; b.vx = approach(b.vx, Math.abs(d.dx) > 3 ? this.facing * STONE.walk : 0, 6 * dt); } if (this.atkT <= 0 && b.onGround) { this.atkT = 3.2; this.setState(Math.random() < 0.55 ? 'crouch' : 'rocks'); b.vx = 0; } break; case 'crouch': b.vx = 0; if (this.stateT > 0.7) { b.vy = 15; this.setState('air'); } break; case 'air': if (b.onGround && this.stateT > 0.2) { this.slam(); this.setState('idle'); } break; case 'rocks': b.vx = 0; if (this.stateT > 0.5) { this.dropRocks(); this.setState('idle'); } break; default: this.setState('idle'); } } private slam(): void { const g = this.game; g.gfx.cam.shake(0.6, 0.35); g.audio.sfx('boss_hit', { x: this.x, pitch: 0.6 }); g.vfx.burst('dust', this.x, this.y - this.hh, { count: 20, scale: 1.6 }); const feet = this.body.y - this.hh; for (const dir of [-1, 1]) g.spawn('boss.wave', this.x + dir * 1.4, feet, { dir, element: this.aura }); } private dropRocks(): void { const g = this.game; const h = g.hero; if (!h) return; g.audio.sfx('boss_roar', { x: this.x, volume: 0.7, pitch: 0.8 }); const xs = [h.x, h.x - 3 - Math.random() * 2, h.x + 3 + Math.random() * 2]; for (const x of xs) { const top = (g.zone?.bounds.maxY ?? 14) - 1; g.spawn('boss.rock', x, top, { floor: this.body.y - this.hh }); } } protected animate(dt: number): void { const t = this.t; const stun = this.stunned > 0; this.head.rotation.z = stun ? Math.sin(t * 20) * 0.05 : Math.sin(t * 1.5) * 0.03; this.head.position.y = this.state === 'crouch' ? -0.25 : 0; if (this.auraMesh) { this.auraMesh.visible = !stun; const s = 1 + Math.sin(t * 3) * 0.04 + (this.softT > 0 ? 0.08 : 0); this.auraMesh.scale.set(1.75 * s, 2.15 * s, 1.5 * s); } this.visual.rotation.y = this.facing > 0 ? -0.25 : 0.25; } onRemoved(): void { super.onRemoved(); this.game.ui.bossBar(null); } } /** Onda de choque que recorre el suelo (salta para esquivarla). */ export class ShockWave extends Entity { private t = 0; private readonly dir: number; private readonly mesh: THREE.Mesh; constructor(p: Props) { super(); this.dir = p.dir ?? 1; this.team = 'enemy'; const ice = p.element === 'ice'; this.mesh = meshOf(coneGeo(), sharedMat(ice ? 'wave.ice' : 'wave.fire', ice ? { color: 0xbfeaff, emissive: 0x4aa8e8, emissiveIntensity: 0.6, gloss: 1 } : { color: 0xff8a2a, emissive: 0xff5a10, emissiveIntensity: 0.9 }), false); this.mesh.scale.set(0.38, 0.8, 0.38); this.mesh.position.y = 0.4; this.view.add(this.mesh); } update(dt: number): void { this.t += dt; this.x += this.dir * 7.5 * dt; const g = this.game; if (this.t > 1.7 || solidAt(this, this.x + this.dir * 0.3, this.y + 0.4, 0.1, 0.25)) { this.kill(); return; } if (iceBlockAt(this, this.x, this.y + 0.4, 0.2)) { g.vfx.burst('ice', this.x, this.y + 0.4, { count: 6 }); this.kill(); return; } g.hitArea({ x: this.x, y: this.y + 0.45, hw: 0.3, hh: 0.45 }, { damage: 1, element: 'none', dirX: this.dir, knock: 7, source: this }, 'enemy'); if (Math.random() < 0.5) g.vfx.trail('dust', this.x, this.y + 0.1, { scale: 0.7 }); } render(alpha: number, dt: number): void { super.render(alpha, dt); const k = 1 + Math.sin(this.t * 30) * 0.1; this.mesh.scale.set(0.38, 0.8 * k, 0.38); } } /** Roca que cae del techo con su sombra de aviso. */ export class FallingRock extends Entity { private t = 0; private vy = 0; private readonly floor: number; private readonly rock: THREE.Mesh; private readonly mark: THREE.Mesh; private readonly warn = 0.9; constructor(p: Props) { super(); this.floor = p.floor ?? 0; this.team = 'enemy'; this.rock = meshOf(dodecaGeo(), sharedMat('rock.fall', { color: 0x8a86a0, gloss: 0.2, rim: 0.4 })); this.rock.scale.setScalar(0.55); this.mark = meshOf(ringGeo(), sharedMat('rock.mark', { color: 0x2b2430, transparent: true, opacity: 0.45, depthWrite: false }), false); this.mark.rotation.x = Math.PI / 2; this.mark.scale.set(0.7, 0.7, 0.7); this.view.add(this.rock, this.mark); } update(dt: number): void { this.t += dt; if (this.t < this.warn) return; this.vy -= 30 * dt; this.y += this.vy * dt; const g = this.game; const blk = iceBlockAt(this, this.x, this.y, 0.4); if (blk) { (blk as Entity & { melt?: () => void }).melt?.(); g.vfx.burst('shatter', this.x, this.y, { count: 10, color: 0x8a86a0 }); this.kill(); return; } g.hitArea({ x: this.x, y: this.y, hw: 0.45, hh: 0.45 }, { damage: 1, element: 'none', dirX: 0, knock: 5, source: this }, 'enemy'); if (this.y <= this.floor + 0.45) { g.vfx.burst('shatter', this.x, this.floor + 0.3, { count: 12, color: 0x8a86a0 }); g.audio.sfx('hit', { x: this.x, pitch: 0.6, volume: 0.6 }); this.kill(); } } render(alpha: number, dt: number): void { super.render(alpha, dt); this.rock.rotation.x += dt * 3; this.rock.rotation.z += dt * 2; this.mark.position.y = this.floor - this.y + 0.05; const k = Math.min(1, this.t / this.warn); this.mark.scale.setScalar(0.3 + 0.5 * k); this.rock.visible = this.t >= this.warn - 0.15; } } // ───────────────────────────── 🧙‍♂️ Hechicero ───────────────────────────── export const WIZARD = { hp: 9, hw: 0.55, hh: 0.7, stun: 3.6, spots: [-6, 0, 6] }; export class Wizard extends Enemy { private shield: THREE.Mesh | null = null; private stunned = 0; private castT = 2.5; private spot = 2; private baseX = 0; private baseY = 0; private lastImmune = -9; private phase = 1; started = false; constructor(props: Props) { super(props); this.hw = WIZARD.hw; this.hh = WIZARD.hh; this.maxHp = WIZARD.hp; this.flying = true; this.freezable = false; this.burnable = false; this.stompable = false; this.drop = 'none'; this.shadowRadius = 0.6; this.tags.add('boss'); this.state = 'wait'; } protected spawnCenterY(y: number): number { return y + 2.6; } protected afterAdded(): void { this.baseX = this.x; this.baseY = this.y; } protected build(): void { const rig = createChibi({ color: 0x9a7ad8, size: 1.3, expression: 'evil', outfit: 'wizard', footColor: 0x2a1240 }); this.rig = rig; const sh = meshOf(sphereGeo(), sharedMat('wiz.shield', { color: 0xd0b0ff, emissive: 0x8f3cff, emissiveIntensity: 0.45, transparent: true, opacity: 0.28, depthWrite: false, gloss: 1, rim: 1, }), false); sh.scale.setScalar(1.2); this.visual.add(sh); this.shield = sh; } /** Empieza la pelea (lo llama la azotea tras la escena del Rey). */ begin(): void { this.started = true; this.setState('float'); this.bar(); } private bar(): void { this.game.ui.bossBar({ name: 'Hechicero', emoji: '🧙‍♂️', frac: Math.max(0, this.hp / this.maxHp) }); } get shielded(): boolean { return this.stunned <= 0; } /** Un orbe devuelto le rompe el escudo. */ breakShield(): void { if (this.defeated) return; this.stunned = WIZARD.stun; this.game.audio.sfx('shatter', { x: this.x }); this.game.vfx.burst('shatter', this.x, this.y, { count: 18, color: 0xd0b0ff, scale: 1.3 }); this.game.vfx.floatText('¡Escudo roto! ¡Ataca!', this.x, this.y + 1.6, '#ffe066'); } takeHit(hit: Hit): boolean { if (this.defeated || !this.started) return false; const g = this.game; if (hit.element === 'cool') { this.breakShield(); this.rig?.setExpression('surprised'); return true; } if (this.shielded) { if (g.time - this.lastImmune > 0.8) { this.lastImmune = g.time; g.vfx.floatText('Escudo mágico: COOL 😎 o devuélvele un orbe 👊', this.x, this.y + 1.7, '#d0b0ff'); } g.vfx.burst('spark', this.x, this.y, { count: 5, color: 0xd0b0ff }); return true; } const dmg = hit.element === 'fury' || hit.damage >= 2 ? 2 : 1; this.hp -= dmg; g.hitstop(0.06); g.audio.sfx('boss_hit', { x: this.x }); g.vfx.floatText(`-${dmg}`, this.x, this.y + 1.2, '#ff6a4a'); this.rig?.play('hurt'); this.bar(); if (this.hp <= 0) { this.finish(); return true; } const ph = this.hp <= this.maxHp / 3 ? 3 : this.hp <= (this.maxHp * 2) / 3 ? 2 : 1; if (ph !== this.phase) { this.phase = ph; this.stunned = 0; g.ui.toast(ph === 2 ? '¡El Hechicero invoca una lluvia de meteoros!' : '¡El Hechicero prepara su rayo final!', '🧙‍♂️'); this.teleport(); } return true; } private finish(): void { const g = this.game; this.defeated = true; g.ui.bossBar(null); g.audio.sfx('boss_die'); g.gfx.cam.shake(0.7, 0.8); g.vfx.burst('poof', this.x, this.y, { count: 30, scale: 2 }); g.vfx.burst('sparkle', this.x, this.y, { count: 30, color: 0xd0b0ff, scale: 2 }); for (const e of g.entities) if (e.tags.has('enemy') && e !== this && !(e as Enemy).defeated) (e as Enemy).die?.('none'); g.events.emit('boss:defeated', { id: 'wizard' }); g.after(0.8, () => this.kill()); } private teleport(): void { const g = this.game; g.vfx.burst('poof', this.x, this.y, { count: 14 }); g.audio.sfx('teleport', { x: this.x, pitch: 0.8 }); let next = this.spot; while (next === this.spot) next = Math.floor(Math.random() * WIZARD.spots.length); this.spot = next; this.baseX = (this.props.cx ?? this.x) + WIZARD.spots[next]; this.body.x = this.baseX; this.body.y = this.baseY; this.x = this.px = this.body.x; this.y = this.py = this.body.y; g.vfx.burst('poof', this.x, this.y, { count: 14 }); } get active(): boolean { return !this.defeated; } protected harmful(): boolean { return this.started && !this.defeated; } update(dt: number): void { if (this.stunned > 0) { this.stunned -= dt; if (this.stunned <= 0) { this.rig?.setExpression('evil'); this.teleport(); } } super.update(dt); } protected think(dt: number): void { const b = this.body; if (!this.started) { b.vx = 0; b.vy = 0; return; } // flota sobre su punto const ty = this.baseY + Math.sin(this.t * 1.6) * 0.4; b.vx = (this.baseX + Math.sin(this.t * 0.7) * 0.8 - this.x) * 3; b.vy = (ty - this.y) * 3; if (this.stunned > 0) { b.vy = Math.min(b.vy, -1); return; } const d = this.heroDelta(); if (d) this.facing = d.dx > 0 ? 1 : -1; this.castT -= dt; if (this.castT > 0) return; const g = this.game; this.rig?.play('special', { speed: 1 }); g.audio.sfx('laser', { x: this.x, pitch: 0.9, volume: 0.6 }); if (this.phase === 1) { this.castT = 3; for (let i = 0; i < 3; i++) g.after(i * 0.35, () => { if (!this.defeated) g.spawn('boss.orb', this.x + this.facing * 0.8, this.y + 0.3, { owner: this.id }); }); } else if (this.phase === 2) { this.castT = 3.6; const h = g.hero; if (h) for (let i = 0; i < 4; i++) g.spawn('boss.meteor', h.x - 4.5 + i * 3 + Math.random(), this.baseY + 7, { floor: h.y - h.body.hh }); g.spawn('boss.orb', this.x + this.facing * 0.8, this.y + 0.3, { owner: this.id }); if (g.allByTag('hot').filter((e) => !e.dead).length < 2 && g.hasType('enemy.ember')) g.spawn('enemy.ember', this.x, (g.hero?.y ?? this.y) - 0.5, { hover: 1.6, range: 9 }); } else { this.castT = 3.4; const h = g.hero; if (h) g.spawn('boss.beam', this.x, h.y - h.body.hh, { dir: this.facing, owner: this.id }); g.after(1.6, () => { if (!this.defeated) g.spawn('boss.orb', this.x + this.facing * 0.8, this.y + 0.3, { owner: this.id }); }); } } protected animate(dt: number): void { super.animate(dt); if (this.shield) { this.shield.visible = this.shielded && this.started; const s = 1.2 + Math.sin(this.t * 3) * 0.04; this.shield.scale.setScalar(s); } } onRemoved(): void { super.onRemoved(); this.game.ui.bossBar(null); } } /** Orbe mágico que persigue despacio. Lo paran los bloques de hielo; un puñetazo lo devuelve. */ export class WizardOrb extends Entity { private vx = 0; private vy = 0; private t = 0; private reflected = false; private readonly ownerId: number; private readonly mesh: THREE.Mesh; constructor(p: Props) { super(); this.ownerId = p.owner ?? -1; this.team = 'enemy'; this.tags.add('projectile'); this.mesh = meshOf(sphereGeo(), sharedMat('wiz.orb', { color: 0xe0c8ff, emissive: 0xa050ff, emissiveIntensity: 1.2, gloss: 1 }), false); this.mesh.scale.setScalar(0.3); this.view.add(this.mesh); } bounds() { return { x: this.x, y: this.y, hw: 0.35, hh: 0.35 }; } takeHit(hit: Hit): boolean { if (this.reflected) return false; if (hit.element === 'fire' || hit.element === 'water') { this.pop(); return true; } // ¡devuelto! this.reflected = true; this.team = 'hero'; const owner = this.game.entities.find((e) => e.id === this.ownerId); const dx = owner ? owner.x - this.x : (hit.dirX || 1) * 5; const dy = owner ? owner.y - this.y : 0; const l = Math.max(0.1, Math.hypot(dx, dy)); this.vx = (dx / l) * 11; this.vy = (dy / l) * 11; this.game.audio.sfx('punch', { x: this.x, pitch: 1.4 }); this.game.vfx.ring(this.x, this.y, 0xffe066, 0.7); return true; } private pop(): void { this.game.vfx.burst('sparkle', this.x, this.y, { count: 10, color: 0xd0b0ff }); this.game.audio.sfx('pop', { x: this.x, pitch: 0.7 }); this.kill(); } update(dt: number): void { const g = this.game; this.t += dt; if (this.reflected) { const owner = g.entities.find((e) => e.id === this.ownerId) as Wizard | undefined; if (owner && !owner.dead && Math.abs(owner.x - this.x) < 1 && Math.abs(owner.y - this.y) < 1.1) { owner.breakShield(); this.pop(); return; } } else { const h = g.hero; if (h) { const dx = h.x - this.x; const dy = h.y - this.y; const l = Math.max(0.1, Math.hypot(dx, dy)); this.vx = approach(this.vx, (dx / l) * 3.6, 6 * dt); this.vy = approach(this.vy, (dy / l) * 3.6, 6 * dt); if (Math.abs(dx) < h.body.hw + 0.25 && Math.abs(dy) < h.body.hh + 0.25) { h.takeHit({ damage: 1, element: 'none', dirX: Math.sign(dx) || 1, knock: 6, source: this }); this.pop(); return; } } } this.x += this.vx * dt; this.y += this.vy * dt; const blk = iceBlockAt(this, this.x, this.y, 0.25); if (blk && !this.reflected) { (blk as Entity & { melt?: () => void }).melt?.(); this.pop(); return; } if (this.t > 7 || solidAt(this, this.x, this.y, 0.2, 0.2)) this.pop(); } render(alpha: number, dt: number): void { super.render(alpha, dt); const s = 0.3 + Math.sin(this.t * 8) * 0.03; this.mesh.scale.setScalar(s); } } /** Meteoro: sombra de aviso y caída. Lo para un bloque de hielo (que se derrite). */ export class Meteor extends Entity { private t = 0; private vy = 0; private readonly floor: number; private readonly rock: THREE.Mesh; private readonly mark: THREE.Mesh; constructor(p: Props) { super(); this.floor = p.floor ?? 0; this.team = 'enemy'; this.tags.add('hot'); this.rock = meshOf(dodecaGeo(), sharedMat('meteor', { color: 0xff8a2a, emissive: 0xff5a10, emissiveIntensity: 1.1 })); this.rock.scale.setScalar(0.42); this.mark = meshOf(ringGeo(), sharedMat('meteor.mark', { color: 0xff5a10, transparent: true, opacity: 0.5, depthWrite: false }), false); this.mark.rotation.x = Math.PI / 2; this.view.add(this.rock, this.mark); } update(dt: number): void { this.t += dt; if (this.t < 1) return; this.vy -= 26 * dt; this.y += this.vy * dt; const g = this.game; const blk = iceBlockAt(this, this.x, this.y, 0.35); if (blk) { (blk as Entity & { melt?: () => void }).melt?.(); g.vfx.burst('smoke', this.x, this.y, { count: 10 }); this.kill(); return; } g.hitArea({ x: this.x, y: this.y, hw: 0.4, hh: 0.4 }, { damage: 1, element: 'fire', dirX: 0, knock: 5, source: this }, 'enemy'); if (this.y <= this.floor + 0.4) { g.vfx.burst('fire', this.x, this.floor + 0.3, { count: 12 }); g.audio.sfx('fireball', { x: this.x, volume: 0.5 }); this.kill(); } } render(alpha: number, dt: number): void { super.render(alpha, dt); this.rock.rotation.x += dt * 4; this.mark.position.y = this.floor - this.y + 0.05; this.mark.scale.setScalar(0.3 + 0.45 * Math.min(1, this.t)); this.rock.visible = this.t >= 0.85; } } /** Rayo rasante: una línea de aviso y luego un haz a ras de suelo. Solo un bloque de hielo lo para. */ export class WizardBeam extends Entity { private t = 0; private readonly dir: number; private readonly beam: THREE.Mesh; private reach = 30; constructor(p: Props) { super(); this.dir = p.dir ?? 1; this.team = 'enemy'; this.beam = meshOf(boxGeo(), sharedMat('wiz.beam', { color: 0xf0e0ff, emissive: 0xb070ff, emissiveIntensity: 1.3, transparent: true, opacity: 0.85 }), false); this.view.add(this.beam); } update(dt: number): void { this.t += dt; const g = this.game; const y = this.y + 0.55; // hasta dónde llega: lo corta el primer bloque de hielo o muro let reach = 30; for (let s = 0.5; s < 30; s += 0.5) { const x = this.x + this.dir * s; if (iceBlockAt(this, x, y, 0.1) || solidAt(this, x, y, 0.1, 0.2)) { reach = s; break; } } this.reach = reach; if (this.t > 1 && this.t < 1.6) { const cx = this.x + this.dir * reach / 2; g.hitArea({ x: cx, y, hw: reach / 2, hh: 0.4 }, { damage: 1, element: 'none', dirX: this.dir, knock: 8, source: this }, 'enemy'); } if (this.t > 1.75) this.kill(); } render(alpha: number, dt: number): void { super.render(alpha, dt); const firing = this.t > 1 && this.t < 1.6; const th = firing ? 0.7 : 0.06; this.beam.scale.set(this.reach, th, firing ? 0.7 : 0.06); this.beam.position.set(this.dir * this.reach / 2, 0.55, 0.2); this.beam.visible = this.t < 1.6; } }