La macchina del tempo da fuori: la partenza giù per Via Liguri Magelli col fulmine e le sgommate di fuoco, e l'arrivo al ritorno dal 1997 (macchina da dietro e davanti di Codex) (Andrea)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GiECd9KMfjthRUnujCGSzZ
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
// La macchina del tempo vista da fuori (story.closeups, type 'corsa'; Andrea, 30 ottobre). In partenza ('parti') va via
|
||||
// giù per la strada accelerando, il fulmine la prende, il bianco, e restano due sgommate di fuoco che bruciano e si
|
||||
// spengono. All'arrivo ('arriva') il fulmine in fondo alla strada, e lei viene avanti e ci passa accanto, lasciando le
|
||||
// stesse strisce (davanti a noi: dietro alla macchina non si vedrebbero). Sopra lo sfondo della scena (`scene`), coi fotogrammi di Codex (`frames`: dietro, dietro coi lampi,
|
||||
// davanti coi lampi). Unità: i pixel della scena 640×360.
|
||||
|
||||
// I tempi, in secondi. Partenza: ferma che si carica, la corsa, il fulmine, il bianco, le fiamme, la fine.
|
||||
export const PARTI = { charge: 0.6, run: 2.2, bolt: 2.3, flash: 0.35, burn: 4.6, end: 5.2 };
|
||||
// Arrivo: il fulmine in fondo, la corsa verso di noi fin fuori dal quadro, le fiamme, la fine.
|
||||
export const ARRIVA = { bolt: 0.3, flash: 0.35, run: 1.5, burn: 4, end: 4.6 };
|
||||
|
||||
const lerp = (a, b, k) => a + (b - a) * k;
|
||||
const clamp01 = k => Math.max(0, Math.min(1, k));
|
||||
// Dove sta la macchina a un punto `k` del percorso (0 vicina, 1 in fondo): posizione delle ruote e grandezza.
|
||||
export function along(def, k) {
|
||||
const [a, b] = def.path;
|
||||
return { x: lerp(a[0], b[0], k), y: lerp(a[1], b[1], k), scale: lerp(a[2], b[2], k) };
|
||||
}
|
||||
// Il punto del percorso al tempo t: in partenza accelera (da fermo); all'arrivo viene avanti dal fondo fin oltre il
|
||||
// punto 0 (fuori dal quadro, accanto a noi).
|
||||
export function progress(c, def) {
|
||||
if (def.mode === 'arriva') return 1 - clamp01((c.t - ARRIVA.bolt) / ARRIVA.run);
|
||||
const k = clamp01((c.t - PARTI.charge) / (PARTI.run - PARTI.charge));
|
||||
return Math.min(0.92, k * k);
|
||||
}
|
||||
// Si vede la macchina? In partenza fino al fulmine; all'arrivo dal fulmine in poi.
|
||||
export function carShown(c, def) {
|
||||
return def.mode === 'arriva' ? c.t >= ARRIVA.bolt + 0.05 && c.t < ARRIVA.bolt + ARRIVA.run : c.t < PARTI.bolt + 0.05;
|
||||
}
|
||||
// Dove arriva il fulmine: sulla macchina in partenza, in fondo alla strada all'arrivo.
|
||||
export function boltAt(def) { return def.mode === 'arriva' ? along(def, 1) : along(def, progress({ t: PARTI.bolt }, def)); }
|
||||
const T = def => def.mode === 'arriva' ? ARRIVA : PARTI;
|
||||
|
||||
export function newCorsa(id) { return { id, t: 0, age: 0, events: [] }; }
|
||||
// Il tempo che passa e i suoni; vero quando è finita.
|
||||
export function updateCorsa(c, def, dt) {
|
||||
c.t += dt;
|
||||
const times = T(def);
|
||||
if (def.mode !== 'arriva' && !c.charge && c.t >= 0.1) { c.charge = true; c.events.push({ kind: 'gara-turbo', power: 1 }); }
|
||||
if (!c.boom && c.t >= times.bolt) { c.boom = true; c.events.push({ kind: 'corsa-tuono', power: 1 }); }
|
||||
if (!c.fire && c.t >= (def.mode === 'arriva' ? ARRIVA.bolt + 0.2 : PARTI.charge + 0.3)) { c.fire = true; c.events.push({ kind: 'corsa-fuoco', power: 1 }); }
|
||||
return c.t >= times.end;
|
||||
}
|
||||
|
||||
// Le due ruote posteriori (o anteriori) a un punto del percorso: una a sinistra e una a destra.
|
||||
function wheels(def, k) {
|
||||
const p = along(def, k), half = def.track * p.scale;
|
||||
return [[p.x - half, p.y], [p.x + half, p.y]];
|
||||
}
|
||||
// Le sgommate di fuoco: da dove è partita a dove è arrivata, fiammelle che tremano, più piccole in fondo, che si
|
||||
// spengono dopo `burn`.
|
||||
function fire(ctx, c, def) {
|
||||
const times = T(def), shown = def.mode === 'arriva' ? [Math.max(progress(c, def), 0), 1] : [0, progress({ t: Math.min(c.t, times.bolt) }, def)];
|
||||
const fade = c.t < times.burn ? 1 : clamp01(1 - (c.t - times.burn) / (times.end - times.burn));
|
||||
if (fade <= 0 || shown[1] - shown[0] < 0.005) return;
|
||||
for (let side = 0; side < 2; side++) {
|
||||
// Prima il segno nero bruciato, poi le fiamme sopra.
|
||||
const [a, b] = [wheels(def, shown[0])[side], wheels(def, shown[1])[side]];
|
||||
ctx.strokeStyle = `rgba(30,18,10,${0.7 * Math.max(fade, 0.5)})`; ctx.lineWidth = 4; ctx.beginPath(); ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]); ctx.stroke();
|
||||
const n = 70;
|
||||
for (let i = 0; i <= n; i++) {
|
||||
const k = lerp(shown[0], shown[1], i / n), [x, y] = wheels(def, k)[side], s = Math.max(0.12, along(def, k).scale);
|
||||
// Lingue di fuoco di altezza diversa, che tremano: rosso fuori, arancio, il cuore giallo.
|
||||
const flick = 0.55 + 0.45 * Math.sin(c.t * 19 + i * 2.3 + side * 2) * Math.sin(c.t * 7 + i * 0.9);
|
||||
const h = (16 + 22 * flick) * s * fade, w = Math.max(2, 9 * s);
|
||||
if (h < 1.5) continue;
|
||||
ctx.fillStyle = `rgba(255,120,30,${0.18 * fade})`; ctx.fillRect(Math.round(x - w), Math.round(y - h * 1.2), Math.ceil(w * 2), Math.ceil(h * 1.2));
|
||||
ctx.fillStyle = `rgba(220,50,20,${0.9 * fade})`; ctx.fillRect(Math.round(x - w / 2), Math.round(y - h), Math.ceil(w), Math.ceil(h));
|
||||
ctx.fillStyle = `rgba(255,${Math.round(140 + 60 * flick)},30,${0.95 * fade})`; ctx.fillRect(Math.round(x - w / 3), Math.round(y - h * 0.7), Math.ceil(w * 0.66), Math.ceil(h * 0.7));
|
||||
ctx.fillStyle = `rgba(255,245,170,${fade})`; ctx.fillRect(Math.round(x - w / 6), Math.round(y - h * 0.35), Math.max(1, Math.ceil(w / 3)), Math.ceil(h * 0.35));
|
||||
// Un filo di fumo che sale quando le fiamme calano.
|
||||
if (c.t > times.burn - 1 && i % 8 === 0) {
|
||||
ctx.fillStyle = `rgba(90,90,96,${0.25 * fade})`;
|
||||
ctx.fillRect(Math.round(x - 2 * s), Math.round(y - h - 6 * s - ((c.t * 18 + i) % 14) * s), Math.ceil(4 * s), Math.ceil(4 * s));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Il fulmine: una saetta spezzata dal cielo fino al punto, con due rami.
|
||||
function bolt(ctx, c, def) {
|
||||
const times = T(def), dt = c.t - times.bolt;
|
||||
if (dt < -0.12 || dt > 0.28) return;
|
||||
const p = boltAt(def), seed = Math.floor(c.t * 30);
|
||||
ctx.save();
|
||||
for (const [width, color] of [[6, 'rgba(140,200,255,0.5)'], [2, '#ffffff']]) {
|
||||
ctx.strokeStyle = color; ctx.lineWidth = width; ctx.beginPath();
|
||||
let x = p.x + 40, y = 0; ctx.moveTo(x, y);
|
||||
const steps = 9;
|
||||
for (let i = 1; i <= steps; i++) {
|
||||
x = lerp(p.x + 40, p.x, i / steps) + (i < steps ? ((seed * (i + 5) * 53) % 30) - 15 : 0);
|
||||
y = lerp(0, p.y - 12 * p.scale, i / steps); ctx.lineTo(x, y);
|
||||
}
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
export function drawCorsa(ctx, c, def, { bg, frames, tint }) {
|
||||
const times = T(def);
|
||||
ctx.save(); ctx.imageSmoothingEnabled = false;
|
||||
// La strada trema un po' quando la macchina si carica e quando arriva il fulmine.
|
||||
const shake = (def.mode !== 'arriva' && c.t < PARTI.charge + 0.4 ? 1.5 : 0) + (Math.abs(c.t - times.bolt) < 0.25 ? 3 : 0);
|
||||
ctx.translate(Math.round(Math.sin(c.t * 57) * shake), Math.round(Math.cos(c.t * 43) * shake));
|
||||
if (bg) ctx.drawImage(bg, 0, 0, 640, 360); else { ctx.fillStyle = '#4a4a50'; ctx.fillRect(0, 0, 640, 360); }
|
||||
if (tint) { ctx.fillStyle = tint; ctx.fillRect(0, 0, 640, 360); }
|
||||
fire(ctx, c, def);
|
||||
if (carShown(c, def)) {
|
||||
const k = progress(c, def), p = along(def, k);
|
||||
// Da dietro: coi lampi mentre si carica e quando corre forte; davanti (all'arrivo) coi lampi finché frena.
|
||||
const img = def.mode === 'arriva' ? frames?.davanti : c.t > PARTI.charge * 0.5 && Math.floor(c.t * 14) % 3 !== 0 ? frames?.lampi : frames?.dietro;
|
||||
if (img) {
|
||||
const w = def.width * p.scale, h = w * img.height / img.width;
|
||||
ctx.drawImage(img, Math.round(p.x - w / 2), Math.round(p.y - h), Math.round(w), Math.round(h));
|
||||
} else { ctx.fillStyle = '#c8ccd2'; ctx.fillRect(Math.round(p.x - 40 * p.scale), Math.round(p.y - 40 * p.scale), Math.round(80 * p.scale), Math.round(40 * p.scale)); }
|
||||
}
|
||||
bolt(ctx, c, def);
|
||||
ctx.restore();
|
||||
// Il bianco del fulmine, che sfuma.
|
||||
const f = c.t - times.bolt;
|
||||
if (f >= 0 && f < times.flash) { ctx.fillStyle = `rgba(255,255,255,${1 - f / times.flash})`; ctx.fillRect(0, 0, 640, 360); }
|
||||
}
|
||||
+4
-1
@@ -12,6 +12,7 @@ import * as scopa from './scopa.js';
|
||||
import * as gara from './gara.js';
|
||||
import * as micro from './micro.js';
|
||||
import * as cerbottana from './cerbottana.js';
|
||||
import { newCorsa, updateCorsa } from './corsa.js';
|
||||
import * as condor from './condor.js';
|
||||
import * as poker from './poker.js';
|
||||
|
||||
@@ -325,7 +326,7 @@ export class Game {
|
||||
return true;
|
||||
}
|
||||
// Il viaggio si chiude da solo alla fine (o uscendo prima): si arriva comunque.
|
||||
if (def?.type === 'viaggio') { this.queue.unshift(...def.complete); return true; }
|
||||
if (def?.type === 'viaggio' || def?.type === 'corsa') { this.queue.unshift(...def.complete); return true; }
|
||||
// I minigiochi: a partita finita (risultato deciso, anche se il conteggio si sta ancora mostrando) la battuta
|
||||
// di chi ha vinto; uscendo prima, quella di chi lascia.
|
||||
if (MINIGAMES[def?.type]) {
|
||||
@@ -486,6 +487,7 @@ export class Game {
|
||||
if (c) {
|
||||
if (this.story.closeups[c.id].type === 'torch') { this.updateTorch(dt); return; }
|
||||
if (this.story.closeups[c.id].type === 'viaggio') { this.updateTrip(dt); return; }
|
||||
if (this.story.closeups[c.id].type === 'corsa') { if (updateCorsa(c, this.story.closeups[c.id], dt)) this.closeupClose(); return; }
|
||||
const m = this.minigame();
|
||||
if (m) {
|
||||
m.update(c, dt);
|
||||
@@ -528,6 +530,7 @@ export class Game {
|
||||
const type = this.story.closeups[e.closeup].type;
|
||||
this.closeup = type === 'torch' ? { id: e.closeup, step: 'search', t: 0, age: 0, found: 0, dwell: 0, beam: [320, 180] }
|
||||
: type === 'viaggio' ? { id: e.closeup, t: 0, age: 0, events: [], typed: 0 }
|
||||
: type === 'corsa' ? newCorsa(e.closeup)
|
||||
// `level`: «Alla bona», «Seria» o «A fassi male», scelto nel dialogo con l'avversario.
|
||||
// `decks`: il mazzo da usare quando il suo flag è acceso (briscola: le napoletane al posto delle toscane).
|
||||
: MINIGAMES[type] ? { id: e.closeup, ...MINIGAMES[type].create(Math.floor(Math.random() * 4294967296), e.level,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { drawPesca } from './pesca-render.js';
|
||||
import { drawGara } from './gara-render.js';
|
||||
import { drawMicro } from './micro-render.js';
|
||||
import { drawCerbottana } from './cerbottana-render.js';
|
||||
import { drawCorsa } from './corsa.js';
|
||||
import { drawCondor } from './condor-render.js';
|
||||
import { drawPoker } from './poker-render.js';
|
||||
import { drawViaggio } from './viaggio.js';
|
||||
@@ -686,6 +687,16 @@ function drawCloseup(ctx, game, time) {
|
||||
drawViaggio(ctx, c, def, backgrounds.get(def.picture));
|
||||
return;
|
||||
}
|
||||
// La macchina del tempo da fuori: lo sfondo di adesso della scena, con la luce della fase del giorno.
|
||||
if (def.type === 'corsa') {
|
||||
const bg = game.backdrop(game.story.scenes[def.scene]), frames = {};
|
||||
for (const [k, src] of [[bg, bg], ...Object.entries(def.frames)]) {
|
||||
if (!backgrounds.has(src)) loadBackground(src);
|
||||
if (k !== bg) frames[k] = backgrounds.get(src);
|
||||
}
|
||||
drawCorsa(ctx, c, def, { bg: backgrounds.get(bg), frames, tint: game.phase()?.tint });
|
||||
return;
|
||||
}
|
||||
if (def.type === 'torch') {
|
||||
if (!backgrounds.has(def.picture)) loadBackground(def.picture);
|
||||
drawTorch(ctx, c, def, backgrounds.get(def.picture));
|
||||
|
||||
@@ -145,6 +145,9 @@ export class Soundscape {
|
||||
else if (kind === 'condor-palloncino') { this.noiseSound(0.12, 1800, 0.14, { pan }); this.tone(140, 60, 0.08, 0.08, 0, pan); }
|
||||
else if (kind === 'condor-plastica') { this.tone(1300, 900, 0.06, 0.05, 0, pan); this.noiseSound(0.05, 2600, 0.03, { pan }); }
|
||||
else if (kind === 'condor-lancio') this.noiseSound(0.2, 700, 0.03, { pan });
|
||||
// La macchina del tempo: il tuono del fulmine e lo sfrigolio delle sgommate di fuoco.
|
||||
else if (kind === 'corsa-tuono') { this.noiseSound(0.9, 400, 0.16, { pan }); this.tone(90, 40, 0.8, 0.1, 0, pan); }
|
||||
else if (kind === 'corsa-fuoco') this.noiseSound(1.6, 2400, 0.05, { pan });
|
||||
else if (kind === 'cerbottana-tosse') { this.noiseSound(0.18, 900, 0.08, { pan }); this.tone(260, 140, 0.12, 0.06, 0.25, pan); this.tone(240, 120, 0.1, 0.05, 0.3, pan); }
|
||||
// Le macchinine: il dito che spinge, le ruote sull'asfalto, l'urto di plastica, fuori pista, il traguardo.
|
||||
else if (kind === 'micro-spinta') { this.tone(1200, 500, 0.04, 0.04 + strength * 0.04, 0, pan); this.noiseSound(0.04, 2600, 0.04, { pan }); }
|
||||
|
||||
@@ -43,11 +43,19 @@ const torchHints = [{
|
||||
}],
|
||||
}];
|
||||
|
||||
// La macchina del tempo che corre, vista da dietro e (all'arrivo) davanti: larga `width` pixel da vicino, le ruote a
|
||||
// `track` della larghezza dal centro.
|
||||
const MACCHINA_CORSA = {
|
||||
frames: { dietro: 'assets/closeups/macchina-dietro.png', lampi: 'assets/closeups/macchina-lampi.png', davanti: 'assets/closeups/macchina-davanti.png' },
|
||||
width: 220, track: 75,
|
||||
};
|
||||
|
||||
// Il ritorno dal 1997, dalla porta o dal pulsante «Torna al 2007»: la macchina del tempo sparisce, e per rifare il
|
||||
// viaggio si richiede all'Arcu (Andrea, 29 ottobre).
|
||||
const RITORNO_2007 = [
|
||||
{ say: 'Si torna nel 2007. Ciao Vannino, ciao Pierino.' },
|
||||
{ go: 'via_liguri_magelli', at: [212, 280], face: 'down' },
|
||||
{ closeup: 'arrivo' },
|
||||
{ unset: 'macchina_trappola' },
|
||||
{ say: 'Riportata dove l\'ho presa. Se ti riviene voglia di pokerini, chiedi.', who: 'arcu', pose: 'explain' },
|
||||
];
|
||||
@@ -249,8 +257,20 @@ export const story = {
|
||||
picture: 'assets/closeups/cruscotto-tempo.png',
|
||||
display: [220, 158, 212, 62],
|
||||
date: '10/07/1997 18:30',
|
||||
complete: [{ closeup: 'partenza' }],
|
||||
},
|
||||
// La partenza vista da fuori: giù per Via Liguri Magelli, il fulmine e le sgommate di fuoco; e l'arrivo, al
|
||||
// ritorno dal 1997 (Andrea, 30 ottobre; la macchina da dietro e davanti è di Codex).
|
||||
partenza: {
|
||||
type: 'corsa', mode: 'parti', scene: 'via_liguri_magelli', ...MACCHINA_CORSA,
|
||||
path: [[215, 350, 1], [252, 192, 0.05]],
|
||||
complete: [{ go: 'barrettino_1997', at: [320, 330], face: 'up' }],
|
||||
},
|
||||
arrivo: {
|
||||
type: 'corsa', mode: 'arriva', scene: 'via_liguri_magelli', ...MACCHINA_CORSA,
|
||||
path: [[110, 470, 2.2], [252, 192, 0.05]],
|
||||
complete: [],
|
||||
},
|
||||
// Il pokerino del Barrettino con Vannino e Pierino (Andrea, 29 ottobre). [DA ANDREA: le battute]
|
||||
poker: {
|
||||
type: 'poker',
|
||||
|
||||
Reference in New Issue
Block a user