// The Drowning Isle: the big moments, staged over the island. // // watersRise(scene) a wave sweeps the island under a caption // capture(scene, key, from, who, to, done) the relic painting rises from its // shrine in a burst of light, then files // itself in the journal's relic tracker // escape(scene, dock, done) a helicopter drops onto the dock, the crew // climbs in, and it lifts off as the // island sinks behind it // loss(scene, gs, done) a short scene for each way to lose // // Every function is skippable in spirit: the game state has already been // decided, and `done` fires when the camera can move on. import * as Phaser from 'phaser'; import { W, H, DEPTH, BX0, BY0, BOARD_W, TILE, DISPLAY_FONT, BODY_FONT, TYPE_FONT, RAIL_X } from './IslandLayout.js'; import { TREASURES, cardFrame } from './IslandData.js'; import * as Sound from './IslandSound.js'; const CX = BX0 + BOARD_W / 2, CY = BY0 + BOARD_W / 2; // A torn strip of journal paper across the island with a headline. export function caption(scene, title, sub = '', { y = CY, hold = 1600, color = '#2b1d08' } = {}) { const t = scene.add.text(0, -8, title, { fontFamily: DISPLAY_FONT, fontSize: '44px', color }).setOrigin(0.5); const st = sub ? scene.add.text(0, 30, sub, { fontFamily: BODY_FONT, fontStyle: 'italic', fontSize: '19px', color: '#5a4a35' }).setOrigin(0.5) : null; const w = Math.max(t.width, st?.width ?? 0) + 90, h = sub ? 110 : 80; const g = scene.add.graphics(); g.fillStyle(0x000000, 0.35); g.fillRect(-w / 2 + 5, -h / 2 - 4 + 6, w, h); g.fillStyle(0xe9dcc0, 1); g.beginPath(); g.moveTo(-w / 2, -h / 2 - 4); for (let x = -w / 2; x <= w / 2; x += 18) g.lineTo(x, -h / 2 - 4 + (Math.random() * 5)); g.lineTo(w / 2, h / 2 - 4); for (let x = w / 2; x >= -w / 2; x -= 18) g.lineTo(x, h / 2 - 4 - (Math.random() * 5)); g.closePath(); g.fillPath(); const c = scene.add.container(CX, y, st ? [g, t, st] : [g, t]).setDepth(DEPTH.banner - 5).setAngle(-2).setAlpha(0).setScale(1.15); scene.tweens.add({ targets: c, alpha: 1, scale: 1, duration: 260, ease: 'Back.easeOut' }); scene.tweens.add({ targets: c, alpha: 0, y: y - 20, delay: hold, duration: 400, onComplete: () => c.destroy() }); return c; } export function watersRise(scene) { Sound.watersRise(scene); caption(scene, 'The Waters Rise', 'Every flooded tile goes back on top of the flood deck', { hold: 1500, color: '#1f4a66' }); // A wave front rolling across the island. const wave = scene.add.tileSprite(BX0 - 340, BY0 - 30, 300, BOARD_W + 60, 'di-water').setOrigin(0) .setDepth(DEPTH.tileFx + 2).setAlpha(0.5).setTint(0xbfe8f0); const foam = scene.add.image(BX0 - 40, CY, 'di-glow').setDepth(DEPTH.tileFx + 3).setDisplaySize(90, BOARD_W + 80) .setTint(0xffffff).setAlpha(0.6).setBlendMode(Phaser.BlendModes.ADD); scene.tweens.add({ targets: [wave, foam], x: `+=${BOARD_W + 420}`, duration: 1500, ease: 'Sine.easeInOut', onUpdate: () => { wave.tilePositionY += 3; }, onComplete: () => { wave.destroy(); foam.destroy(); }, }); scene.cameras.main.shake(500, 0.004); } export function capture(scene, key, from, who, to, done = () => {}) { Sound.capture(scene); const objs = []; const dim = scene.add.rectangle(0, 0, RAIL_X - 30, H, 0x05101a, 0).setOrigin(0).setDepth(DEPTH.popup); objs.push(dim); scene.tweens.add({ targets: dim, fillAlpha: 0.6, duration: 400 }); // turning rays const rays = scene.add.graphics().setPosition(CX, CY - 20).setDepth(DEPTH.popup + 1).setAlpha(0).setBlendMode(Phaser.BlendModes.ADD); const col = TREASURES[key].color; for (let i = 0; i < 16; i++) { const a = (i / 16) * Math.PI * 2; rays.fillStyle(i % 2 ? col : 0xffe7a8, 0.35); rays.fillTriangle(0, 0, Math.cos(a - 0.09) * 420, Math.sin(a - 0.09) * 420, Math.cos(a + 0.09) * 420, Math.sin(a + 0.09) * 420); } objs.push(rays); scene.tweens.add({ targets: rays, alpha: 1, duration: 500, delay: 200 }); scene.tweens.add({ targets: rays, angle: 40, duration: 3000 }); const glow = scene.add.image(CX, CY - 20, 'di-glow').setDepth(DEPTH.popup + 1).setDisplaySize(520, 520).setTint(col).setAlpha(0).setBlendMode(Phaser.BlendModes.ADD); objs.push(glow); scene.tweens.add({ targets: glow, alpha: 0.9, duration: 600, delay: 200 }); let art; if (scene.textures.exists('forbiddenisland-cards')) { art = scene.add.image(from.x, from.y, 'forbiddenisland-cards', cardFrame(`treasure:${key}`)).setDisplaySize(40, 52); } else { art = scene.add.circle(from.x, from.y, 20, col); } art.setDepth(DEPTH.popup + 2); const big = { w: 240, h: 315 }; scene.tweens.add({ targets: art, x: CX, y: CY - 20, displayWidth: big.w, displayHeight: big.h, duration: 900, ease: 'Cubic.easeOut' }); const sparks = scene.add.particles(CX, CY - 20, 'di-spark', { speed: { min: 80, max: 340 }, lifespan: 1200, scale: { start: 1.4, end: 0 }, alpha: { start: 1, end: 0 }, blendMode: 'ADD', emitting: false, }).setDepth(DEPTH.popup + 3); objs.push(sparks); scene.time.delayedCall(850, () => sparks.explode(70)); const title = scene.add.text(CX, CY + 175, TREASURES[key].name, { fontFamily: DISPLAY_FONT, fontSize: '40px', color: '#f0d58c' }) .setOrigin(0.5).setDepth(DEPTH.popup + 3).setAlpha(0).setShadow(0, 3, '#000', 8); const sub = scene.add.text(CX, CY + 220, `recovered by ${who}`, { fontFamily: BODY_FONT, fontStyle: 'italic', fontSize: '20px', color: '#f2e6cc' }) .setOrigin(0.5).setDepth(DEPTH.popup + 3).setAlpha(0); objs.push(title, sub); scene.tweens.add({ targets: [title, sub], alpha: 1, duration: 400, delay: 900 }); scene.time.delayedCall(2700, () => { scene.tweens.add({ targets: [dim], fillAlpha: 0, duration: 450 }); scene.tweens.add({ targets: [rays, glow, title, sub], alpha: 0, duration: 400 }); scene.tweens.add({ targets: art, x: to.x, y: to.y, displayWidth: 40, displayHeight: 52, duration: 650, ease: 'Cubic.easeIn', onComplete: () => { art.destroy(); objs.forEach((o) => o.destroy()); done(); }, }); }); } // An original little expedition helicopter, drawn in a container. function makeHelicopter(scene) { const g = scene.add.graphics(); g.fillStyle(0x000000, 0.0); // tail boom + fin g.fillStyle(0x4a5a3a, 1); g.fillRect(30, -10, 90, 9); g.fillTriangle(112, -10, 128, -34, 126, -6); // body g.fillStyle(0x5d6e44, 1); g.fillEllipse(0, 0, 100, 52); g.fillStyle(0x3d4a2c, 1); g.fillRect(-30, 12, 70, 8); // cockpit glass g.fillStyle(0x9fd3e0, 0.85); g.fillEllipse(-26, -6, 42, 32); g.fillStyle(0xffffff, 0.35); g.fillEllipse(-32, -12, 14, 8); // stencil and skids g.fillStyle(0xe9dcc0, 1); g.fillRect(8, -6, 26, 3); g.lineStyle(3, 0x2a2a22, 1); g.lineBetween(-40, 36, 40, 36); g.lineBetween(-24, 22, -26, 36); g.lineBetween(22, 22, 24, 36); g.lineBetween(-40, 36, -46, 31); // mast g.fillStyle(0x2a2a22, 1); g.fillRect(-4, -34, 8, 10); const rotor = scene.add.ellipse(0, -36, 230, 10, 0x1a1a14, 0.45); const tail = scene.add.ellipse(126, -20, 6, 30, 0x1a1a14, 0.45); const shadow = scene.add.ellipse(0, 0, 120, 26, 0x000000, 0.35); const body = scene.add.container(0, 0, [g, rotor, tail]); const c = scene.add.container(0, 0, [body]).setDepth(DEPTH.rain - 2); c.rotor = rotor; c.tail = tail; c.body = body; c.shadow = shadow; shadow.setDepth(DEPTH.tileFx + 2); const spin = scene.tweens.add({ targets: rotor, scaleX: { from: 1, to: 0.15 }, duration: 60, yoyo: true, repeat: -1 }); const spin2 = scene.tweens.add({ targets: tail, scaleY: { from: 1, to: 0.2 }, duration: 45, yoyo: true, repeat: -1 }); c.stopRotor = () => { spin.stop(); spin2.stop(); }; return c; } export function escape(scene, dock, done = () => {}) { Sound.rotor(scene, 6); const heli = makeHelicopter(scene); heli.setPosition(-200, dock.y - 260).setScale(0.8); heli.shadow.setPosition(-200, dock.y + 30); const hover = { y: dock.y - 70 }; scene.tweens.add({ targets: heli, x: dock.x, y: hover.y, scale: 1, duration: 1800, ease: 'Cubic.easeOut' }); scene.tweens.add({ targets: heli.shadow, x: dock.x, duration: 1800, ease: 'Cubic.easeOut' }); scene.tweens.add({ targets: heli.body, angle: { from: -4, to: 4 }, duration: 700, yoyo: true, repeat: -1, ease: 'Sine.easeInOut' }); // the crew climbs aboard scene.time.delayedCall(1900, () => { const figs = Object.values(scene.figures ?? {}); figs.forEach((f, i) => { scene.tweens.add({ targets: f.container, x: dock.x, y: hover.y + 10, alpha: 0, scale: 0.6, duration: 600, delay: i * 220, ease: 'Cubic.easeIn' }); }); }); // the island goes under behind them, furthest tiles first scene.time.delayedCall(2600, () => { const views = Object.values(scene.tileViews ?? {}).filter((v) => v.state !== 'sunk'); views.sort((a, b) => Math.hypot(b.x - dock.x, b.y - dock.y) - Math.hypot(a.x - dock.x, a.y - dock.y)); views.forEach((v, i) => scene.time.delayedCall(i * 90, () => v.sink())); Sound.sink(scene); }); scene.time.delayedCall(3100, () => { scene.tweens.add({ targets: heli, x: RAIL_X + 120, y: -160, scale: 0.55, duration: 2400, ease: 'Cubic.easeIn' }); scene.tweens.add({ targets: heli.shadow, alpha: 0, duration: 900 }); caption(scene, 'Lift-off', 'All four relics aboard, and the whole crew with them', { y: BY0 + BOARD_W - 80, hold: 2200 }); }); scene.time.delayedCall(5600, () => { heli.stopRotor(); heli.destroy(); heli.shadow.destroy(); done(); }); } export function loss(scene, gs, done = () => {}) { const kind = gs.lossKind ?? 'gauge'; scene.storm?.strike({ bright: 0.75 }); scene.cameras.main.shake(600, 0.006); const views = Object.values(scene.tileViews ?? {}); if (kind === 'gauge') { watersRise(scene); const rest = views.filter((v) => v.state !== 'sunk').sort((a, b) => a.x - b.x); rest.forEach((v, i) => scene.time.delayedCall(500 + i * 70, () => v.sink())); scene.time.delayedCall(2200, () => caption(scene, 'Swallowed by the Sea', 'The tide gauge reached the drowned mark', { hold: 1600, color: '#8e2a1e' })); scene.time.delayedCall(4200, done); return; } if (kind === 'relic' && gs.lossTreasure && scene.textures.exists('forbiddenisland-cards')) { const art = scene.add.image(CX, CY - 30, 'forbiddenisland-cards', cardFrame(`treasure:${gs.lossTreasure}`)) .setDisplaySize(200, 262).setDepth(DEPTH.popup + 2).setAlpha(0); const crack = scene.add.graphics().setDepth(DEPTH.popup + 3).setPosition(CX, CY - 30); scene.tweens.add({ targets: art, alpha: 1, duration: 400 }); scene.time.delayedCall(700, () => { crack.lineStyle(4, 0x1a110a, 1); crack.beginPath(); crack.moveTo(-10, -131); [[8, -80], [-14, -30], [12, 10], [-6, 60], [10, 131]].forEach(([x, y]) => crack.lineTo(x, y)); crack.strokePath(); art.setTint(0x777777); Sound.sink(scene); }); scene.time.delayedCall(1300, () => { scene.tweens.add({ targets: [art, crack], y: '+=260', alpha: 0, angle: 12, duration: 1100, ease: 'Cubic.easeIn' }); caption(scene, 'A Relic Is Lost', `${TREASURES[gs.lossTreasure].name} sank with both of its shrines`, { hold: 1600, color: '#8e2a1e' }); }); scene.time.delayedCall(3600, () => { art.destroy(); crack.destroy(); done(); }); return; } if (kind === 'crew' && gs.lossSeat != null && scene.figures?.[gs.lossSeat]) { const f = scene.figures[gs.lossSeat]; scene.sea?.bubbles(f.container.x, f.container.y - 10, 30, 20); scene.tweens.add({ targets: f.container, y: f.container.y + 30, alpha: 0, duration: 1600, ease: 'Cubic.easeIn' }); Sound.sink(scene); caption(scene, 'Lost Beneath the Waves', 'There was no dry ground left to swim to', { hold: 1800, color: '#8e2a1e' }); scene.time.delayedCall(2800, done); return; } // the dock const dock = scene.tileViews?.['fools-landing']; if (dock) { scene.sea?.ripple(dock.x, dock.y, { size: TILE * 3, duration: 1800 }); scene.sea?.ripple(dock.x, dock.y, { size: TILE * 2, duration: 1500, delay: 300 }); } caption(scene, 'The Dock Is Gone', 'No helicopter can land on open water', { hold: 1800, color: '#8e2a1e' }); scene.time.delayedCall(2800, done); } export { TYPE_FONT, W };