/** * CUEVA CRISTAL πŸ•³οΈ * * x -4..34 A. Entrada y tutorial de linterna: tierra blanda, vagoneta, lΓ‘mparas colgantes. * x 34..88 B. TΓΊnel principal: abismo de agua oscura, plataformas, murciΓ©lagos y checkpoint. * x 88..142 C. Cuevas de araΓ±as: tres cΓ‘maras ascendentes, fuego, telaraΓ±as y secreto excavable. * x 142..176 D. Arena de la AraΓ±a Gigante: cierre temporal de muros y combate de tres fases. * x 176..208 E. Gruta de cristal: abismo de agua oscura que se cruza con burbujas. * x 208..244 F. Salida superior: escaleras de cristal, teletransporte y puerta a la ciudad. * * La zona es oscura; el PointLight Γ‘mbar sigue al hΓ©roe solo si lleva la LINTERNA. Las luces de * cristal son estΓ‘ticas y no parpadean. Todos los recursos repetidos se comparten. */ import * as THREE from 'three'; import { PooledLight } from '../../render/lightPool'; import type { Collider, EnvParams, GroundOpts, Props, ZoneContext, ZoneDef } from '../../core/types'; import type { Game } from '../../core/game'; import type { KitZoneContext } from '../kit/context'; import { vfxAmbient } from '../../vfx/index'; import { toonMaterial } from '../../render'; import { invisibleWall } from './shared'; import { Invasion } from './invasion'; import { isToolOn } from '../../core/slots'; import { DigGrid, wireDig } from '../dig'; // ───────────────────────────── Recursos compartidos ───────────────────────────── function shared(o: T): T { o.userData.shared = true; return o; } const GEO = { box: shared(new THREE.BoxGeometry(1, 1, 1)), cyl: shared(new THREE.CylinderGeometry(1, 1, 1, 12)), sphere: shared(new THREE.SphereGeometry(1, 18, 12)), cone: shared(new THREE.ConeGeometry(1, 1, 6)), plane: shared(new THREE.PlaneGeometry(1, 1)), }; const MAT = { rail: shared(toonMaterial({ color: 0x747095, gloss: 0.8, rim: 0.6 })), wood: shared(toonMaterial({ color: 0x7b4a36, gloss: 0.35, rim: 0.35 })), darkWood: shared(toonMaterial({ color: 0x4b2c32, gloss: 0.3, rim: 0.3 })), iron: shared(toonMaterial({ color: 0x3b3a58, gloss: 0.75, rim: 0.5 })), amber: shared(toonMaterial({ color: 0xffc928, emissive: 0xff9a1e, emissiveIntensity: 0.82, gloss: 1, rim: 1 })), amberSoft: shared(toonMaterial({ color: 0xffe5a3, emissive: 0xffb13a, emissiveIntensity: 0.38, gloss: 0.8, rim: 0.8 })), crystalCyan: shared(toonMaterial({ color: 0x6fe8ff, emissive: 0x2fc8ff, emissiveIntensity: 0.62, gloss: 1, rim: 1, transparent: true, opacity: 0.9 })), crystalViolet: shared(toonMaterial({ color: 0xb58cff, emissive: 0x804cff, emissiveIntensity: 0.52, gloss: 1, rim: 1, transparent: true, opacity: 0.9 })), rock: shared(toonMaterial({ color: 0x695182, gloss: 0.28, rim: 0.55 })), rockDark: shared(toonMaterial({ color: 0x3f2e5b, gloss: 0.22, rim: 0.45 })), flame: shared(toonMaterial({ color: 0xff9a2e, emissive: 0xff5a16, emissiveIntensity: 1.15, gloss: 0.7, rim: 1 })), ember: shared(toonMaterial({ color: 0xffc928, emissive: 0xff7a14, emissiveIntensity: 0.85, gloss: 0.9, rim: 1 })), web: shared(new THREE.MeshBasicMaterial({ color: 0xcfc6ff, transparent: true, opacity: 0.58, depthWrite: false, side: THREE.DoubleSide })), }; let webTex: THREE.Texture | null = null; function caveWebTexture(): THREE.Texture { if (webTex) return webTex; const n = 256; const c = document.createElement('canvas'); c.width = c.height = n; const g = c.getContext('2d')!; g.clearRect(0, 0, n, n); g.strokeStyle = 'rgba(232,225,255,0.92)'; g.lineWidth = 2.4; const cx = n / 2, cy = n / 2; for (let i = 0; i < 14; i++) { const a = (i / 14) * Math.PI * 2; g.beginPath(); g.moveTo(cx, cy); g.lineTo(cx + Math.cos(a) * n * 0.47, cy + Math.sin(a) * n * 0.47); g.stroke(); } for (let ring = 1; ring <= 5; ring++) { const r = (ring / 5) * n * 0.44; g.beginPath(); for (let i = 0; i <= 16; i++) { const a = (i / 16) * Math.PI * 2; const rr = r * (0.9 + ((i * 5 + ring * 7) % 4) * 0.03); const x = cx + Math.cos(a) * rr; const y = cy + Math.sin(a) * rr; if (i === 0) g.moveTo(x, y); else g.lineTo(x, y); } g.stroke(); } webTex = new THREE.CanvasTexture(c); webTex.colorSpace = THREE.SRGBColorSpace; webTex.userData.shared = true; return webTex; } function mesh(geo: THREE.BufferGeometry, mat: THREE.Material, x: number, y: number, z: number, sx: number, sy: number, sz: number, 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.z = rz; m.castShadow = true; m.receiveShadow = true; return m; } function addRails(z: ZoneContext, x0: number, x1: number, y: number): void { const len = x1 - x0; for (const dz of [-0.28, 0.28]) { z.group.add(mesh(GEO.box, MAT.rail, (x0 + x1) / 2, y + 0.08, dz, len, 0.06, 0.08)); } const n = Math.max(2, Math.floor(len / 0.72)); const ties = new THREE.InstancedMesh(GEO.box, MAT.darkWood, n); const dummy = new THREE.Object3D(); for (let i = 0; i < n; i++) { dummy.position.set(x0 + (i + 0.5) * (len / n), y + 0.04, 0); dummy.scale.set(0.15, 0.05, 0.84); dummy.updateMatrix(); ties.setMatrixAt(i, dummy.matrix); } ties.castShadow = true; ties.receiveShadow = true; z.group.add(ties); } function addMineCart(z: ZoneContext, x: number, y: number, facing = 1): void { const g = new THREE.Group(); g.position.set(x, y, 0.2); g.scale.x = facing; g.add(mesh(GEO.box, MAT.iron, 0, 0.35, 0, 0.78, 0.08, 0.68)); g.add(mesh(GEO.box, MAT.darkWood, 0, 0.56, 0, 0.76, 0.4, 0.62)); for (const sx of [-0.3, 0.3]) { for (const sz of [-0.25, 0.25]) { const wheel = mesh(GEO.cyl, MAT.rail, sx, 0.18, sz, 0.16, 0.06, 0.16, Math.PI / 2); wheel.rotation.x = Math.PI / 2; g.add(wheel); } } z.group.add(g); } function addHangingLantern(z: ZoneContext, x: number, top: number, bottom: number, withLight = false): void { const chainLen = Math.max(0.2, top - bottom); z.group.add(mesh(GEO.cyl, MAT.rail, x, bottom + chainLen / 2, -0.35, 0.025, chainLen, 0.025)); const cage = new THREE.Group(); cage.position.set(x, bottom, -0.35); cage.add(mesh(GEO.box, MAT.iron, 0, 0, 0, 0.34, 0.42, 0.34)); cage.add(mesh(GEO.box, MAT.amber, 0, 0, 0.18, 0.2, 0.28, 0.04)); cage.add(mesh(GEO.sphere, MAT.amberSoft, 0, 0, 0, 0.12, 0.12, 0.12)); z.group.add(cage); if (withLight) { const l = new PooledLight(0xffb84a, 1.35, 8.5, 1.9); l.position.set(x, bottom, 1.1); z.group.add(l); } } function addCeilingSpike(z: ZoneContext, x: number, top: number, len: number, scale = 1): void { z.group.add(mesh(GEO.cone, MAT.rockDark, x, top - len * 0.5, -0.8, 0.33 * scale, len, 0.33 * scale, Math.PI)); } function addWallWeb(z: ZoneContext, x: number, y: number, s: number, zz = -2.6): void { const mat = MAT.web.clone(); mat.map = caveWebTexture(); mat.needsUpdate = true; mat.userData.shared = false; const m = new THREE.Mesh(GEO.plane, mat); m.position.set(x, y, zz); m.scale.set(s, s, 1); m.rotation.z = (x * 0.17) % 1; m.renderOrder = 1; z.group.add(m); } function addFlameHazardVisual(z: ZoneContext, x: number, y: number, w: number): void { const n = Math.max(3, Math.round(w / 0.55)); for (let i = 0; i < n; i++) { const px = x - w / 2 + (i + 0.5) * (w / n); z.group.add(mesh(GEO.sphere, MAT.ember, px, y + 0.13, 0.25, 0.11, 0.1, 0.11)); z.group.add(mesh(GEO.cone, MAT.flame, px, y + 0.36, 0.25, 0.13, 0.42, 0.13)); } } function addCrystalLight(z: ZoneContext, x: number, y: number, color: number, intensity = 1.7): void { const l = new PooledLight(color, intensity, 13, 2); l.position.set(x, y, 2.2); z.group.add(l); } // ───────────────────────────── Estado de la zona ───────────────────────────── interface CaveRt { lit: boolean; grids: DigGrid[]; secretChestSpawned: boolean; leftWall: Collider; rightWall: Collider; arenaClosed: boolean; boss: { dead: boolean } | null; offDig: (() => void) | null; invasion: Invasion | null; } let rt: CaveRt | null = null; const ARENA = { x0: 143.5, x1: 174.5, floor: 9 }; const WATER_B = { x0: 38, x1: 68, surface: -3.5 }; const WATER_E = { x0: 182, x1: 208, surface: 8.5 }; function spawnSecretChest(g: Game): void { if (!rt || rt.secretChestSpawned) return; rt.secretChestSpawned = true; if (g.hasType('item.chest')) { g.spawn('item.chest', 139.4, 9, { id: 'cave-secret-1', contains: 'diamond' }); } } // ───────────────────────────── IluminaciΓ³n global de la cueva ───────────────────────────── /** Enciende o apaga la iluminaciΓ³n de toda la cueva como una habitaciΓ³n. */ function applyCaveLighting(g: Game, on: boolean, seconds: number): void { g.gfx.setEnv({ preset: 'cave', darkness: on ? 0.06 : 0.88, fogNear: on ? 13 : 5, fogFar: on ? 62 : 20, ambientIntensity: on ? 1.4 : 0.6, sunIntensity: on ? 1.9 : 0.5, sunColor: on ? 0xcfc4ff : 0x8a7aff, bloom: on ? 1.02 : 0.9, vignette: on ? 0.4 : 0.7, }, seconds); } // ───────────────────────────── Zona ───────────────────────────── export const caveZone: ZoneDef = { id: 'cave', name: 'Cueva Cristal', emoji: 'πŸ•³οΈ', bounds: { minX: -4, maxX: 268, minY: -12, maxY: 34 }, spawns: { default: { x: 3, y: 0 }, 'from-lagoon': { x: 3, y: 0 }, boss: { x: 146, y: 9 }, crystal: { x: 178, y: 9 }, exit: { x: 239, y: 16 }, 'tp-cave': { x: 220, y: 10 }, 'from-forest': { x: 3, y: 0 }, }, env: { preset: 'cave', darkness: 0.88, fogNear: 5, fogFar: 20, ambientIntensity: 0.6, sunIntensity: 0.5, bloom: 0.9 } as Partial, music: 'cave', build(z) { const k = z as KitZoneContext; const g = z.game; z.backdrop('cave', { horizon: -1.2 }); // Luz fija de la boca de la cueva: con la linterna apagada deja entrever el entorno. const entranceLight = new PooledLight(0xffd7a0, 1.9, 19, 1.9); entranceLight.position.set(7, 3.2, 3.2); z.group.add(entranceLight); const leftWall = g.physics.box(ARENA.x0 - 0.4, ARENA.floor + 8, 0.5, 16, { material: 'stone', tag: 'arena-wall' }); const rightWall = g.physics.box(ARENA.x1 + 0.4, ARENA.floor + 8, 0.5, 16, { material: 'stone', tag: 'arena-wall' }); leftWall.enabled = false; rightWall.enabled = false; rt = { lit: false, grids: [], secretChestSpawned: false, leftWall, rightWall, arenaClosed: false, boss: null, offDig: null, invasion: null, }; invisibleWall(g, -4.6, 0, 30); invisibleWall(g, 268.6, 0, 34); // ═════════ A. Entrada y tutorial de linterna (x -4..34) ═════════ // CΓ‘mara de tierra blanda sustituye el antiguo terraplΓ©n: el tΓΊnel inferior ya es transitable. z.ground(-4, 16, 0, { style: 'cave' }); z.ground(16, 19, -2, { style: 'cave', plain: true } as GroundOpts & { plain: boolean }); z.ground(19, 34, 0, { style: 'cave' }); // Boca interior: el claro de afuera entra tenue por la izquierda y se puede chocar para salir. const daylight = new PooledLight(0xffe2b0, 14, 22, 1.2); daylight.position.set(-1.2, 3.4, 2.4); z.group.add(daylight); const glow = new THREE.Mesh( new THREE.PlaneGeometry(2.4, 3.4), new THREE.MeshBasicMaterial({ color: 0xffd9a0, transparent: true, opacity: 0.55, depthWrite: false }), ); glow.position.set(-3.6, 2.2, -0.4); z.group.add(glow); z.prop('rock', -2.4, 0, { z: 1.35, scale: 1.5, color: 0x6a6278 }); z.prop('rock', -2.2, 2.8, { z: 0.4, scale: 1.2, color: 0x524868 }); z.exit(-3.2, 1.6, 1.2, 3.2, 'lagoon', 'cave-mouth', { arrow: 'left' }); addRails(z, 1.5, 29, 0); addMineCart(z, 9, 0, 1); addMineCart(z, 26, 0, -1); addHangingLantern(z, 5, 9.2, 6.3); addHangingLantern(z, 14, 10.0, 7.1, true); addHangingLantern(z, 25, 8.4, 5.4); z.prop('crystal', 7.2, 0, { z: -1.9, color: 0x65e0ff, scale: 0.85 }); z.prop('crystal', 22.5, 0, { z: -2.5, color: 0xa77bff, scale: 1.15 }); z.prop('mushroom', 11.5, 0, { z: -1.1, color: 0x9966ff, scale: 0.75 }); z.prop('mushroom', 24.7, 0, { z: -0.9, color: 0x65d7ff, scale: 0.58 }); z.prop('rock', 3.5, 0, { z: -2.1, scale: 1.2 }); z.prop('rock', 30.5, 0, { z: -2.6, scale: 1.6 }); addWallWeb(z, 17, 6.4, 2.3, -3.1); addCeilingSpike(z, 8, 13.5, 2.7, 1.2); addCeilingSpike(z, 29, 13.2, 2.1, 0.9); k.scatter('grassTuft', 1, 31, 0, 5, { z: 1.1, zJitter: 0.1 }); // Tierra blanda de la entrada: 3Γ—2 celdas sobre una cΓ‘mara a -2. const gridA = new DigGrid({ game: g, prefix: 'cave-a', x0: 16, y0: -2, cols: 3, rows: 2, top: 'cave', soil: 'cave', rewards: [{ i: 1, j: 0, kind: 'diamond', id: 'cave-diamond-1' }], }); rt.grids.push(gridA); z.prop('sign', 14.2, 0, { text: 'Tierra blanda: pulsa πŸͺ', z: 0.4 }); // ═════════ B. TΓΊnel principal con abismo (x 34..88) ═════════ z.ground(34, 38, 0, { style: 'cave' }); z.water(WATER_B.x0, WATER_B.x1, WATER_B.surface, 7.2, { color: 0x244078, deep: 0x08081c, foam: 0x7ad8ff, wave: 0.18, shoreL: true, shoreR: true, }); z.ground(WATER_B.x0, WATER_B.x1, -10, { style: 'cave', plain: true } as GroundOpts & { plain: boolean }); z.platform(42, 0.8, 4.2, { style: 'cave', thickness: 0.65 }); z.platform(49.5, 2.5, 3.7, { style: 'cave', thickness: 0.6, move: { dy: 0.7, period: 4.2 } }); z.platform(56.5, 3.9, 3.5, { style: 'cave', thickness: 0.55 }); z.platform(63.2, 2.1, 3.8, { style: 'cave', thickness: 0.62, move: { dx: 0.8, period: 3.4 } }); z.ground(68, 72, 0, { style: 'cave' }); z.ground(72, 75, -2, { style: 'cave', plain: true } as GroundOpts & { plain: boolean }); z.ground(75, 88, 0, { style: 'cave' }); for (const [x, len, s] of [[44, 2.9, 1.15], [56.5, 2.2, 0.9], [73.5, 2.6, 1.05], [83, 1.8, 0.72]] as const) { addCeilingSpike(z, x, 12.2, len, s); } addWallWeb(z, 52, 7.6, 3.3, -3.2); addWallWeb(z, 80, 6.8, 2.1, -2.9); addHangingLantern(z, 75.5, 8.8, 5.7, true); z.prop('stalagmite', 70.8, 0, { z: -1.9, scale: 1.15 }); z.prop('stalagmite', 85.5, 0, { z: -2.5, scale: 0.9 }); z.prop('crystal', 76.8, 0, { z: -2.2, color: 0x65e0ff, scale: 1.0 }); if (g.hasType('enemy.bat')) { g.spawn('enemy.bat', 46.5, 10.6, { range: 7 }); g.spawn('enemy.bat', 59.5, 11.5, { range: 7.5 }); g.spawn('enemy.bat', 74.5, 10.2, { range: 6.5 }); } // Tierra blanda junto al checkpoint: cava hacia abajo para encontrar la cΓ‘mara de monedas. const gridB = new DigGrid({ game: g, prefix: 'cave-b', x0: 72, y0: -2, cols: 3, rows: 2, top: 'cave', soil: 'cave', rewards: [ { i: 0, j: 0, kind: 'coin', n: 3 }, { i: 2, j: 0, kind: 'diamond', id: 'cave-diamond-2' }, ], }); rt.grids.push(gridB); z.prop('sign', 70, 0, { text: 'Cava aquΓ­ abajo', z: 0.4 }); g.spawn('item.checkpoint', 82, 0, { spawn: 'checkpoint-b' }); // ═════════ C. Cuevas de araΓ±as (x 88..142) ═════════ z.ground(88, 106, 0, { style: 'cave' }); z.platform(96.5, 4.2, 4.6, { style: 'cave', thickness: 0.6 }); z.platform(103.2, 2.4, 3.1, { style: 'cave', thickness: 0.55 }); z.ground(106, 124, 5, { style: 'cave' }); z.platform(121.3, 7.0, 3.1, { style: 'cave', thickness: 0.55 }); z.ground(124, 142, 9, { style: 'cave' }); addWallWeb(z, 91, 7.2, 3.5, -3.0); addWallWeb(z, 100, 8.5, 2.7, -2.8); addWallWeb(z, 109, 10.8, 3.2, -3.1); addWallWeb(z, 119, 11.5, 2.4, -2.8); addWallWeb(z, 130, 13.0, 3.1, -3.0); z.area('hazard', 96.3, 0.42, 3.0, 0.84, { visual: false, damage: 1, element: 'fire' }); addFlameHazardVisual(z, 96.3, 0, 3.0); z.area('hazard', 112.3, 5.42, 3.2, 0.84, { visual: false, damage: 1, element: 'fire' }); addFlameHazardVisual(z, 112.3, 5, 3.2); addHangingLantern(z, 99.5, 12, 8.0); addHangingLantern(z, 117.5, 15, 11.5); addCeilingSpike(z, 93, 13, 2.3, 0.95); addCeilingSpike(z, 115, 16.5, 2.8, 1.15); addCeilingSpike(z, 128, 18, 2.2, 0.9); z.prop('mushroom', 92.8, 0, { z: -0.8, color: 0xa455f0, scale: 0.7 }); z.prop('mushroom', 108.2, 5, { z: -1.0, color: 0x65d7ff, scale: 0.8 }); z.prop('crystal', 122.5, 5, { z: -2.1, color: 0xb58cff, scale: 1.1 }); z.spawn('item.diamond', 95.5, 5.4, { id: 'cave-diamond-4' }); z.spawn('item.heart', 97.5, 4.8); if (g.hasType('enemy.spider')) { g.spawn('enemy.spider', 93.5, 11.2, {}); g.spawn('enemy.spider', 101.5, 10.3, {}); g.spawn('enemy.spider', 109.5, 14.2, {}); g.spawn('enemy.spider', 117.5, 13.4, {}); } // Secreto: pared de tierra apisonada en una grieta de roca. Solo se abre cavando. if (!g.state.has('cave.secret-1')) { z.prop('rock', 133.2, 9, { z: -1.4, scale: 1.6 }); z.prop('rock', 137.4, 9, { z: -1.2, scale: 1.4 }); const gridC = new DigGrid({ game: g, prefix: 'cave-secret', x0: 134, y0: 9, cols: 2, rows: 3, top: 'none', soil: 'cave', onComplete: () => { g.state.set('cave.secret-1', true); spawnSecretChest(g); g.ui.toast('Β‘Pasaje secreto descubierto!', 'πŸ•³οΈ'); g.audio.sfx('chest', { volume: 0.55, x: 135.5 }); }, }); rt.grids.push(gridC); } else { spawnSecretChest(g); } // ═════════ D. Arena de la AraΓ±a Gigante (x 142..176) ═════════ z.ground(142, 176, 9, { style: 'cave' }); addWallWeb(z, 158, 16.5, 5.2, -3.2); addWallWeb(z, 151, 13.2, 2.8, -2.9); addWallWeb(z, 166, 13.8, 3.0, -3.0); z.prop('rock', 144.8, 9, { z: -2.3, scale: 1.8 }); z.prop('rock', 173.0, 9, { z: -2.3, scale: 1.6 }); z.prop('crystal', 146.2, 9, { z: -2.7, color: 0xa77bff, scale: 1.1 }); z.prop('crystal', 172.0, 9, { z: -2.7, color: 0x65e0ff, scale: 1.15 }); addHangingLantern(z, 147.5, 22, 17.3, true); addHangingLantern(z, 168.5, 22, 17.3, true); addCeilingSpike(z, 156, 23.5, 3.8, 1.7); g.spawn('item.checkpoint', 140.5, 9, { spawn: 'boss' }); if (g.state.has('spider.defeated')) { if (!g.state.has('emma.ring') && g.hasType('item.ring')) g.spawn('item.ring', 158, 9.15, { id: 'emma-ring' }); } else if (g.hasType('boss.spider')) { rt.boss = g.spawn('boss.spider', 158, 9, { arena: { ...ARENA } }) as { dead: boolean }; } // ═════════ E. Gruta de cristal (x 176..208) ═════════ z.ground(176, 182, 9, { style: 'cave' }); z.water(WATER_E.x0, WATER_E.x1, WATER_E.surface, 10, { color: 0x16295c, deep: 0x050414, foam: 0x6bdcff, wave: 0.22, shoreL: true, shoreR: true, }); z.ground(WATER_E.x0, WATER_E.x1, -1.5, { style: 'cave', plain: true } as GroundOpts & { plain: boolean }); z.ground(208, 224, 10, { style: 'cave' }); for (const [x, y, color] of [[181, 13, 0x6fe8ff], [195, 16.4, 0x9b7bff], [207.7, 13.5, 0x65e0ff]] as const) { addCrystalLight(z, x, y, color, 1.65); } z.prop('crystal', 179.5, 9, { z: -2.8, color: 0x6fe8ff, scale: 1.8 }); z.prop('crystal', 181.2, 9, { z: -3.4, color: 0x9b7bff, scale: 1.25 }); z.prop('crystal', 196, 6.0, { z: -4.5, color: 0x6fe8ff, scale: 2.8 }); z.prop('crystal', 202, 6.5, { z: -4.2, color: 0xb58cff, scale: 2.2 }); z.prop('crystal', 209.5, 10, { z: -2.6, color: 0x6fe8ff, scale: 1.6 }); z.prop('crystal', 216.5, 10, { z: -2.8, color: 0xb58cff, scale: 1.2 }); z.prop('mushroom', 210.5, 10, { z: -1.0, color: 0x65d7ff, scale: 0.8 }); addHangingLantern(z, 213.5, 18, 13.7); addCeilingSpike(z, 190, 23, 4.6, 1.8); addCeilingSpike(z, 203, 22, 3.5, 1.4); z.spawn('item.checkpoint', 177.5, 9, { spawn: 'crystal' }); z.spawn('item.diamond', 196, 15.2, { id: 'cave-diamond-3' }); z.spawn('item.heart', 214.2, 10.8); // InvasiΓ³n tras el poder COOL: la gruta se cierra hasta vencer a todos (🫧 para subir, πŸ”« para derribar). rt.invasion = new Invasion(g, [{ id: 'cave-grotto', name: 'Gruta de cristal', x0: 175.6, x1: 209.4, floor: 9, top: 10, enemies: [ ['enemy.bee', 184, 12], ['enemy.ghost', 188, 14.5], ['enemy.bat', 192, 18.5], ['enemy.bee', 195, 13.5], ['enemy.ghost', 199, 12.5], ['enemy.bat', 202, 18], ['enemy.bee', 205, 15], ['enemy.bee', 190, 16.5], ], }]); // ═════════ F. Salida superior (x 208..244) ═════════ z.platform(222, 11.6, 3.2, { style: 'cave', thickness: 0.6 }); z.platform(227.2, 13.2, 3.1, { style: 'cave', thickness: 0.55 }); z.platform(232.2, 15.0, 3.0, { style: 'cave', thickness: 0.55 }); z.ground(234, 268, 16, { style: 'cave' }); z.prop('crystal', 236.5, 16, { z: -2.4, color: 0x65e0ff, scale: 1.3 }); z.prop('crystal', 241, 16, { z: -2.8, color: 0xb58cff, scale: 1.1 }); addHangingLantern(z, 237.5, 25, 19.8, true); z.spawn('item.teleporter', 220, 10, { id: 'cave', name: 'Cueva Cristal' }); z.prop('sign', 226, 10, { text: '↑ Salida', z: 0.3 }); // Chimenea ascendente al Bosque Susurro: la salida superior de la cueva. z.platform(247.5, 18.5, 3.4, { style: 'cave', thickness: 0.6 }); z.platform(252.2, 20.9, 3.2, { style: 'cave', thickness: 0.55 }); z.platform(256.8, 23.3, 3.2, { style: 'cave', thickness: 0.55 }); z.platform(261.2, 25.7, 3.2, { style: 'cave', thickness: 0.55 }); z.ground(263, 268, 28, { style: 'cave' }); z.prop('crystal', 265.5, 28, { z: -2.4, color: 0x65e0ff, scale: 1.2 }); addHangingLantern(z, 265, 33, 30.2, true); z.spawn('item.checkpoint', 264.2, 28, { spawn: 'exit' }); // La salida vertical al bosque se resuelve al alcanzar el borde superior derecho. z.prop('sign', 262.2, 28, { text: 'Bosque Susurro 🌲', z: 0.4 }); // ───────── monedas (una de cada tres del rastro se quitΓ³ para equilibrar con los cofres del castillo) ───────── const coins: Array<[number, number]> = [ // A (8) [4, 1.2], [6.5, 1.6], [9, 1.2], [11.5, 1.6], [14, 1.2], [18, 2.2], [22, 1.3], [28, 2.1], // B (15) [36, 1.25], [42, 2.1], [45.2, 2.8], [49.5, 4.0], [52.2, 4.7], [56.5, 5.3], [59.2, 5.7], [63.2, 3.4], [66, 2.2], [72, 1.25], [77, 1.4], [80.5, 2.1], [84, 1.35], [47, 8.2], [57.2, 8.8], // C (16) [90, 1.25], [93, 2.3], [95.8, 5.4], [99, 2.5], [102.5, 3.7], [107, 6.2], [110, 6.6], [113, 7.0], [116, 6.4], [119, 6.8], [121.8, 8.2], [126, 10.2], [129, 10.8], [132, 10.4], [138, 10.5], [141, 10.2], // D (8) [145, 10.4], [149, 11.0], [153, 10.5], [157, 11.2], [161, 10.5], [165, 11.1], [169, 10.4], [173, 10.5], // E (11) [184, 10.7], [188, 11.8], [192, 12.8], [196, 13.8], [200, 12.4], [204, 11.5], [207, 10.8], [212, 11.3], [215.5, 11.8], [218, 12.2], [221, 11.3], // F (12) [222, 13.0], [225, 13.4], [228, 14.6], [231, 15.5], [233, 16.7], [236, 17.2], [239, 17.2], [242, 17.2], [193, 15.8], [199, 16.0], [137, 10.7], [140, 11.1], // Chimenea al Bosque (4) [247.5, 19.6], [252.2, 22.0], [256.8, 24.4], [261.2, 26.8], ]; coins.forEach(([x, y], i) => { if (i % 3 !== 2) z.spawn('item.coin', x, y); }); // ───────── primer plano y atmΓ³sfera ───────── k.scatter('grassTuft', 1, 30, 0, 5, { z: 1.15, zJitter: 0.15 }); k.scatter('mushroom', 2, 30, 0, 3, { z: 1.0, zJitter: 0.2, color: 0x8f6bff, scale: 0.55 }); z.prop('stalagmite', 34.5, 0, { z: 1.3, scale: 0.7 }); z.prop('stalagmite', 87.5, 0, { z: 1.2, scale: 0.6 }); }, onEnter(game) { const g = game; if (!rt) return; g.state.set('cave.entered', true); rt.lit = isToolOn(g.state, 'flashlight'); applyCaveLighting(g, rt.lit, 0); vfxAmbient(g, 'dust', { density: rt.lit ? 0.22 : 0.42, color: 0x9c86c8, windX: 0.08 }); rt.offDig = wireDig(g, rt.grids); g.events.emit('map:poi', { zone: 'cave', x: 2, y: 2, emoji: 'πŸ•³οΈ', id: 'cave-entry' }); g.events.emit('map:poi', { zone: 'cave', x: 266, y: 29, emoji: '🌲', id: 'cave-forest' }); if (!g.state.has('spider.defeated')) { g.events.emit('map:poi', { zone: 'cave', x: 158, y: 10, emoji: 'πŸ•·οΈ', id: 'spider-boss' }); } if (g.state.has('spider.defeated')) { rt.leftWall.enabled = false; rt.rightWall.enabled = false; } }, update(game, dt) { const r = rt; const h = game.hero; if (!r || !h) return; const lit = isToolOn(game.state, 'flashlight'); if (lit !== r.lit) { r.lit = lit; applyCaveLighting(game, lit, 0.38); vfxAmbient(game, 'dust', { density: lit ? 0.22 : 0.42, color: 0x9c86c8, windX: 0.08 }); game.ui.toast(lit ? 'La cueva se ilumina' : 'La cueva vuelve a la oscuridad', 'πŸ”¦'); } void dt; r.invasion?.update(game); if (h.alive && h.x >= 266.5 && h.y >= 28 && !game.state.has('cave.forestExitBusy')) { game.state.set('cave.forestExitBusy', true); void game.loadZone('forest', 'from-cave').finally(() => game.state.set('cave.forestExitBusy', false)); return; } const fighting = game.state.has('spider.awakened') && !game.state.has('spider.defeated'); if (fighting !== r.arenaClosed) { r.arenaClosed = fighting; r.leftWall.enabled = fighting; r.rightWall.enabled = fighting; } }, onExit(game) { vfxAmbient(game, null); rt?.offDig?.(); rt = null; }, };