/** * 🌝 boss.luna — la Luna llena que persigue al héroe en el atardecer de la ciudad. * * Props: { arena?: { x0, x1, floor } } (límites de movimiento; por defecto ±15 u alrededor del spawn y el suelo * bajo él). y del spawn = suelo (entra bajando desde el cielo). * * Cómo se vence (5 golpes): persigue al héroe con vaivén senoidal y daña al tocarla. Cada ciclo telegrafía * una embestida (tiembla, se pone roja y marca el suelo con un anillo) y cae en picado; tras el golpe contra el * suelo queda ATURDIDA unos segundos (estrellitas): solo entonces cuentan los golpes (1 por aturdimiento). * - Fase 1 (5-4 vidas): vaivén + embestidas. * - Fase 2 (≤3): además lanza abanicos de estrellas/lunitas (`boss.luna.star`); golpéalas para devolvérselas: * si le aciertan, cae aturdida al suelo. * - Fase 3 (1 vida): furiosa (cara enfadada, rojiza), más rápida, telegrafía menos y aturde menos. * El poder COOL también la derriba. Al vencerla: explosiones, se encoge y escapa al cielo; flag `luna.defeated`, * `boss:defeated {id:'luna'}`, `ui.bossBar(null)` y lluvia de estrellas. */ import * as THREE from 'three'; import { Entity } from '../../core/entity'; import type { Body, Hit, Props } from '../../core/types'; import { createChibi } from '../../characters/chibi'; import type { ChibiRig } from '../../characters/types'; import { emojiMesh, emojiSprite } from '../../render'; import { haloTexture, meshOf, onSurface, rigBody, sharedMat, sphereGeo } from './shared'; export const LUNA = { lives: 5, size: 4, /** Radio visual / de contacto. */ radius: 1.9, hover: 4.7, wave: { amp: 1.0, freq: 2.2 }, introTime: 3.2, chaseTime: [3.0, 2.6, 1.9], chaseSpeed: [3.2, 3.8, 5.2], telegraph: [1.0, 0.9, 0.6], dashSpeed: [13, 14, 17.5], stunTime: [3.3, 3.0, 2.4], hurtTime: 0.7, recoverTime: 1.1, volley: { wind: 0.6, time: 1.15, count: [5, 5, 7], spread: 1.0, speed: 6.2, afterChase: 1.3 }, contact: { damage: 1, knock: 9 }, stompBounce: 13, defeat: { boom: 1.9, escape: 1.6, rise: 10, stars: 6 }, color: 0xfff1b8, furyColor: 0xffbf7a, emissive: 0xffd86a, furyEmissive: 0xff7a2a, deflectCd: 0.35, }; export const LUNA_STAR = { life: 4.2, radius: 0.42, damage: 1, reflectMul: 1.7, size: 0.85 }; type St = 'intro' | 'chase' | 'volley' | 'telegraph' | 'dash' | 'stunned' | 'hurt' | 'recover' | 'defeat'; const CRATERS: Array<[number, number, number]> = [ [-0.78, 0.5, 0.11], [0.82, -0.3, 0.09], [-0.55, -0.6, 0.08], [0.48, 0.66, 0.07], [-1.0, -0.05, 0.1], [1.05, 0.32, 0.06], ]; export class Luna extends Entity { declare body: Body; readonly props: Props; private rig!: ChibiRig; private readonly visual = new THREE.Group(); private halo!: THREE.Sprite; private dizzy = new THREE.Group(); private st: St = 'intro'; private stT = 0; private t = 0; lives = LUNA.lives; private arena = { x0: -15, x1: 15, floor: 0 }; private tx = 0; private volleyDone = false; private fired = false; private ringT = 0; private deflectT = 0; private boomT = 0; private lockedHero = false; private finished = false; private furious = false; private escapeY = 0; private dashVx = 0; private dashVy = 0; constructor(props: Props) { super(); this.props = props; this.team = 'enemy'; this.tags.add('boss'); this.view.add(this.visual); } get phase(): 0 | 1 | 2 { return this.lives <= 1 ? 2 : this.lives <= 3 ? 1 : 0; } get vulnerable(): boolean { return this.st === 'stunned'; } onAdded(): void { const g = this.game; const a = this.props.arena; const floor = a?.floor ?? g.physics.groundBelow(this.x, this.y + 1, 20) ?? this.y; this.arena = { x0: a?.x0 ?? this.x - 15, x1: a?.x1 ?? this.x + 15, floor }; const startY = floor + LUNA.hover + 9; this.body = g.physics.body(this.x, startY, LUNA.radius * 0.92, LUNA.radius * 0.92); this.body.noCollide = true; this.hp = this.lives; // ── vista ── const rig = createChibi({ color: LUNA.color, size: LUNA.size, expression: 'cool', hands: false, feet: false, emissive: LUNA.emissive, emissiveIntensity: 0.14, }); this.rig = rig; rig.play('float', { loop: true }); const body = rigBody(rig); const crMat = sharedMat('luna.crater', { color: 0xe6cf86, emissive: 0xffd86a, emissiveIntensity: 0.15, gloss: 0.3 }); for (const [az, el, s] of CRATERS) { const c = meshOf(sphereGeo(), crMat, false); onSurface(c, az, el, 0.495); c.lookAt(c.position.clone().multiplyScalar(2)); c.scale.set(s, s, s * 0.25); body.add(c); } this.visual.add(rig.root); const haloMat = new THREE.SpriteMaterial({ map: haloTexture(), color: new THREE.Color(0xffe39a).multiplyScalar(1.6), transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, opacity: 0.55, }); this.halo = new THREE.Sprite(haloMat); this.halo.scale.set(LUNA.radius * 4.6, LUNA.radius * 4.6, 1); this.halo.position.z = -1.2; this.view.add(this.halo); for (let i = 0; i < 4; i++) this.dizzy.add(emojiSprite('⭐', 0.6, { glow: 0.4 })); this.dizzy.visible = false; this.view.add(this.dizzy); this.setPos(this.x, startY); this.startIntro(); } onRemoved(): void { if (!this.finished) { this.game.ui.bossBar(null); this.game.gfx.cam.focus(null); } this.unlockHero(); this.rig.dispose(); } private unlockHero(): void { if (this.lockedHero && this.game.hero) this.game.hero.inputLocked = false; this.lockedHero = false; } private set(s: St): void { this.st = s; this.stT = 0; } private heroOk() { const h = this.game.hero; return h && h.alive ? h : null; } private clampX(x: number): number { const m = LUNA.radius; return Math.min(this.arena.x1 - m, Math.max(this.arena.x0 + m, x)); } private bar(): void { this.game.ui.bossBar({ name: 'La Luna', emoji: '🌝', frac: this.lives / LUNA.lives }); } // ───────── secuencias ───────── private startIntro(): void { const g = this.game; this.set('intro'); const h = g.hero; if (h) { h.inputLocked = true; this.lockedHero = true; } g.gfx.cam.focus({ x: this.x, y: this.arena.floor + LUNA.hover - 0.5 }, 0.9); g.ui.banner('¡La Luna!', 'Golpéala cuando caiga aturdida', '🌝'); g.audio.music('boss'); g.events.emit('boss:start', { id: 'luna' }); this.bar(); } update(dt: number): void { const b = this.body; const g = this.game; this.t += dt; this.stT += dt; this.deflectT = Math.max(0, this.deflectT - dt); const ph = this.phase; const floor = this.arena.floor; const hoverY = floor + LUNA.hover + Math.sin(this.t * LUNA.wave.freq) * LUNA.wave.amp; const h = this.heroOk(); switch (this.st) { case 'intro': { const u = Math.min(1, this.stT / (LUNA.introTime * 0.7)); const e = 1 - Math.pow(1 - u, 3); b.y = floor + LUNA.hover + 9 * (1 - e) + Math.sin(this.t * LUNA.wave.freq) * LUNA.wave.amp * e; if (this.stT > 1.3 && this.stT - dt <= 1.3) { g.audio.sfx('boss_roar'); g.gfx.cam.shake(0.5, 0.6); this.rig.squash(0.3); g.vfx.ring(b.x, b.y, 0xffe39a, 3); } if (this.stT >= LUNA.introTime) { this.unlockHero(); g.gfx.cam.focus(null); this.set('chase'); } break; } case 'chase': { this.follow(dt, hoverY, LUNA.chaseSpeed[ph]); const limit = this.volleyDone && ph >= 1 ? LUNA.volley.afterChase : LUNA.chaseTime[ph]; if (this.stT >= limit) { if (ph >= 1 && !this.volleyDone) { this.set('volley'); this.fired = false; this.rig.setExpression('cool'); this.rig.squash(-0.2); } else { this.set('telegraph'); this.tx = this.clampX(h ? h.x : b.x); this.ringT = 0; this.rig.setExpression('angry'); g.audio.sfx('boss_roar', { pitch: 1.25, volume: 0.7 }); } } break; } case 'volley': { this.follow(dt, hoverY, LUNA.chaseSpeed[ph] * 0.3); if (!this.fired && this.stT >= LUNA.volley.wind) { this.fired = true; this.fireVolley(); } if (this.stT >= LUNA.volley.time) { this.volleyDone = true; this.set('chase'); this.restoreFace(); } break; } case 'telegraph': { // se eleva un poco y tiembla; marca el punto de impacto b.y += (floor + LUNA.hover + 1.2 - b.y) * Math.min(1, dt * 4); b.x += (b.x < this.tx ? 1 : -1) * Math.min(Math.abs(this.tx - b.x), dt * 1.2); this.ringT -= dt; if (this.ringT <= 0) { this.ringT = 0.28; g.vfx.ring(this.tx, floor + 0.05, 0xff5a3a, 1.3); } if (this.stT >= LUNA.telegraph[ph]) this.startDash(this.tx); break; } case 'dash': { b.x += this.dashVx * dt; b.y += this.dashVy * dt; g.vfx.trail('sparkle', b.x - this.dashVx * 0.06, b.y - this.dashVy * 0.06, { color: 0xffe39a, scale: 1.4 }); const landY = floor + LUNA.radius * 0.88; if (b.y <= landY) { b.y = landY; b.x = this.clampX(b.x); this.impact(); } break; } case 'stunned': { b.y = floor + LUNA.radius * 0.88; if (this.stT >= LUNA.stunTime[ph]) { this.set('recover'); this.restoreFace(); this.rig.squash(0.25); g.audio.sfx('whoosh', { pitch: 0.6, x: b.x }); } break; } case 'hurt': { b.y = floor + LUNA.radius * 0.88 + Math.sin(Math.min(1, this.stT / LUNA.hurtTime) * Math.PI) * 0.8; if (this.stT >= LUNA.hurtTime) { this.set('recover'); this.restoreFace(); } break; } case 'recover': { const u = Math.min(1, this.stT / LUNA.recoverTime); const from = floor + LUNA.radius * 0.88; b.y = from + (hoverY - from) * (u * u * (3 - 2 * u)); if (u >= 1) { this.volleyDone = false; this.set('chase'); } break; } case 'defeat': this.updateDefeat(dt); return; } this.checkContact(); } private follow(dt: number, y: number, speed: number): void { const b = this.body; const h = this.heroOk(); const tx = this.clampX(h ? h.x : (this.arena.x0 + this.arena.x1) / 2); const vx = Math.max(-speed, Math.min(speed, (tx - b.x) * 1.6)); b.vx += (vx - b.vx) * Math.min(1, dt * 3); b.x = this.clampX(b.x + b.vx * dt); b.y += (y - b.y) * Math.min(1, dt * 3); } private startDash(tx: number): void { const b = this.body; const ph = this.phase; const dx = tx - b.x; const dy = this.arena.floor + LUNA.radius * 0.88 - b.y; const d = Math.max(0.001, Math.hypot(dx, dy)); this.dashVx = (dx / d) * LUNA.dashSpeed[ph]; this.dashVy = (dy / d) * LUNA.dashSpeed[ph]; this.set('dash'); this.rig.squash(0.35); this.game.audio.sfx('whoosh', { pitch: 0.7, x: b.x }); } private impact(): void { const g = this.game; const b = this.body; const floor = this.arena.floor; this.set('stunned'); this.volleyDone = false; g.gfx.cam.shake(0.65, 0.4); g.audio.sfx('thunder', { volume: 0.55, x: b.x }); g.audio.sfx('land', { pitch: 0.5, x: b.x }); g.vfx.burst('dust', b.x - 1.4, floor + 0.1, { count: 10, dirX: -1, scale: 1.6 }); g.vfx.burst('dust', b.x + 1.4, floor + 0.1, { count: 10, dirX: 1, scale: 1.6 }); g.vfx.ring(b.x, floor + 0.1, 0xffffff, 2.2); g.vfx.burst('star', b.x, b.y + LUNA.radius, { count: 6 }); this.rig.squash(-0.45); this.rig.setExpression('hurt'); } /** La derriba (estrella devuelta o COOL): cae y queda aturdida. */ knockDown(): void { if (this.st === 'chase' || this.st === 'volley' || this.st === 'telegraph') { const g = this.game; g.audio.sfx('boss_hit', { x: this.x }); g.vfx.burst('hit', this.x, this.y, { scale: 2 }); g.vfx.floatText('¡Derribada!', this.x, this.y + LUNA.radius + 0.4, '#ffe39a'); this.rig.flash(0xffffff, 0.2); this.rig.setExpression('surprised'); this.startDash(this.body.x); } } private restoreFace(): void { this.rig.setExpression(this.furious ? 'angry' : 'cool'); } private fireVolley(): void { const g = this.game; const b = this.body; const h = this.heroOk(); const ph = this.phase; const n = LUNA.volley.count[ph]; const base = h ? Math.atan2(h.y - b.y, h.x - b.x) : -Math.PI / 2; for (let i = 0; i < n; i++) { const a = base + (n === 1 ? 0 : (i / (n - 1) - 0.5) * LUNA.volley.spread * (ph >= 2 ? 1.3 : 1)); const sx = b.x + Math.cos(a) * LUNA.radius * 0.8; const sy = b.y + Math.sin(a) * LUNA.radius * 0.8; g.spawn('boss.luna.star', sx, sy, { vx: Math.cos(a) * LUNA.volley.speed, vy: Math.sin(a) * LUNA.volley.speed, luna: this, emoji: i % 2 ? '🌙' : '⭐', }); } g.audio.sfx('laser', { pitch: 1.3, x: b.x }); g.audio.sfx('star', { pitch: 0.8 }); g.vfx.burst('sparkle', b.x, b.y, { count: 14, color: 0xffe39a, scale: 1.6 }); this.rig.squash(0.3); } // ───────── contacto ───────── private checkContact(): void { const h = this.heroOk(); if (!h || this.st === 'intro' || this.st === 'defeat') return; const hb = h.body; const dx = hb.x - this.body.x, dy = hb.y - this.body.y; const r = LUNA.radius * 0.88 + 0.35; if (dx * dx + dy * dy > r * r) return; const harmless = this.st === 'stunned' || this.st === 'hurt' || this.st === 'recover'; // Caer encima: rebota sin daño (no cuenta como golpe salvo aturdida; eso lo resuelve takeHit) // Aturdida: basta con estar encima (cayendo o apoyado en algo) para que cuente el pisotón. const onTop = this.vulnerable ? dy > LUNA.radius * 0.3 && hb.vy <= 0.5 : hb.vy < 0 && dy > LUNA.radius * 0.5; if (onTop) { hb.vy = LUNA.stompBounce; this.game.audio.sfx('bounce', { x: hb.x }); this.rig.squash(-0.15); if (this.vulnerable) this.takeHit({ damage: 1, element: 'none', dirX: h.facing, source: h }); return; } if (harmless) return; h.takeHit({ damage: LUNA.contact.damage, element: 'none', dirX: dx < 0 ? -1 : 1, knock: LUNA.contact.knock, source: this }); } takeHit(hit: Hit): boolean { const g = this.game; if (this.st === 'defeat' || this.st === 'intro') return false; if (this.vulnerable && hit.damage > 0) { this.registerHit(hit); return true; } if (hit.element === 'cool') { this.knockDown(); return true; } if (this.deflectT <= 0 && hit.damage > 0) { this.deflectT = LUNA.deflectCd; const sx = hit.source ? (hit.source.x + this.x) / 2 : this.x; const sy = hit.source ? hit.source.y : this.y; g.vfx.burst('spark', sx, sy, { count: 6, color: 0xffe39a }); g.audio.sfx('hit', { pitch: 1.7, volume: 0.35, x: sx }); g.vfx.floatText('¡Ja, ja!', this.x, this.y + LUNA.radius + 0.3, '#ffe39a'); } return false; } private registerHit(hit: Hit): void { const g = this.game; const b = this.body; const before = this.phase; this.lives--; this.hp = this.lives; g.hitstop(0.14); g.gfx.cam.shake(0.55, 0.3); g.audio.sfx('boss_hit', { x: b.x }); g.vfx.burst('hit', b.x - (hit.dirX || 0) * LUNA.radius * 0.6, b.y, { scale: 2.2, dirX: hit.dirX }); g.vfx.burst('star', b.x, b.y + LUNA.radius * 0.6, { count: 8 }); g.vfx.floatText('-1', b.x, b.y + LUNA.radius + 0.5, '#ffffff'); this.rig.flash(0xffffff, 0.25); this.rig.squash(-0.35); this.rig.play('hurt'); this.bar(); if (this.lives <= 0) { this.startDefeat(); return; } this.set('hurt'); if (this.phase !== before) { if (this.phase === 1) { g.ui.toast('¡La Luna lanza estrellas fugaces!', '🌠'); } else if (this.phase === 2) { this.furious = true; this.rig.setColor(LUNA.furyColor); this.rig.setEmissive(LUNA.furyEmissive, 0.5); g.ui.toast('¡La Luna está furiosa!', '😡'); g.audio.sfx('boss_roar', { pitch: 0.85 }); g.vfx.ring(b.x, b.y, 0xff6a3a, 3); } } this.rig.setExpression(this.furious ? 'angry' : 'hurt'); } // ───────── derrota ───────── private startDefeat(): void { const g = this.game; this.set('defeat'); this.boomT = 0; this.dizzy.visible = false; g.ui.bossBar(null); g.gfx.cam.focus({ x: this.body.x, y: this.body.y + 1 }, 1.1); g.vfx.flash(0xffffff, 0.18); g.gfx.cam.shake(0.8, 1.2); this.rig.setExpression('hurt', 0); // destruye proyectiles en vuelo for (const e of g.allByTag('lunastar')) { g.vfx.burst('sparkle', e.x, e.y, { count: 4, color: 0xffe39a }); e.kill(); } } private updateDefeat(dt: number): void { const g = this.game; const b = this.body; const D = LUNA.defeat; const T = this.stT; if (T < D.boom) { this.boomT -= dt; if (this.boomT <= 0) { this.boomT = 0.2; const a = Math.random() * Math.PI * 2, r = Math.random() * LUNA.radius; g.vfx.burst('explosion', b.x + Math.cos(a) * r, b.y + Math.sin(a) * r, { scale: 0.9 }); g.audio.sfx('boss_hit', { pitch: 0.9 + Math.random() * 0.4, volume: 0.6 }); this.rig.flash(0xffffff, 0.12); } return; } if (T - dt < D.boom) { g.audio.sfx('boss_die'); g.vfx.flash(0xffffff, 0.4); g.vfx.burst('explosion', b.x, b.y, { scale: 2.2 }); g.vfx.burst('confetti', b.x, b.y, { count: 30 }); g.gfx.cam.focus(null); this.escapeY = b.y; this.rig.setExpression('sad'); this.dropStars(); } const u = Math.min(1, (T - D.boom) / D.escape); b.y = this.escapeY + D.rise * u * u; b.x += Math.sin(T * 9) * dt * 2; g.vfx.trail('sparkle', b.x, b.y - 0.5, { color: 0xffe39a, scale: 1.2 }); if (u >= 1 && !this.finished) this.finish(); } private dropStars(): void { const g = this.game; if (!g.hasType('item.coin')) return; const n = LUNA.defeat.stars; for (let i = 0; i < n; i++) { const x = this.clampX(this.body.x + (i - (n - 1) / 2) * 1.1); g.spawn('item.coin', x, this.arena.floor + 0.6 + (i % 2) * 0.6, { pop: true }); } } private finish(): void { const g = this.game; this.finished = true; g.vfx.burst('sparkle', this.body.x, this.body.y, { count: 20, color: 0xffe39a, scale: 2 }); g.audio.sfx('victory'); g.state.set('luna.defeated', true); g.events.emit('boss:defeated', { id: 'luna' }); g.ui.bossBar(null); this.kill(); } // ───────── render ───────── render(alpha: number, dt: number): void { super.render(alpha, dt); this.rig.update(dt); const st = this.st; const T = this.stT; // escala por estado (aplastada en el suelo, encogiéndose al escapar) let s = 1, sy = 1, rot = 0, shake = 0; if (st === 'telegraph') shake = 0.08 * Math.sin(this.t * 60); if (st === 'stunned') { sy = 0.86 + 0.04 * Math.sin(this.t * 6); rot = Math.sin(this.t * 3) * 0.12; } if (st === 'defeat') { const D = LUNA.defeat; shake = T < D.boom ? 0.12 * Math.sin(this.t * 70) : 0; if (T >= D.boom) { const u = Math.min(1, (T - D.boom) / D.escape); s = 1 - 0.75 * u; rot = u * 9; } } if (st === 'dash') rot = -Math.sign(this.dashVx) * 0.25; this.visual.scale.set(s * (2 - sy), s * sy, s); this.visual.rotation.z = rot; this.visual.position.x = shake; this.visual.position.y = -(1 - sy) * LUNA.radius * 0.5; const glow = 0.5 + 0.12 * Math.sin(this.t * 2.4) + (st === 'telegraph' ? 0.25 : 0); const hm = this.halo.material as THREE.SpriteMaterial; hm.opacity = st === 'defeat' ? glow * Math.max(0, 1 - Math.max(0, T - LUNA.defeat.boom) / LUNA.defeat.escape) : glow; if (this.furious) hm.color.setRGB(2.2, 1.0, 0.5); this.halo.scale.setScalar(LUNA.radius * (4.4 + 0.3 * Math.sin(this.t * 2.4)) * s); this.dizzy.visible = st === 'stunned'; if (this.dizzy.visible) { const n = this.dizzy.children.length; for (let i = 0; i < n; i++) { const a = this.t * 4 + (i / n) * Math.PI * 2; this.dizzy.children[i].position.set(Math.cos(a) * 1.4, LUNA.radius * 0.9 + 0.3 + Math.sin(a * 2) * 0.1, Math.sin(a) * 0.8 + 0.5); } } } } /** ⭐/🌙 proyectil de la Luna (y = centro). Props: { vx, vy, luna, emoji }. Golpéalo para devolverlo. */ export class LunaStar extends Entity { private vx: number; private vy: number; private life = LUNA_STAR.life; private reflected = false; private luna: Luna | null; private spin = (Math.random() < 0.5 ? -1 : 1) * 6; constructor(props: Props) { super(); this.vx = props.vx ?? 0; this.vy = props.vy ?? 0; this.luna = props.luna instanceof Luna ? props.luna : null; this.team = 'enemy'; this.tags.add('projectile'); this.tags.add('lunastar'); this.view.add(emojiMesh(props.emoji ?? '⭐', LUNA_STAR.size, { glow: true, shadow: false })); } bounds() { return { x: this.x, y: this.y, hw: LUNA_STAR.radius, hh: LUNA_STAR.radius }; } update(dt: number): void { const g = this.game; this.x += this.vx * dt; this.y += this.vy * dt; this.life -= dt; this.t += dt; if (Math.floor(this.t * 20) !== Math.floor((this.t - dt) * 20)) { g.vfx.trail('sparkle', this.x, this.y, { color: this.reflected ? 0x9fe8ff : 0xffe39a, scale: 0.6 }); } if (this.life <= 0 || g.physics.solidAt(this.x, this.y)) { g.vfx.burst('sparkle', this.x, this.y, { count: 5, color: 0xffe39a }); this.kill(); return; } if (this.reflected) { const l = this.luna; if (l && !l.dead) { const dx = l.x - this.x, dy = l.y - this.y; const r = LUNA.radius + LUNA_STAR.radius; if (dx * dx + dy * dy < r * r) { l.knockDown(); g.vfx.burst('star', this.x, this.y, { count: 6 }); this.kill(); } } return; } const h = g.hero; if (h && h.alive) { const hb = h.body; if (Math.abs(hb.x - this.x) < hb.hw + LUNA_STAR.radius * 0.8 && Math.abs(hb.y - this.y) < hb.hh + LUNA_STAR.radius * 0.8) { if (h.takeHit({ damage: LUNA_STAR.damage, element: 'none', dirX: this.vx < 0 ? -1 : 1, knock: 6, source: this })) { g.vfx.burst('sparkle', this.x, this.y, { count: 8, color: 0xffe39a }); this.kill(); } } } } private t = 0; takeHit(hit: Hit): boolean { if (this.reflected || this.dead) return false; const g = this.game; this.reflected = true; this.team = 'hero'; this.life = LUNA_STAR.life; const sp = Math.hypot(this.vx, this.vy) * LUNA_STAR.reflectMul; const l = this.luna; if (l && !l.dead) { const dx = l.x - this.x, dy = l.y - this.y; const d = Math.max(0.001, Math.hypot(dx, dy)); this.vx = (dx / d) * sp; this.vy = (dy / d) * sp; } else { this.vx = (hit.dirX || 1) * sp; this.vy = Math.abs(this.vy); } g.audio.sfx('punch', { pitch: 1.5, x: this.x }); g.audio.sfx('star', { pitch: 1.3, volume: 0.6 }); g.vfx.burst('spark', this.x, this.y, { count: 8, color: 0x9fe8ff }); g.vfx.floatText('¡Devuelta!', this.x, this.y + 0.6, '#9fe8ff'); g.hitstop(0.04); return true; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.view.rotation.z += this.spin * dt; const s = 1 + 0.12 * Math.sin(this.t * 18); this.view.scale.setScalar(this.reflected ? s * 1.15 : s); } }