/** * Piezas 3D y mecΓ‘nicas propias del Bosque Susurro 🌲. * * Todo lo que no es terreno del kit vive aquΓ­ para no tocar `kit/props.ts`: * Β· FarmPatch β€” cultivos secos que reverdecen con LLUVIA o agua. * Β· RainVine β€” enredaderas / setas que crecen mientras llueve. * Β· DryPond β€” poza seca: la lluvia la llena y sube la balsa. * Β· LavaCrossing β€” lava que se enfrΓ­a con lluvia y forma una costra pisable. * Β· CrackedRock β€” roca agrietada que solo rompe la FURIA. * Β· Burnable β€” zarzas / telaraΓ±as que solo quema el FUEGO. * Β· Torch β€” antorcha que se enciende con una bola de fuego. * Β· FireSwitch β€” interruptor de fuego (ideal para rebotar la bola). * Β· FlowerSwitch β€” flor que se abre con agua. * Β· CoolSwitch β€” cristal que reacciona a la onda COOL. * Β· IceSecret β€” secreto de HIELO (cascada, bloque o poza helada). * Β· FrozenDrop β€” repisas de gotas heladas (lluvia + HIELO). * Β· CastleGate β€” puerta de hielo del castillo que solo derrite el FUEGO. * * Recursos compartidos (geometrΓ­as/materiales) a nivel de mΓ³dulo. Nada asigna memoria por frame * salvo los grupos propios de cada entidad, creados una vez. */ import * as THREE from 'three'; import { PooledLight } from '../../render/lightPool'; import { Entity } from '../../core/entity'; import type { Area, Collider, Hit, Props } from '../../core/types'; import { isToolOn } from '../../core/slots'; import { isRainingAt } from '../weather'; import { tallyAdd } from '../../core/tally'; import { kitMat, P } from '../kit/util'; // ───────────────────────────── Recursos compartidos ───────────────────────────── const shared = }>(o: T): T => { o.userData.shared = true; return o; }; const GEO = { box: shared(new THREE.BoxGeometry(1, 1, 1)), sph: shared(new THREE.SphereGeometry(1, 20, 14)), sphLo: shared(new THREE.SphereGeometry(1, 10, 8)), cyl: shared(new THREE.CylinderGeometry(1, 1, 1, 16)), cone: shared(new THREE.ConeGeometry(1, 1, 12)), hemi: shared(new THREE.SphereGeometry(1, 20, 10, 0, Math.PI * 2, 0, Math.PI / 2)), torus: shared(new THREE.TorusGeometry(1, 0.12, 8, 28)), plane: shared(new THREE.PlaneGeometry(1, 1)), octa: shared(new THREE.OctahedronGeometry(1, 0)), }; const MAT = { soil: kitMat('fSoil', { color: 0x7a5230, gloss: 0.12, rim: 0.2 }), soilWet: kitMat('fSoilWet', { color: 0x4f341e, gloss: 0.35, rim: 0.22 }), soilDry: kitMat('fSoilDry', { color: 0xa8814e, gloss: 0.08, rim: 0.18 }), wood: kitMat('fWood', { color: 0x8a5a34, gloss: 0.3, rim: 0.35 }), darkWood: kitMat('fDarkWood', { color: 0x5a3a20, gloss: 0.25, rim: 0.3 }), plank: kitMat('fPlank', { color: 0xb07a44, gloss: 0.35, rim: 0.35 }), leaf: kitMat('fLeaf', { color: 0x3f9b45, gloss: 0.4, rim: 0.4 }), leafDark: kitMat('fLeafDark', { color: 0x2a6b33, gloss: 0.35, rim: 0.35 }), leafDry: kitMat('fLeafDry', { color: 0x9a9a4a, gloss: 0.2, rim: 0.2 }), leafBright: kitMat('fLeafBright', { color: 0x5bd23c, gloss: 0.5, rim: 0.5 }), pink: kitMat('fPink', { color: 0xff7ab8, gloss: 0.55, rim: 0.5 }), petal: kitMat('fPetal', { color: 0xffc1e0, gloss: 0.55, rim: 0.5 }), gold: kitMat('fGold', { color: 0xffc928, gloss: 0.8, rim: 0.7 }), danger: kitMat('fDanger', { color: 0xf2452e, gloss: 0.5, rim: 0.5 }), stone: kitMat('fStone', { color: 0x8a8f9a, gloss: 0.3, rim: 0.45 }), rock: kitMat('fRock', { color: 0x6b7280, gloss: 0.25, rim: 0.4 }), dark: kitMat('fDark', { color: 0x2b2430, gloss: 0.2, rim: 0.2 }), metal: kitMat('fMetal', { color: 0x3b3f5c, gloss: 0.7, rim: 0.6 }), flame: kitMat('fFlame', { color: 0xff8a1a, emissive: 0xff5a10, emissiveIntensity: 1.8, gloss: 0.4, rim: 1 }), flameCore: kitMat('fFlameCore', { color: 0xffe066, emissive: 0xffd000, emissiveIntensity: 2.2, gloss: 0.4 }), ember: kitMat('fEmber', { color: 0xffc928, emissive: 0xff7a14, emissiveIntensity: 0.8, gloss: 0.7 }), ice: kitMat('fIce', { color: 0xbfeaff, emissive: 0x4aa8e8, emissiveIntensity: 0.3, gloss: 1, rim: 1, transparent: true, opacity: 0.52, depthWrite: false, }), iceSolid: kitMat('fIceSolid', { color: 0xd8f3ff, emissive: 0x6fc8ff, emissiveIntensity: 0.22, gloss: 0.9, rim: 1, transparent: true, opacity: 0.82, }), water: kitMat('fWater', { color: 0x4fc3ff, emissive: 0x2fa8f5, emissiveIntensity: 0.2, gloss: 1, rim: 0.9, transparent: true, opacity: 0.58, depthWrite: false, }), vapor: kitMat('fVapor', { color: 0xdfe8f0, transparent: true, opacity: 0.35, depthWrite: false, gloss: 0.2 }), web: kitMat('fWeb', { color: 0xffffff, transparent: true, opacity: 0.55, depthWrite: false, gloss: 0.2 }), crack: kitMat('fCrack', { color: 0x1e1a22, gloss: 0.1, rim: 0.1 }), cool: kitMat('fCool', { color: 0x7fd8ff, emissive: 0x2fa8f5, emissiveIntensity: 0.5, gloss: 1, rim: 1 }), coolOn: kitMat('fCoolOn', { color: 0xa8ecff, emissive: 0x2fa8f5, emissiveIntensity: 1.2, gloss: 1, rim: 1 }), }; function part(parent: THREE.Object3D, geo: THREE.BufferGeometry, mat: THREE.Material, x: number, y: number, z: number, sx: number, sy: number, sz: number, rx = 0, ry = 0, rz = 0): THREE.Mesh { const m = new THREE.Mesh(geo, mat); m.position.set(x, y, z); m.scale.set(sx, sy, sz); m.rotation.set(rx, ry, rz); m.castShadow = true; m.receiveShadow = true; parent.add(m); return m; } const rainOn = (e: Entity): boolean => isToolOn(e.game.state, 'rain'); declare module '../../core/types' { interface GameEvents { 'tool:toggle': { tool: 'flashlight' | 'rain'; on: boolean }; 'castle:gate': { open: boolean } } } function warn(e: Entity, text: string, color = '#ffe3a8'): void { e.game.vfx.floatText(text, e.x, e.y + 2.1, color); } // ───────────────────────────── Granja ───────────────────────────── /** Cultivo seco que reverdece al mojarlo (lluvia o pistola de agua). */ export class FarmPatch extends Entity { private readonly index: number; private readonly kind: string; private readonly dry = new THREE.Group(); private readonly wetCrop = new THREE.Group(); private isWet = false; private offRain: (() => void) | null = null; private pop = 0; constructor(props: Props) { super(); this.index = Number(props.index ?? 0); this.kind = String(props.kind ?? 'corn'); this.team = 'neutral'; } onAdded(): void { const g = this.game; part(this.view, GEO.sph, MAT.soilDry, 0, 0.12, 0, 0.72, 0.16, 0.42); this.buildCrop(this.dry, true); this.buildCrop(this.wetCrop, false); this.view.add(this.dry, this.wetCrop); this.isWet = g.state.has(`forest.farm.${this.index}`); this.apply(); this.offRain = g.events.on('tool:toggle', (e) => { if (e.tool === 'rain' && e.on) this.wet(); }); } onRemoved(): void { this.offRain?.(); this.offRain = null; } private buildCrop(root: THREE.Group, dry: boolean): void { const leaf = dry ? MAT.leafDry : MAT.leafBright; const stem = dry ? MAT.leafDry : MAT.leaf; if (this.kind === 'corn') { const s = dry ? 0.72 : 1.15; part(root, GEO.cyl, stem, 0, 0.28 * s, 0, 0.055, 0.58 * s, 0.055); for (const side of [-1, 1]) { part(root, GEO.sphLo, leaf, side * 0.13, 0.38 * s, 0.04, 0.18, 0.06, 0.09, 0, 0, side * -0.5); part(root, GEO.sphLo, leaf, side * 0.1, 0.2 * s, 0.02, 0.15, 0.05, 0.08, 0, 0, side * 0.6); } if (!dry) { part(root, GEO.sphLo, MAT.gold, 0.1, 0.44, 0.08, 0.08, 0.17, 0.07, 0.2, 0, -0.25); part(root, GEO.sphLo, MAT.gold, -0.08, 0.3, 0.05, 0.07, 0.14, 0.065, -0.1, 0, 0.3); } } else if (this.kind === 'carrot') { const s = dry ? 0.68 : 1.08; if (!dry) part(root, GEO.cone, MAT.danger, 0, 0.18, 0, 0.12, 0.26, 0.12, Math.PI); for (let i = 0; i < 4; i++) { const a = (i / 4) * Math.PI * 2 + 0.3; part(root, GEO.cone, leaf, Math.cos(a) * 0.1, 0.35 * s, Math.sin(a) * 0.06, 0.06, 0.34 * s, 0.06, 0, 0, Math.cos(a) * 0.55); } } else if (this.kind === 'sunflower') { const s = dry ? 0.66 : 1.1; part(root, GEO.cyl, stem, 0, 0.4 * s, 0, 0.05, 0.8 * s, 0.05); part(root, GEO.sphLo, leaf, 0.12, 0.4 * s, 0.03, 0.15, 0.05, 0.08, 0, 0, -0.5); part(root, GEO.sphLo, leaf, -0.11, 0.3 * s, 0.02, 0.13, 0.05, 0.07, 0, 0, 0.5); if (!dry) { part(root, GEO.sph, MAT.gold, 0, 0.86, 0.02, 0.2, 0.2, 0.1); for (let i = 0; i < 8; i++) { const a = (i / 8) * Math.PI * 2; part(root, GEO.sphLo, MAT.gold, Math.cos(a) * 0.2, 0.86 + Math.sin(a) * 0.2, 0.02, 0.11, 0.07, 0.05, 0, 0, a); } part(root, GEO.sphLo, MAT.darkWood, 0, 0.86, 0.09, 0.08, 0.08, 0.04); } else { part(root, GEO.sphLo, MAT.leafDry, 0, 0.84, 0.02, 0.14, 0.14, 0.07); } } } private apply(): void { this.dry.visible = !this.isWet; this.wetCrop.visible = this.isWet; } wet(): void { if (this.isWet) return; this.isWet = true; this.pop = 1; this.game.state.set(`forest.farm.${this.index}`, true); this.apply(); this.game.vfx.burst('splash', this.x, this.y + 0.4, { count: 8, color: 0x7fd0ff }); this.game.audio.sfx('splash', { pitch: 1.3, volume: 0.4, x: this.x }); } takeHit(hit: Hit): boolean { if (hit.element === 'water') { this.wet(); return true; } return false; } bounds() { return { x: this.x, y: this.y + 0.55, hw: 0.75, hh: 0.6 }; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.pop = Math.max(0, this.pop - dt * 2.5); const s = 1 + Math.sin(this.pop * Math.PI) * 0.18; this.wetCrop.scale.set(1 / Math.sqrt(s), s, 1 / Math.sqrt(s)); } } // ───────────────────────────── Lluvia: enredaderas y setas ───────────────────────────── /** Plataforma vegetal que crece mientras la LLUVIA estΓ‘ activa. */ export class RainVine extends Entity { private col!: Collider; private readonly plant = new THREE.Group(); private readonly width: number; private readonly kind: string; private grow = 0; constructor(props: Props) { super(); this.width = Number(props.w ?? 1.8); this.kind = String(props.kind ?? 'vine'); this.tags.add('platform'); } onAdded(): void { this.col = this.game.physics.box(this.x, this.y - 0.13, this.width, 0.26, { oneWay: true, material: 'grass', owner: this, tag: 'rain-vine', vx: 0, vy: 0, enabled: false, }); const h = 1.25; this.plant.position.y = -h; if (this.kind === 'mushroom') { part(this.plant, GEO.cyl, MAT.plank, 0, h * 0.45, 0, 0.14, h * 0.85, 0.14); part(this.plant, GEO.hemi, MAT.danger, 0, h * 0.83, 0, this.width * 0.5, 0.3, this.width * 0.4); for (let i = 0; i < 5; i++) { const a = (i / 5) * Math.PI * 2; part(this.plant, GEO.sphLo, MAT.petal, Math.cos(a) * this.width * 0.26, h * 0.93, Math.sin(a) * this.width * 0.16, 0.09, 0.03, 0.07); } part(this.plant, GEO.sphLo, MAT.leaf, -0.2, h * 0.25, 0.05, 0.24, 0.05, 0.13, 0, 0, 0.4); part(this.plant, GEO.sphLo, MAT.leaf, 0.2, h * 0.4, 0.05, 0.24, 0.05, 0.13, 0, 0, -0.4); } else { part(this.plant, GEO.cyl, MAT.leafDark, 0, h * 0.55, 0, 0.07, h * 1.1, 0.07); for (let i = 0; i < 5; i++) { const a = (i / 5) * Math.PI * 2; part(this.plant, GEO.sphLo, i % 2 ? MAT.leaf : MAT.leafBright, Math.cos(a) * 0.22, h * (0.25 + i * 0.15), Math.sin(a) * 0.08, this.width * 0.3, 0.06, 0.16, 0, 0, Math.cos(a) * 0.3); } part(this.plant, GEO.hemi, MAT.leafDark, 0, h * 0.98, 0, this.width * 0.48, 0.13, 0.3); } this.plant.scale.set(0.02, 0.02, 0.02); this.view.add(this.plant); this.grow = rainOn(this) ? 1 : 0; this.apply(); } onRemoved(): void { this.game.physics.remove(this.col); } update(dt: number): void { const on = rainOn(this); const target = on ? 1 : 0; if (this.grow !== target) { const step = dt * (on ? 2.1 : 2.8); this.grow += Math.sign(target - this.grow) * Math.min(Math.abs(target - this.grow), step); this.apply(); } } private apply(): void { const e = 0.02 + 0.98 * this.grow; this.plant.scale.set(0.7 + 0.3 * this.grow, e, 0.7 + 0.3 * this.grow); this.col.enabled = this.grow > 0.7; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.plant.rotation.z = Math.sin(this.game.time * 1.3 + this.x) * 0.035; } } // ───────────────────────────── Lluvia: poza seca ───────────────────────────── /** Poza con balsa flotante: la lluvia sube el nivel y la balsa. */ export class DryPond extends Entity { private readonly floorY: number; private readonly surfaceY: number; private readonly width: number; private readonly flag: string; private readonly water = new THREE.Group(); private raft!: Collider; private level = 0; private filled = false; private vfxT = 0; constructor(props: Props) { super(); this.floorY = Number(props.floor ?? -5.8); this.surfaceY = Number(props.surface ?? -0.1); this.width = Number(props.w ?? 7.6); this.flag = String(props.flag ?? 'forest.pond'); this.tags.add('platform'); } onAdded(): void { const g = this.game; // agua contenida en la poza (visual y Γ‘rea de agua real) const h = Math.max(0.1, this.surfaceY - this.floorY); part(this.water, GEO.box, MAT.water, 0, h / 2, 0, this.width, h, 2.4); this.water.position.y = this.floorY; this.view.add(this.water); // balsa const raftMesh = new THREE.Group(); part(raftMesh, GEO.box, MAT.plank, 0, 0, 0, 3.6, 0.22, 1.9); for (const x of [-1.3, 0, 1.3]) part(raftMesh, GEO.cyl, MAT.darkWood, x, 0.16, 0, 0.08, 0.9, 0.08, Math.PI / 2); this.view.add(raftMesh); this.raft = g.physics.box(this.x, this.y + this.floorY + 0.3, 3.6, 0.24, { oneWay: true, material: 'wood', owner: this, tag: 'raft', vx: 0, vy: 0, }); this.raftMesh = raftMesh; this.filled = g.state.has(this.flag); this.level = this.filled ? 1 : 0; if (this.filled) { const area = g.physics.addArea({ kind: 'water', x: this.x, y: this.y + (this.floorY + this.surfaceY) / 2, hw: this.width / 2, hh: (this.surfaceY - this.floorY) / 2, data: { swim: false } }); void area; } this.applyLevel(0); } private raftMesh!: THREE.Group; onRemoved(): void { this.game.physics.remove(this.raft); } update(dt: number): void { const h = this.game.hero; const near = !!h && Math.abs(h.x - this.x) < 12; if (!this.filled && near && rainOn(this)) { this.level = Math.min(1, this.level + dt / 2.6); if (this.level >= 1) { this.filled = true; this.game.state.set(this.flag, true); this.game.state.save(); this.game.ui.toast('Β‘La poza se ha llenado! La balsa flota', 'πŸ’§'); this.game.audio.sfx('splash', { pitch: 0.9, volume: 0.7, x: this.x }); this.game.vfx.burst('splash', this.x, this.y + this.surfaceY, { count: 24, scale: 1.4, color: 0x7fd0ff }); } this.applyLevel(dt); } this.vfxT -= dt; if (this.level > 0 && this.level < 1 && this.vfxT <= 0) { this.vfxT = 0.22; this.game.vfx.trail('splash', this.x + (Math.random() - 0.5) * this.width * 0.7, this.y + this.floorY + (this.surfaceY - this.floorY) * this.level + 0.1, { scale: 0.5 }); } } private applyLevel(dt: number): void { const surf = this.floorY + (this.surfaceY - this.floorY) * this.level; const h = Math.max(0.02, surf - this.floorY); this.water.scale.y = h / Math.max(0.1, this.surfaceY - this.floorY); const ry = this.y + surf + 0.2; if (dt > 0) this.raft.vy = (ry - this.raft.y) / dt; this.raft.y = ry; this.raftMesh.position.y = surf + 0.02; this.water.visible = this.level > 0.02; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.raftMesh.rotation.z = Math.sin(this.game.time * 1.4 + this.x) * 0.025; } } // ───────────────────────────── Lava enfriada por lluvia ───────────────────────────── interface LavaProps extends Props { hazard: Area; lava: Area; w: number; flag: string; } /** * Tramo de lava: mientras LLUEVE cerca se enfrΓ­a y TODA la balsa se convierte en roca pisable * (la costra crece desde la superficie hasta el fondo). Al dejar de llover, tras un respiro, * las grietas se encienden y vuelve a ser lava activa: hay que cruzar con la lluvia puesta. */ const crustRock = kitMat('lavaCrustRock', { color: 0x5e4f55, gloss: 0.18, rim: 0.3 }); const crustTop = kitMat('lavaCrustTop', { color: 0x6e5e62, gloss: 0.22, rim: 0.35 }); const crustStone = kitMat('lavaCrustStone', { color: 0x4a3d43, gloss: 0.15, rim: 0.3 }); const crustGlow = kitMat('lavaCrustGlow', { color: 0xffb347, emissive: 0xff5a10, emissiveIntensity: 0.9, gloss: 0.6 }); export class LavaCrossing extends Entity { private readonly o: LavaProps; private crust!: Collider; private readonly rock = new THREE.Group(); private readonly slab = new THREE.Group(); private readonly cracks = new THREE.Group(); private progress = 0; private solid = false; private dryT = 0; private pvT = 0; private top = 0; private depth = 2; constructor(props: LavaProps) { super(); this.o = props; this.tags.add('lava-crossing'); } onAdded(): void { const g = this.game; const lv = this.o.lava; this.top = lv.y + lv.hh; this.depth = lv.hh * 2; this.crust = g.physics.box(lv.x, this.top - 0.18, lv.hw * 2, 0.7, { material: 'stone', tag: 'lava-crust', owner: this, enabled: false, }); // bloque de roca del tamaΓ±o de TODA la balsa (ancho, fondo y profundidad de la lava) const view = lv.data?.view as THREE.Object3D | undefined; const box = view ? new THREE.Box3().setFromObject(view) : null; const zf = box && Number.isFinite(box.max.z) ? box.max.z + 0.03 : 1.5; const zb = box && Number.isFinite(box.min.z) ? box.min.z - 0.03 : -3; const w = lv.hw * 2 + 0.04; const zc = (zf + zb) / 2; const zd = zf - zb; part(this.slab, GEO.box, crustRock, 0, -0.5, 0, w, 1, zd); // piedras de basalto incrustadas en la cara frontal (textura de roca, no una caja lisa) for (let i = 0; i < Math.round(w * 1.6); i++) { const sx = -w / 2 + 0.3 + ((i * 0.618) % 1) * (w - 0.6); const sy = -0.12 - ((i * 0.377) % 1) * 0.8; const s = 0.22 + ((i * 0.53) % 1) * 0.3; part(this.slab, GEO.box, i % 3 ? crustStone : crustTop, sx, sy, zd / 2, s, 0.11, 0.08); } this.slab.position.set(0, 0.1, zc); this.rock.add(this.slab); // superficie: losas irregulares de basalto + grietas que brillan al recalentarse const n = Math.max(3, Math.round(w / 1.6)); for (let i = 0; i < n; i++) { const px = -w / 2 + (i + 0.5) * (w / n); part(this.rock, GEO.box, crustTop, px, 0.12 + ((i * 37) % 5) * 0.012, zc, w / n - 0.06, 0.1, zd - 0.06); if (i < n - 1) part(this.cracks, GEO.box, crustGlow, px + w / n / 2, 0.13, zc, 0.07, 0.1, zd - 0.1); } this.rock.add(this.cracks); this.rock.position.set(lv.x - this.x, this.top - this.y, 0); this.rock.visible = false; this.view.add(this.rock); this.apply(); } onRemoved(): void { this.game.physics.remove(this.crust); } update(dt: number): void { const g = this.game; const h = g.hero; const lv = this.o.lava; // llueve sobre la balsa: interruptor de lluvia con el hΓ©roe cerca, o una sala con lluvia const near = (rainOn(this) && !!h && Math.abs(h.x - lv.x) < lv.hw + 9 && Math.abs(h.y - this.top) < 10) || isRainingAt(g, lv.x, this.top + 1); if (near) { this.dryT = 0; if (this.progress < 1) { this.progress = Math.min(1, this.progress + dt / 1.8); this.pvT -= dt; if (this.pvT <= 0) { this.pvT = 0.16; g.vfx.trail('smoke', lv.x + (Math.random() - 0.5) * lv.hw * 2, this.top + 0.15, { scale: 0.75, color: 0xd8e0e8 }); } if (this.progress >= 1 && !g.state.has(this.o.flag)) { g.state.set(this.o.flag, true); g.ui.toast('Β‘La lluvia endurece la lava! Cruza mientras siga lloviendo', '🌧️'); } } } else if (this.progress > 0) { // sin lluvia: aguanta un poco y vuelve a fundirse this.dryT += dt; if (this.dryT > 2.5) { this.progress = Math.max(0, this.progress - dt / 2.6); if (Math.random() < dt * 6) g.vfx.trail('fire', lv.x + (Math.random() - 0.5) * lv.hw * 2, this.top + 0.1, { scale: 0.5 }); } } this.apply(); } private apply(): void { const k = this.progress; this.rock.visible = k > 0.01; // la costra crece desde arriba hasta llenar toda la balsa const th = Math.max(0.12, Math.min(1, k * 1.15) * this.depth); this.slab.scale.y = th; // grietas: incandescentes al formarse y al volver a fundirse const glow = k < 0.85 || this.dryT > 2.5; this.cracks.visible = glow; const solid = k > 0.82; if (solid !== this.solid) { this.solid = solid; if (!solid && this.game.hero) this.game.audio.sfx('fire', { volume: 0.4, x: this.x }); } this.crust.enabled = solid; this.o.hazard.enabled = !solid; this.o.lava.enabled = !solid; } } // ───────────────────────────── Roca agrietada (FURIA) ───────────────────────────── interface RockProps extends Props { w: number; h: number; flag: string; hp?: number; /** BotΓ­n escondido dentro: 'coins:N', 'diamond:', 'heartbox:' separados por comas. */ loot?: string; } export class CrackedRock extends Entity { private readonly o: RockProps; private col!: Collider; private readonly rock = new THREE.Group(); private hits = 0; private warnT = 0; constructor(props: RockProps) { super(); this.o = props; } onAdded(): void { const g = this.game; for (const it of (this.o.loot ?? '').split(',').filter(Boolean)) { const [k, a] = it.split(':'); if (k === 'coins') tallyAdd(g, 'c', Number(a) || 1); else if (k === 'diamond') tallyAdd(g, 'd', 1); } if (g.state.has(this.o.flag)) { this.dead = true; return; } this.col = g.physics.box(this.x, this.y + this.o.h / 2, this.o.w, this.o.h, { material: 'stone', tag: 'cracked-rock', owner: this, }); const n = 4; for (let i = 0; i < n; i++) { const px = (i % 2 ? 0.45 : -0.4) * this.o.w * 0.5; const py = this.o.h * (0.2 + (i / n) * 0.6); part(this.rock, P.rock(i), MAT.rock, px, py, -0.4 + (i % 2) * 0.5, this.o.w * 0.42, this.o.h * 0.34, 1.25, 0.2 * i, i * 0.8, 0.1 * i); } for (let i = 0; i < 5; i++) { part(this.rock, GEO.box, MAT.crack, -0.2 + i * 0.25, this.o.h * 0.35 + (i % 2) * 0.5, 1.05, 0.05, this.o.h * 0.35, 0.05, 0, 0, 0.5 - i * 0.2); } this.view.add(this.rock); } onRemoved(): void { if (this.col) this.game.physics.remove(this.col); } bounds() { return { x: this.x, y: this.y + this.o.h / 2, hw: this.o.w / 2, hh: this.o.h / 2 }; } takeHit(hit: Hit): boolean { if (hit.element !== 'fury') { if (this.warnT <= 0) { this.warnT = 1.2; warn(this, 'Solo la FURIA rompe esta roca 😑', '#ffb0a0'); this.game.audio.sfx('bounce', { pitch: 1.2, volume: 0.4, x: this.x }); } return true; } this.hits++; this.game.gfx.cam.shake(0.25, 0.18); this.game.audio.sfx('shatter', { x: this.x, volume: 0.7 }); this.game.vfx.burst('dust', this.x, this.y + this.o.h * 0.5, { count: 16, scale: 1.5, color: 0xa89888 }); this.game.vfx.burst('shatter', this.x, this.y + this.o.h * 0.5, { count: 8, color: 0x9a9aa8 }); this.rock.position.x = (Math.random() - 0.5) * 0.16; if (this.hits >= (this.o.hp ?? 2)) this.break(); return true; } private break(): void { this.col.enabled = false; this.game.state.set(this.o.flag, true); this.game.state.save(); this.rock.visible = false; this.game.vfx.burst('shatter', this.x, this.y + this.o.h * 0.5, { count: 22, scale: 1.6, color: 0x9a9aa8 }); this.game.vfx.burst('dust', this.x, this.y + 0.6, { count: 24, scale: 1.6, color: 0xa89888 }); this.game.audio.sfx('shatter', { x: this.x, volume: 0.8 }); this.game.ui.toast('Β‘La roca se ha partido!', 'πŸ’₯'); // lo que escondΓ­a dentro sale despedido const g = this.game; let i = 0; for (const it of (this.o.loot ?? '').split(',').filter(Boolean)) { const [k, a] = it.split(':'); const pop = (type: string, p: Props) => { const n = i++; g.after(0.15 + n * 0.06, () => g.spawn(type, this.x, this.y + 0.6, { pop: true, tally: true, vx: (n % 2 ? 1 : -1) * (1 + (n % 3)), ...p })); }; if (k === 'coins') for (let c = 0; c < (Number(a) || 1); c++) pop('item.coin', {}); else if (k === 'diamond') pop('item.diamond', { id: a }); else if (k === 'heartbox') pop('item.heartbox', { id: a }); } this.kill(); } update(dt: number): void { this.warnT = Math.max(0, this.warnT - dt); this.rock.position.x *= 0.85; } } // ───────────────────────────── Zarzas y telaraΓ±as (FUEGO) ───────────────────────────── interface BurnProps extends Props { w: number; h: number; kind: 'bramble' | 'web'; flag: string; } export class Burnable extends Entity { private readonly o: BurnProps; private col!: Collider; private readonly art = new THREE.Group(); private warnT = 0; private burned = false; private burnT = 0; constructor(props: BurnProps) { super(); this.o = props; } onAdded(): void { const g = this.game; if (g.state.has(this.o.flag)) { this.dead = true; return; } this.col = g.physics.box(this.x, this.y + this.o.h / 2, this.o.w, this.o.h, { material: this.o.kind === 'web' ? 'cloud' : 'wood', tag: 'burnable', owner: this, }); { for (let i = 0; i < 7; i++) { const px = -this.o.w / 2 + (i / 6) * this.o.w; part(this.art, GEO.cyl, i % 2 ? MAT.wood : MAT.leafDark, px, this.o.h * 0.45, 0, 0.07, this.o.h * 0.9, 0.07, 0, 0, (i - 3) * 0.12); part(this.art, GEO.cone, MAT.leafDark, px + 0.15, this.o.h * (0.35 + (i % 3) * 0.2), 0.2, 0.12, 0.25, 0.12, 0, 0, 0.7); } } this.view.add(this.art); } onRemoved(): void { if (this.col) this.game.physics.remove(this.col); } bounds() { return { x: this.x, y: this.y + this.o.h / 2, hw: this.o.w / 2, hh: this.o.h / 2 }; } takeHit(hit: Hit): boolean { if (this.burned) return false; if (hit.element !== 'fire') { if (this.warnT <= 0) { this.warnT = 1.2; warn(this, 'Los matorrales espinosos solo se queman con FUEGO πŸ”₯', '#ffc2a0'); } return true; } this.burned = true; this.burnT = 0.85; this.col.enabled = false; this.game.vfx.burst('fire', this.x, this.y + this.o.h * 0.5, { count: 18, scale: 1.3 }); this.game.audio.sfx('fire', { x: this.x, volume: 0.8 }); this.game.ui.toast('Β‘Los matorrales espinosos arden!', 'πŸ”₯'); return true; } update(dt: number): void { this.warnT = Math.max(0, this.warnT - dt); if (!this.burned) return; this.burnT -= dt; const k = Math.max(0, this.burnT / 0.85); this.art.scale.set(0.82 + k * 0.18, k, 0.82 + k * 0.18); if (Math.random() < 0.2) this.game.vfx.burst('smoke', this.x + (Math.random() - 0.5) * this.o.w * 0.5, this.y + this.o.h * 0.45, { count: 2, scale: 0.45, color: 0x6f6255 }); if (this.burnT <= 0) { this.game.state.set(this.o.flag, true); this.game.state.save(); this.art.visible = false; this.game.vfx.burst('smoke', this.x, this.y + 0.3, { count: 10, scale: 0.8, color: 0x70685e }); this.game.vfx.burst('dust', this.x, this.y + 0.1, { count: 12, scale: 0.8, color: 0x493b35 }); this.kill(); } } } // ───────────────────────────── Antorchas e interruptores de fuego ───────────────────────────── interface TorchProps extends Props { id: string; group?: string; } export class Torch extends Entity { private readonly o: TorchProps; private readonly flame = new THREE.Group(); private light: PooledLight | null = null; private lit = false; constructor(props: TorchProps) { super(); this.o = props; this.team = 'neutral'; } onAdded(): void { part(this.view, GEO.cyl, MAT.darkWood, 0, 0.75, 0, 0.09, 1.5, 0.09); part(this.view, GEO.cyl, MAT.metal, 0, 1.5, 0, 0.24, 0.18, 0.24); part(this.flame, GEO.cone, MAT.flame, 0, 0.26, 0.02, 0.18, 0.5, 0.18); part(this.flame, GEO.sph, MAT.flameCore, 0, 0.18, 0.02, 0.11, 0.16, 0.11); this.flame.position.y = 1.58; this.flame.visible = false; this.view.add(this.flame); this.lit = this.game.state.has(`forest.torch.${this.o.id}`); this.apply(); } bounds() { return { x: this.x, y: this.y + 1.1, hw: 0.55, hh: 1.1 }; } takeHit(hit: Hit): boolean { if (hit.element !== 'fire') return false; this.light_(); return true; } private light_(): void { if (this.lit) return; this.lit = true; this.game.state.set(`forest.torch.${this.o.id}`, true); this.game.state.save(); this.apply(); this.game.vfx.burst('fire', this.x, this.y + 1.7, { count: 14, scale: 1.1 }); this.game.audio.sfx('fire', { pitch: 1.2, x: this.x, volume: 0.7 }); this.game.ui.toast('Β‘Antorcha encendida!', 'πŸ”₯'); } private apply(): void { this.flame.visible = this.lit; if (this.lit && !this.light) { this.light = new PooledLight(0xffb040, 1.15, 7, 1.8); this.light.position.set(0, 1.7, 0.5); this.view.add(this.light); } if (this.light) this.light.visible = this.lit; } render(alpha: number, dt: number): void { super.render(alpha, dt); if (!this.lit) return; const s = 1 + Math.sin(this.game.time * 9 + this.x) * 0.08; this.flame.scale.set(1 / Math.sqrt(s), s, 1); } } interface FsProps extends Props { id: string; group?: string; } /** Interruptor que se enciende con una bola de fuego (rebota en burbujas). */ export class FireSwitch extends Entity { private readonly o: FsProps; private lit = false; private readonly ring: THREE.Mesh; private readonly core: THREE.Mesh; constructor(props: FsProps) { super(); this.o = props; this.team = 'neutral'; this.ring = new THREE.Mesh(GEO.torus, MAT.metal as unknown as THREE.Material); this.core = new THREE.Mesh(GEO.sph, MAT.cool as unknown as THREE.Material); } onAdded(): void { part(this.view, GEO.cyl, MAT.metal, 0, 0.3, 0, 0.22, 0.6, 0.22); this.ring.scale.setScalar(0.44); this.ring.position.y = 0.85; this.ring.rotation.x = Math.PI / 2; this.core.scale.setScalar(0.22); this.core.position.y = 0.85; this.view.add(this.ring, this.core); this.lit = this.game.state.has(`forest.fireswitch.${this.o.id}`); this.apply(); } bounds() { return { x: this.x, y: this.y + 0.9, hw: 0.6, hh: 0.75 }; } takeHit(hit: Hit): boolean { if (hit.element !== 'fire') return false; if (this.lit) return true; this.lit = true; this.game.state.set(`forest.fireswitch.${this.o.id}`, true); this.game.state.save(); this.apply(); this.game.vfx.burst('fire', this.x, this.y + 0.9, { count: 18, scale: 1.2 }); this.game.vfx.ring(this.x, this.y + 0.9, 0xffb040, 1.2); this.game.audio.sfx('powerup', { pitch: 1.4, volume: 0.6, x: this.x }); this.game.ui.toast('Β‘Brasero encendido!', 'πŸ”₯'); return true; } private apply(): void { this.core.scale.setScalar(this.lit ? 0.3 : 0.22); this.ring.rotation.x = Math.PI / 2; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.ring.rotation.z += dt * (this.lit ? 2.2 : 0.5); this.core.position.y = 0.85 + Math.sin(this.game.time * 2.2 + this.x) * 0.04; } } // ───────────────────────────── Flor (agua) ───────────────────────────── export class FlowerSwitch extends Entity { private readonly flowerId: string; private bloomed = false; private readonly bud = new THREE.Group(); private readonly petals: THREE.Mesh[] = []; private readonly center: THREE.Mesh; constructor(props: Props) { super(); this.flowerId = String(props.id ?? 'flor'); this.team = 'neutral'; this.center = new THREE.Mesh(GEO.sph, MAT.gold as unknown as THREE.Material); } onAdded(): void { part(this.view, GEO.cyl, MAT.leafDark, 0, 0.5, 0, 0.1, 1.0, 0.1); part(this.view, GEO.sphLo, MAT.leaf, 0.22, 0.45, 0.05, 0.3, 0.06, 0.16, 0, 0, -0.4); part(this.view, GEO.sphLo, MAT.leaf, -0.2, 0.65, 0.05, 0.26, 0.05, 0.14, 0, 0, 0.4); for (let i = 0; i < 7; i++) { const a = (i / 7) * Math.PI * 2; const p = new THREE.Mesh(GEO.sphLo, MAT.petal); p.position.set(Math.cos(a) * 0.2, 1.16, Math.sin(a) * 0.1); p.scale.set(0.18, 0.07, 0.12); p.rotation.z = Math.cos(a) * 0.6; this.petals.push(p); this.bud.add(p); } this.center.scale.setScalar(0.14); this.center.position.y = 1.18; this.bud.add(this.center); this.view.add(this.bud); this.bloomed = this.game.state.has(`forest.flower.${this.flowerId}`); this.apply(); } bounds() { return { x: this.x, y: this.y + 1.05, hw: 0.6, hh: 0.8 }; } takeHit(hit: Hit): boolean { if (hit.element !== 'water') { warn(this, 'Necesita agua para florecer πŸ’§', '#bfeaff'); return true; } if (this.bloomed) return true; this.bloomed = true; this.game.state.set(`forest.flower.${this.flowerId}`, true); this.game.state.save(); this.apply(); this.game.vfx.burst('sparkle', this.x, this.y + 1.2, { count: 18, scale: 1.2, color: 0xffaad8 }); this.game.vfx.burst('splash', this.x, this.y + 1.1, { count: 10, scale: 0.9 }); this.game.audio.sfx('splash', { pitch: 1.4, volume: 0.6, x: this.x }); this.game.ui.toast('Β‘La flor ha florecido!', '🌸'); return true; } private apply(): void { const k = this.bloomed ? 1 : 0.42; for (let i = 0; i < this.petals.length; i++) { const a = (i / this.petals.length) * Math.PI * 2; this.petals[i].position.set(Math.cos(a) * 0.2 * k, 1.16 + (this.bloomed ? 0.03 : -0.08), Math.sin(a) * 0.1 * k); this.petals[i].scale.set(0.18, this.bloomed ? 0.08 : 0.05, this.bloomed ? 0.14 : 0.09); } this.center.visible = this.bloomed; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.bud.rotation.y = Math.sin(this.game.time * 0.9 + this.x) * 0.12; } } // ───────────────────────────── Cristal COOL ───────────────────────────── interface CoolProps extends Props { id: string; group?: string; } export class CoolSwitch extends Entity { private readonly o: CoolProps; private on = false; private offEvent: (() => void) | null = null; private readonly crystal: THREE.Mesh; private readonly halo: THREE.Mesh; constructor(props: CoolProps) { super(); this.o = props; this.team = 'neutral'; this.crystal = new THREE.Mesh(GEO.octa, MAT.cool as unknown as THREE.Material); this.halo = new THREE.Mesh(GEO.torus, MAT.cool as unknown as THREE.Material); } onAdded(): void { part(this.view, GEO.cyl, MAT.stone, 0, 0.25, 0, 0.3, 0.5, 0.3); this.crystal.scale.set(0.3, 0.55, 0.3); this.crystal.position.y = 0.95; this.halo.scale.setScalar(0.55); this.halo.rotation.x = Math.PI / 2; this.halo.position.y = 0.75; this.view.add(this.crystal, this.halo); this.on = this.game.state.has(`forest.cool.${this.o.id}`); this.apply(); this.offEvent = this.game.events.on('hero:coolwave', (e) => { if (this.on) return; const dx = this.x - e.x, dy = this.y + 0.9 - e.y; if (dx * dx + dy * dy > (e.radius + 0.6) * (e.radius + 0.6)) return; this.activate(); }); } onRemoved(): void { this.offEvent?.(); this.offEvent = null; } bounds() { return { x: this.x, y: this.y + 0.8, hw: 0.55, hh: 0.9 }; } takeHit(hit: Hit): boolean { if (hit.element === 'cool') { this.activate(); return true; } return false; } private activate(): void { if (this.on) return; this.on = true; this.game.state.set(`forest.cool.${this.o.id}`, true); this.game.state.save(); this.apply(); this.game.vfx.ring(this.x, this.y + 0.9, 0x7fd8ff, 1.4); this.game.vfx.burst('sparkle', this.x, this.y + 0.9, { count: 16, color: 0x9fe8ff }); this.game.audio.sfx('cool', { volume: 0.6, pitch: 1.3, x: this.x }); this.game.ui.toast('Β‘Cristal COOL activado!', '😎'); } private apply(): void { this.crystal.material = this.on ? MAT.coolOn : MAT.cool; this.halo.material = this.on ? MAT.coolOn : MAT.cool; } render(alpha: number, dt: number): void { super.render(alpha, dt); this.crystal.rotation.y += dt * (this.on ? 1.6 : 0.5); this.halo.rotation.z += dt * (this.on ? 1.1 : 0.3); } } // ───────────────────────────── Secretos de HIELO ───────────────────────────── interface IceProps extends Props { kind: 'waterfall' | 'block'; id: string; flag: string; w?: number; h?: number; } export class IceSecret extends Entity { private readonly o: IceProps; private col: Collider | null = null; private readonly art = new THREE.Group(); private readonly slabs: Collider[] = []; private open = false; private warnT = 0; constructor(props: IceProps) { super(); this.o = props; this.team = 'neutral'; } onAdded(): void { const g = this.game; this.open = g.state.has(this.o.flag); if (this.o.kind === 'waterfall') { // 3 repisas de hielo para subir la cascada (solo aparecen al congelarla) for (let i = 0; i < 3; i++) { const y = this.y + 2.2 + i * 1.8; const x = this.x + (i % 2 ? 0.9 : -0.9); const c = g.physics.box(x, y - 0.15, 1.7, 0.3, { oneWay: true, material: 'ice', tag: 'ice-step', owner: this, enabled: false, }); this.slabs.push(c); const m = part(this.art, GEO.box, MAT.ice, x - this.x, y - this.y, 0, 1.7, 0.35, 1.5); m.castShadow = false; part(this.art, GEO.cone, MAT.ice, x - this.x, y - this.y - 0.3, 0, 0.2, 0.5, 0.2, Math.PI); } } else { const w = this.o.w ?? 2.2; const h = this.o.h ?? 3.2; this.col = g.physics.box(this.x, this.y + h / 2, w, h, { material: 'ice', tag: 'ice-secret', owner: this, }); const m = part(this.art, P.rbox(), MAT.iceSolid, 0, h / 2, 0, w, h, 2.0); m.castShadow = false; part(this.art, GEO.cyl, MAT.ice, -w * 0.22, h * 0.62, 1.05, 0.03, h * 0.4, 0.03, 0, 0, -0.4); part(this.art, GEO.sph, MAT.ice, 0.2, h * 0.35, 0.9, 0.12, 0.12, 0.12); } this.art.visible = !this.open; this.view.add(this.art); this.apply(); } onRemoved(): void { if (this.col) this.game.physics.remove(this.col); for (const c of this.slabs) this.game.physics.remove(c); } bounds() { const w = this.o.w ?? 2.2; return { x: this.x, y: this.y + (this.o.kind === 'waterfall' ? 3.4 : 1.6), hw: w / 2 + 0.3, hh: 1.9 }; } takeHit(hit: Hit): boolean { if (this.open) return false; if (hit.element !== 'ice') { if (this.warnT <= 0) { this.warnT = 1.4; warn(this, this.o.kind === 'waterfall' ? 'Solo el HIELO congela la cascada πŸ₯Ά' : 'Solo el HIELO rompe este bloque πŸ₯Ά', '#bfeaff'); } return true; } this.activate(); return true; } private activate(): void { if (this.open) return; this.open = true; this.game.state.set(this.o.flag, true); this.game.state.save(); if (this.col) this.col.enabled = false; for (const c of this.slabs) c.enabled = true; this.art.visible = this.o.kind === 'waterfall'; if (this.o.kind === 'block') this.art.visible = false; this.game.vfx.burst('shatter', this.x, this.y + 1.5, { count: 22, scale: 1.6, color: 0xbfeaff }); this.game.vfx.burst('ice', this.x, this.y + 1.5, { count: 18, scale: 1.4 }); this.game.audio.sfx('shatter', { x: this.x, volume: 0.8 }); this.game.ui.toast(this.o.kind === 'waterfall' ? 'Β‘La cascada se ha congelado! Sube por las repisas' : 'Β‘El hielo se ha roto!', 'πŸ₯Ά'); } private apply(): void { if (this.o.kind === 'waterfall') { for (const c of this.slabs) c.enabled = this.open; } else if (this.col) { this.col.enabled = !this.open; } } update(dt: number): void { this.warnT = Math.max(0, this.warnT - dt); } } interface DropProps extends Props { w: number; flag: string; } /** Repisa de gotas heladas: solo existe con LLUVIA + HIELO. */ export class FrozenDrop extends Entity { private readonly o: DropProps; private col!: Collider; private readonly art = new THREE.Group(); private on = false; private k = 0; constructor(props: DropProps) { super(); this.o = props; this.tags.add('platform'); } onAdded(): void { this.col = this.game.physics.box(this.x, this.y - 0.15, this.o.w, 0.3, { oneWay: true, material: 'ice', owner: this, tag: 'frozen-drop', enabled: false, }); part(this.art, GEO.box, MAT.ice, 0, 0, 0, this.o.w, 0.28, 1.5); part(this.art, GEO.cone, MAT.ice, -this.o.w * 0.3, -0.35, 0.4, 0.16, 0.6, 0.16, Math.PI); part(this.art, GEO.cone, MAT.ice, this.o.w * 0.25, -0.3, -0.3, 0.12, 0.45, 0.12, Math.PI); this.art.scale.setScalar(0.05); this.art.visible = false; this.view.add(this.art); } onRemoved(): void { this.game.physics.remove(this.col); } update(dt: number): void { const active = this.game.state.has(this.o.flag) && rainOn(this); if (active !== this.on) { this.on = active; this.col.enabled = active; if (active) { this.game.vfx.burst('ice', this.x, this.y, { count: 8, scale: 0.8 }); this.game.audio.sfx('freeze', { pitch: 1.4, volume: 0.4, x: this.x }); } } const target = this.on ? 1 : 0; if (this.k !== target) { this.k += Math.sign(target - this.k) * Math.min(Math.abs(target - this.k), dt * 3); const s = Math.max(0.03, this.k); this.art.scale.set(s, s, s); this.art.visible = this.k > 0.04; } } } // ───────────────────────────── Puerta del castillo ───────────────────────────── interface GateProps extends Props { w: number; h: number; flag: string; impacts?: number; } export class CastleGate extends Entity { private readonly o: GateProps; private col!: Collider; private readonly ice = new THREE.Group(); private readonly cracks: THREE.Mesh[] = []; private impacts = 0; private open = false; private warnT = 0; private meltT = 0; constructor(props: GateProps) { super(); this.o = props; this.team = 'neutral'; this.tags.add('meltable'); } onAdded(): void { const g = this.game; this.col = g.physics.box(this.x, this.y + this.o.h / 2, this.o.w, this.o.h, { material: 'ice', tag: 'castle-gate', owner: this, }); // Bloque grueso translΓΊcido (fondo + cara) con brillos estΓ‘ticos. const core = part(this.ice, P.rboxSoft(), MAT.iceSolid, 0, this.o.h / 2, 0, this.o.w, this.o.h, 3.2); core.castShadow = false; part(this.ice, GEO.box, MAT.ice, 0, this.o.h * 0.42, 1.64, this.o.w * 0.92, this.o.h * 0.84, 0.08); // vetas y burbujas internas for (let i = 0; i < 7; i++) { const px = (i % 2 ? 0.32 : -0.28) * this.o.w; const py = this.o.h * (0.16 + (i / 7) * 0.7); part(this.ice, GEO.sphLo, MAT.ice, px, py, 1.25, 0.12, 0.18, 0.06); } // brillos fijos (no parpadean) for (const [px, py, rz] of [[-0.28, 0.72, 0.5], [-0.16, 0.42, 0.45], [0.3, 0.56, -0.5]] as const) { part(this.ice, GEO.cyl, MAT.iceSolid, px * this.o.w, this.o.h * py, 1.7, 0.035, this.o.h * 0.28, 0.035, 0, 0, rz); } // grietas progresivas for (let i = 0; i < 6; i++) { const c = part(this.ice, GEO.box, MAT.iceSolid, -this.o.w * 0.34 + i * this.o.w * 0.13, this.o.h * (0.25 + (i % 3) * 0.2), 1.72, 0.05, this.o.h * 0.35, 0.03, 0, 0, 0.6 - i * 0.22); c.visible = false; this.cracks.push(c); } this.open = g.state.has(this.o.flag); if (this.open) { this.col.enabled = false; this.ice.visible = false; } this.view.add(this.ice); } onRemoved(): void { this.game.physics.remove(this.col); } bounds() { return { x: this.x, y: this.y + this.o.h / 2, hw: this.o.w / 2, hh: this.o.h / 2 }; } takeHit(hit: Hit): boolean { if (this.open) return false; if (hit.element === 'fire') { this.hitFire(hit); return true; } if (this.warnT <= 0) { this.warnT = 1.1; this.game.vfx.floatText('EstΓ‘ congelada… necesitas algo muy caliente', this.x, this.y + this.o.h * 0.75, '#bfeaff'); this.game.audio.sfx('bounce', { pitch: 0.8, volume: 0.7, x: this.x }); this.game.vfx.burst('ice', this.x, this.y + this.o.h * 0.55, { count: 6, scale: 0.8 }); const h = this.game.hero; if (h) { h.body.vx = (h.x < this.x ? -1 : 1) * 8; h.body.vy = Math.max(h.body.vy, 5.5); } } return true; } private hitFire(hit: Hit): void { this.impacts++; const px = hit.source?.x ?? this.x - this.o.w * 0.4; const py = hit.source?.y ?? this.y + this.o.h * 0.45; this.game.audio.sfx('fire', { x: px, volume: 0.8 }); this.game.vfx.burst('fire', px, py, { count: 14, scale: 1.2 }); this.game.vfx.burst('smoke', px, py, { count: 10, scale: 1.3 }); this.game.vfx.burst('splash', px, py, { count: 8, scale: 0.9, color: 0xbfeaff }); this.game.gfx.cam.shake(0.3, 0.25); const n = Math.min(this.cracks.length, this.impacts); for (let i = 0; i < n; i++) this.cracks[i].visible = true; if (this.impacts === 1) this.game.ui.toast('La puerta empieza a agrietarse… Β‘sigue con FUEGO!', 'πŸ”₯'); if (this.impacts >= (this.o.impacts ?? 4)) this.melt(); } private melt(): void { if (this.open) return; this.open = true; this.meltT = 1.4; this.col.enabled = false; this.game.state.set(this.o.flag, true); this.game.state.save(); this.game.audio.sfx('shatter', { x: this.x, volume: 0.9 }); this.game.audio.sfx('victory', { volume: 0.8 }); this.game.vfx.burst('splash', this.x, this.y + 1, { count: 30, scale: 1.6, color: 0xbfeaff }); this.game.vfx.burst('smoke', this.x, this.y + 1.4, { count: 30, scale: 1.8 }); this.game.vfx.burst('confetti', this.x, this.y + 1.2, { count: 26 }); this.game.ui.banner('Β‘La puerta del castillo estΓ‘ abierta!', 'El hielo se ha derretido con FUEGO', 'πŸ”₯'); this.game.events.emit('castle:gate', { open: true }); this.game.ui.toast('Habla con el Rey FrΓ­o para activar los portales', '🏰'); } update(dt: number): void { this.warnT = Math.max(0, this.warnT - dt); if (this.meltT <= 0) return; this.meltT -= dt; if (Math.floor(this.meltT * 8) !== Math.floor((this.meltT + dt) * 8)) this.game.vfx.burst('smoke', this.x, this.y + this.o.h * 0.65, { count: 2, scale: 0.55, color: 0xdfe8f0 }); const k = Math.max(0, this.meltT / 1.4); this.ice.scale.set(1 + (1 - k) * 0.08, k, 1); this.ice.position.y = (1 - k) * -1.2; if (this.meltT <= 0) this.ice.visible = false; } } // ───────────────────────────── Molino ───────────────────────────── /** Molino de viento con aspas girando despacio (sin parpadeos). */ export class Windmill extends Entity { private readonly blades = new THREE.Group(); private readonly h: number; constructor(props: Props) { super(); this.h = Number(props.h ?? 4.6); this.team = 'neutral'; // decorado de fondo (detrΓ‘s de la casa de Anna): el hΓ©roe pasa POR DELANTE, nunca a travΓ©s de Γ©l this.z = -3.2; } onAdded(): void { part(this.view, GEO.cyl, MAT.plank, 0, this.h * 0.5, 0, 1.15, this.h, 1.15); part(this.view, GEO.cyl, MAT.darkWood, 0, this.h * 0.75, 0, 1.2, 0.16, 1.2); part(this.view, GEO.cone, MAT.danger, 0, this.h + 0.25, 0, 1.4, 0.7, 1.4); part(this.view, GEO.box, MAT.darkWood, 0, 0.55, 0.95, 0.55, 0.95, 0.12); this.blades.position.set(0, this.h * 0.78, 1.18); for (let i = 0; i < 4; i++) { const a = (i / 4) * Math.PI * 2; const arm = new THREE.Group(); arm.rotation.z = a; part(arm, GEO.box, MAT.plank, 0, 1.05, 0, 0.16, 1.7, 0.1); part(arm, GEO.box, MAT.iceSolid, 0, 1.55, 0.04, 0.5, 0.72, 0.05); this.blades.add(arm); } part(this.blades, GEO.sph, MAT.gold, 0, 0, 0.08, 0.16, 0.16, 0.12); this.view.add(this.blades); } render(alpha: number, dt: number): void { super.render(alpha, dt); this.blades.rotation.z -= dt * 0.55; } } /** Registra las piezas mecΓ‘nicas locales del tramo forestal. */ export function installForestKit(game: import('../../core/game').Game): void { game.register('forest.farm', (_g, _x, _y, p) => new FarmPatch(p)); game.register('forest.vine', (_g, _x, _y, p) => new RainVine(p)); game.register('forest.pond', (_g, _x, _y, p) => new DryPond(p)); game.register('forest.lava', (_g, _x, _y, p) => new LavaCrossing(p as LavaProps)); game.register('forest.rock', (_g, _x, _y, p) => new CrackedRock(p as RockProps)); game.register('forest.burnable', (_g, _x, _y, p) => new Burnable(p as BurnProps)); game.register('forest.torch', (_g, _x, _y, p) => new Torch(p as TorchProps)); game.register('forest.fireswitch', (_g, _x, _y, p) => new FireSwitch(p as FsProps)); game.register('forest.flower', (_g, _x, _y, p) => new FlowerSwitch(p)); game.register('forest.cool', (_g, _x, _y, p) => new CoolSwitch(p as CoolProps)); game.register('forest.ice', (_g, _x, _y, p) => new IceSecret(p as IceProps)); game.register('forest.drop', (_g, _x, _y, p) => new FrozenDrop(p as DropProps)); game.register('forest.gate', (_g, _x, _y, p) => new CastleGate(p as GateProps)); game.register('forest.windmill', (_g, _x, _y, p) => new Windmill(p)); }