import * as THREE from 'three'; import type { Game } from '../../core/game'; import type { Collider, GroundOpts, ZoneDef } from '../../core/types'; import type { KitZoneContext } from '../kit/context'; import { vfxAmbient } from '../../vfx/index'; import { Invasion } from './invasion'; import { Barrier, SinkPad, invisibleWall } from './shared'; /** * LAGUNA BURBUJA 🫧 * * x -12..30 Orilla de entrada: llegada desde la ciudad, Eddy, checkpoint 'eddy', teletransporte. * x 30..80 Cruce de nenúfares (agua, superficie -0.6): nenúfares que se hunden un poco, troncos * móviles y nenúfares frágiles (amarillentos, con grietas) que se hunden si te quedas. * Llegar a la otra orilla sin caer → 'lagoon.crossed'. Después aparece un puente de vuelta. * x 80..96 Orilla lejana: checkpoint 'far-shore'. * x 96..170 Lago abierto (solo con burbujas): globos b1 b2 b3, monedas, roca de descanso y la isla * del cofre 'lagoon-island' (x 132..140). * El tesoro aéreo 'lagoon-sky' está en el cielo del CRUCE DE NENÚFARES (nube x≈66, y 8,0), * fuera del alcance del doble salto: solo con burbujas. * x 170..200 Orilla de la cueva: Paco y Lola entregan linterna/pala; la entrada 🕳️ se abre al tener la linterna. * * Flags propios: 'lagoon.attempt' (true mientras se cruza; si cae al agua vuelve a false y el héroe * reaparece en la orilla de Eddy, porque los nenúfares no cuentan como "suelo seguro"). */ const WATER_Y = -0.6; const PAD_TOP = WATER_Y + 0.12; const CROSS = { x0: 30, x1: 80 }; const FAR = { x0: 81, x1: 95 }; interface LagoonRt { bridge: Collider[]; bridgeView: THREE.Object3D[]; bridgeOn: boolean; wasWater: boolean; caveBarrier: Barrier; caveOpen: boolean; invasion: Invasion; } let rt: LagoonRt | null = null; function setBridge(g: Game, r: LagoonRt, on: boolean, animate: boolean): void { r.bridgeOn = on; for (const c of r.bridge) c.enabled = on; for (const v of r.bridgeView) v.visible = on; if (on && animate) { for (let x = CROSS.x0 + 3; x < CROSS.x1; x += 6) g.vfx.burst('splash', x, WATER_Y, { count: 8 }); g.audio.sfx('door', { volume: 0.6 }); g.ui.toast('¡Ha aparecido un puente de troncos de vuelta!', '🪵'); } } function onRoute(g: Game): boolean { const h = g.hero; const gr = h?.body.ground; return !!h && h.body.onGround && !!gr && (gr.tag === 'pad' || gr.tag === 'route'); } export const lagoonZone: ZoneDef = { id: 'lagoon', name: 'Laguna Burbuja', emoji: '🫧', bounds: { minX: -12, maxX: 200, minY: -5, maxY: 15 }, spawns: { default: { x: -5, y: 0 }, 'from-city': { x: -6, y: 0 }, eddy: { x: 14, y: 0 }, 'tp-lagoon': { x: 7, y: 0 }, 'far-shore': { x: 90, y: 0 }, cave: { x: 186, y: 0 }, 'cave-mouth': { x: 192, y: 0 }, }, env: 'lagoon', music: 'lagoon', build(z) { const k = z as KitZoneContext; const g = z.game; z.backdrop('lagoon', { horizon: -0.6 }); invisibleWall(g, -12.5, 0, 20); invisibleWall(g, 200.5, 0, 20); // ═════════ A. Orilla de entrada (x -12..30) ═════════ z.ground(-12, 16, 0, { style: 'grass' }); z.ground(16, 30, 0, { style: 'sand' }); z.exit(-11, 1.5, 1.6, 3, 'city', 'from-lagoon', { arrow: 'left' }); z.prop('sign', -2, 0, { text: '🫧 Laguna Burbuja' }); z.prop('tree', -8.5, 0, { z: -2.8, fruit: true }); z.prop('palm', 4, 0, { z: -2.4, lean: 0.6 }); z.prop('palm', 23, 0, { z: -2.6, lean: -0.5 }); z.prop('bush', -5, 0, { z: -1.3, flowers: true }); z.prop('rock', 11, 0, { z: -1.5 }); z.prop('rock', 27.5, 0, { z: -1.8, color: 0xe8c48a, moss: false }); z.prop('reeds', 29, 0, { z: -0.6 }); z.decor('🐚', 25.5, 0, { z: 0.9, scale: 0.45 }); z.decor('🦀', 19.2, 0, { z: -0.7, scale: 0.6 }); z.decor('⛱️', 18, 0, { z: -2.2, scale: 2 }); k.scatter('flower', -11, 15, 0, 8, { z: -0.9, zJitter: 0.5 }); z.spawn('item.checkpoint', 1, 0, { spawn: 'eddy' }); z.spawn('item.teleporter', 7, 0, { id: 'lagoon' }); z.spawn('npc.eddy', 21, 0, { id: 'eddy' }); z.prop('sign', 28, 0, { text: '¡No caigas al agua!', z: -1.1 }); // ═════════ B. Cruce de nenúfares (x 30..80) ═════════ z.water(CROSS.x0, CROSS.x1, WATER_Y, 4.4); z.ground(CROSS.x0, CROSS.x1, WATER_Y - 4.4, { style: 'sand', plain: true } as GroundOpts); // enseñar: nenúfares estables const pads: Array<[number, boolean, boolean]> = [ [33.5, false, false], [37.5, false, true], [41.5, false, false], ]; // practicar: tronco móvil z.platform(47.5, -0.25, 3, { style: 'wood', move: { dx: 3.4, period: 3.6 } }).tag = 'route'; // combinar: frágiles seguidos pads.push([53.5, false, false], [57.3, true, false], [61, true, false], [64.8, false, true]); // tronco que sube y baja z.platform(69.3, 0.2, 2.4, { style: 'wood', move: { dy: 1.6, period: 2.8 } }).tag = 'route'; pads.push([73.6, true, false], [77.2, false, false]); for (const [x, fragile, flower] of pads) g.add(new SinkPad(x, PAD_TOP, { fragile, flower, tag: 'pad' })); // decorado del agua (sin colisión) for (const [x, zz] of [[35, -2.2], [44, -3], [55.5, -1.8], [66, -2.6], [75, -3.2]] as const) { z.prop('lilypad', x, WATER_Y + 0.02, { z: zz, flower: x === 55.5 }); } z.decor('🐸', 44, WATER_Y + 0.05, { z: -3, scale: 0.6 }); z.decor('🦆', 60, WATER_Y, { z: -3.6, scale: 0.8 }); z.decor('🐟', 51, WATER_Y - 1.4, { z: 0.6, scale: 0.6 }); // acantilado del fondo con cascadas z.prop('rock', 39, WATER_Y - 3, { z: -7.5, scale: 9, color: 0x8fa3a8, moss: false }); k.waterfall(38.6, 2.6, WATER_Y, { z: -4.2, width: 1.8 }); z.prop('rock', 64, WATER_Y - 3, { z: -8, scale: 10, color: 0x98a6ad, moss: false }); k.waterfall(63.6, 3.2, WATER_Y, { z: -4.4, width: 2.2 }); for (const x of [31, 50, 79]) z.prop('reeds', x, WATER_Y, { z: 1.7 }); z.spawn('item.coin', 41.5, 2); z.spawn('item.coin', 47.5, 2.4); z.spawn('item.coin', 69.3, 3.4); // ── tesoro aéreo en el cielo del cruce: islote nube SOLO alcanzable con burbujas. // Lo más alto que se pisa aquí es el tronco que sube (≈1,8 u): con doble salto se llega como mucho // a ≈6,5 u, así que la nube a 8,0 u exige una cadena de burbujas (cada escalón sube ≈2,4 u). z.platform(66, 8.0, 5, { style: 'cloud' }); z.prop('lilypad', 64.2, 8.0, { z: -0.5, flower: true }); z.prop('flower', 67.9, 8.0, { z: -0.4 }); z.prop('reeds', 68.3, 8.0, { z: 0.4 }); z.spawn('item.chest', 66, 8.0, { id: 'lagoon-sky', contains: 'diamond' }); z.spawn('item.diamond', 67.5, 8.8, { id: '@lagoon.d1375_88' }); z.decor('✨', 66, 9.7, { z: -0.5, scale: 0.8, glow: true }); // monedas guía para la cadena de burbujas desde el nenúfar estable for (const [x, y] of [[64.8, 2.4], [66.2, 4.4], [65, 6.3]]) { z.spawn('item.coin', x, y); } // puente de vuelta (aparece tras 'lagoon.crossed') const bridge: Collider[] = []; const bridgeView: THREE.Object3D[] = []; for (let i = 0; i < 5; i++) { const x = CROSS.x0 + 5 + i * 10; bridgeView.push(z.prop('bridge', x, 0.6, { width: 10, dynamic: true, z: -0.2 })); bridge.push(g.physics.box(x, 0.5, 10, 0.2, { oneWay: true, material: 'wood', tag: 'bridge' })); } // ═════════ C. Orilla lejana (x 80..96) ═════════ z.ground(80, 96, 0, { style: 'sand' }); z.prop('palm', 86, 0, { z: -2.4, lean: 0.4 }); z.prop('rock', 92.5, 0, { z: -1.6, color: 0xe8c48a, moss: false }); z.prop('sign', 94.5, 0, { text: '🫧 Solo con burbujas', z: -0.9 }); z.decor('🐢', 83.5, 0, { z: -0.8, scale: 0.7 }); z.spawn('item.checkpoint', 89.5, 0, { spawn: 'far-shore' }); z.prop('reeds', 95.6, 0, { z: -0.5 }); // ═════════ D. Lago abierto (x 96..170), solo con burbujas ═════════ z.water(96, 170, WATER_Y, 4.4, { shoreL: false }); z.ground(96, 170, WATER_Y - 4.4, { style: 'sand', plain: true } as GroundOpts); // roca de descanso z.block(116, -0.6, 2, 1.4, { style: 'stone' }); z.decor('🦩', 116.3, 0.1, { z: -0.6, scale: 0.9 }); // isla del cofre z.block(136, -1.6, 8, 3.2, { style: 'sand' }); z.prop('palm', 133.5, 0, { z: -1.6, lean: 0.5 }); z.prop('bush', 138.6, 0, { z: -1.1, berries: true, scale: 0.8 }); z.spawn('item.chest', 137, 0, { id: 'lagoon-island', contains: 'diamond' }); z.spawn('item.heart', 134.5, 0.2); // globos (el héroe los revienta con la pistola de agua subido a una burbuja) z.spawn('item.balloon', 106, 3.6, { id: 'b1' }); z.spawn('item.balloon', 125, 6.8, { id: 'b2' }); z.spawn('item.balloon', 156, 5.4, { id: 'b3' }); // monedas en arco para guiar las cadenas de burbujas for (const [x, y] of [[100, 1.6], [102.5, 2.6], [105, 2.2], [121, 2.4], [123.5, 3.4], [146, 2], [149, 3], [152, 3.4], [162, 2]]) { z.spawn('item.coin', x, y); } z.spawn('item.diamond', 125, 9.2); z.decor('🦢', 110, WATER_Y, { z: -3.4, scale: 1 }); z.decor('🦆', 147, WATER_Y, { z: -4, scale: 0.8, flipX: true }); z.decor('🐟', 142, WATER_Y - 1.8, { z: 0.6, scale: 0.6, flipX: true }); z.prop('rock', 104, WATER_Y - 3, { z: -8, scale: 8, color: 0x8fa3a8, moss: false }); z.prop('rock', 150, WATER_Y - 3, { z: -8, scale: 9.5, color: 0x98a6ad, moss: false }); k.waterfall(149.6, 2.9, WATER_Y, { z: -4.6, width: 1.6 }); for (const [x, zz] of [[99, -1.8], [112, -2.6], [128, -2], [144, -2.8], [160, -1.6], [166, -3]] as const) { z.prop('lilypad', x, WATER_Y + 0.02, { z: zz, flower: x === 128 || x === 160 }); } for (const x of [100, 129, 158]) z.prop('reeds', x, WATER_Y, { z: 1.75 }); // ═════════ E. Orilla de la cueva (x 170..200) ═════════ // Camino de tierra que sube hasta la boca. Nada de muralla de piedra. z.ground(170, 180, 0, { style: 'grass' }); z.ground(180, 199, 0, { style: 'sand' }); z.prop('reeds', 170.6, 0, { z: -0.5 }); z.prop('tree', 174, 0, { z: -2.8 }); z.prop('palm', 178.5, 0, { z: -2.2, lean: -0.4 }); z.prop('rock', 182.2, 0, { z: -1.6, scale: 1.15, color: 0x7a6e86 }); z.prop('rock', 186.4, 0, { z: 1.15, scale: 0.85, color: 0x6a6078 }); z.prop('barrel', 184.2, 0, { z: -0.7 }); z.prop('crate', 188.8, 0, { z: -1.2 }); z.prop('torch', 191.2, 0, { z: -1.5 }); z.spawn('npc.miner', 185.4, 0, { id: 'minero-paco', role: 'flashlight', emoji: '👷', name: 'Minero Paco', facing: 1, }); z.spawn('npc.miner', 188.2, 0, { id: 'minera-lola', role: 'shovel', emoji: '👷‍♀️', name: 'Minera Lola', facing: -1, }); // Boca natural de la cueva: ladera de roca con arco, entibado de mina, farol y raíles (sin puerta). z.spawn('world.cavemouth', 197.4, 0, {}); const caveOpen = g.state.hasTool('flashlight'); const caveBarrier = g.add(new Barrier(193.4, 0, { color: 0xffc928, emoji: '🚧', closed: !caveOpen })); z.prop('sign', 192.2, 0, { text: 'Cueva Cristal', z: 0.4 }); // se entra caminando hacia la oscuridad del arco z.exit(198.6, 1.6, 1.2, 3.2, 'cave', 'from-lagoon', {}); if (g.hasType('enemy.robot')) z.spawn('enemy.robot', 175, 0, { patrol: [171, 179] }); // ───────── primer plano y cielo ───────── k.scatter('grassTuft', -11, 15, 0, 10, { z: 1.2, zJitter: 0.2 }); k.scatter('grassTuft', 170, 179, 0, 4, { z: 1.2, zJitter: 0.2 }); for (const [x, y, s] of [[0, 10.5, 1.6], [40, 12, 2], [85, 11, 1.7], [130, 12.5, 2.2], [180, 11, 1.8]]) { z.prop('cloud', x, y, { z: -9, scale: s }); } const invasion = new Invasion(g, [ { id: 'lagoon-cross', name: 'Cruce de nenúfares', x0: 28.8, x1: 80.6, enemies: [ ['enemy.bee', 39, 3], ['enemy.ghost', 46, 4.5], ['enemy.bee', 54, 5.5], ['enemy.bat', 60, 8], ['enemy.bee', 66, 3.2], ['enemy.ghost', 70, 6.5], ['enemy.bee', 75, 5], ], }, ]); rt = { bridge, bridgeView, bridgeOn: false, wasWater: false, caveBarrier, caveOpen, invasion }; }, onEnter(game) { vfxAmbient(game, 'bubbles', { density: 0.6 }); if (!rt) return; game.state.set('lagoon.attempt', false); setBridge(game, rt, game.state.has('lagoon.crossed'), false); const canEnter = game.state.hasTool('flashlight'); rt.caveOpen = canEnter; rt.caveBarrier.setClosed(!canEnter, true); }, update(game) { const r = rt; const h = game.hero; if (!r || !h) return; r.invasion.update(game); const st = game.state; const b = h.body; if (!r.caveOpen && st.hasTool('flashlight')) { r.caveOpen = true; r.caveBarrier.setClosed(false); game.ui.toast('¡La entrada a la Cueva Cristal está abierta!', '🕳️'); game.audio.sfx('door', { volume: 0.7 }); game.after(0.8, () => game.vfx.burst('sparkle', 195, 3.2, { count: 18, color: 0xffe066 })); } const inWater = game.physics.areasAt(b, 'water').some((a) => b.y < a.y + a.hh); if (!st.has('lagoon.crossed')) { const attempt = st.has('lagoon.attempt'); if (!attempt && onRoute(game)) st.set('lagoon.attempt', true); else if (attempt) { if (inWater && !r.wasWater) { st.set('lagoon.attempt', false); game.ui.toast('¡Chof! Vuelve a intentarlo desde la orilla', '💦'); } else if (b.onGround && h.x < CROSS.x0 && !onRoute(game)) { st.set('lagoon.attempt', false); } else if (b.onGround && !onRoute(game) && h.x > FAR.x0 && h.x < FAR.x1) { st.set('lagoon.attempt', false); st.set('lagoon.crossed', true); game.vfx.burst('confetti', h.x, h.y + 1, { count: 40 }); game.audio.sfx('victory', { volume: 0.7 }); r.bridgeOn = true; game.after(1.5, () => { if (rt) setBridge(game, rt, true, true); }); } } } else if (!r.bridgeOn && st.has('lagoon.crossed')) { // por si el flag llega de otro lado (consola, partida antigua) setBridge(game, r, true, false); } r.wasWater = inWater; }, onExit(game) { vfxAmbient(game, null); rt = null; }, };