import React, {useEffect, useState} from 'react'; import { AbsoluteFill, Audio, Composition, Easing, Img, continueRender, delayRender, interpolate, registerRoot, staticFile, useCurrentFrame, useVideoConfig, } from 'remotion'; /* ───────────────── 内容 ───────────────── */ export type Hand = 'rock' | 'scissors' | 'paper'; type Props = {hand: Hand; round: number}; const HANDS: Record = { rock: {zh: '石头', file: '270a.svg', beats: '✊'}, scissors: {zh: '剪刀', file: '270c.svg', beats: '✌️'}, paper: {zh: '布', file: '1f590.svg', beats: '🖐'}, }; const TRUTH = {label: '真心话', line1: '说说看,', line2: '你多久没回家了?'}; const DARE = {label: '大冒险', line1: '现在、立刻,', line2: '给爸妈打个视频。'}; /* ───────────────── 色彩 ───────────────── */ const INK = '#0b0a0c'; const PAPER = '#f6efe4'; const AMBER = '#f5b942'; const RED = '#ff2d46'; const RED_DEEP = '#7a0d1c'; const clamp = {extrapolateLeft: 'clamp', extrapolateRight: 'clamp'} as const; const outBack = Easing.bezier(0.34, 1.56, 0.64, 1); const outExpo = Easing.bezier(0.16, 1, 0.3, 1); const inExpo = Easing.bezier(0.7, 0, 0.84, 0); /* 时间轴(30 fps, 90 帧) */ const T = { coverHold: 12, // 0–12 封面停留(coverFrame = 6) cardOut: 20, // 12–20 规则卡滑出 beats: [20, 30, 40], // 石头 / 剪刀 / 布 slam: 48, // 砸下 verdict: 56, // 底部结果条 end: 90, }; /* ───────────────── 字体 ───────────────── */ const FontLoader: React.FC = () => { const [handle] = useState(() => delayRender('fonts')); useEffect(() => { const faces = [ new FontFace('Smiley', `url(${staticFile('fonts/SmileySans-Oblique.ttf')})`), new FontFace('NotoSC', `url(${staticFile('fonts/NotoSansSC.ttf')})`), new FontFace('Poppins', `url(${staticFile('fonts/Poppins-ExtraBold.ttf')})`), ]; Promise.all(faces.map((f) => f.load())).then((loaded) => { loaded.forEach((f) => (document.fonts as unknown as {add: (f: FontFace) => void}).add(f)); continueRender(handle); }); }, [handle]); return null; }; const ZH = 'Smiley, NotoSC, "PingFang SC", sans-serif'; const BODY = 'NotoSC, "PingFang SC", sans-serif'; /* ───────────────── 背景 ───────────────── */ const Backdrop: React.FC<{heat: number}> = ({heat}) => ( {/* 对角条纹 */} {/* 暗角 */} ); /* ───────────────── 封面规则卡 ───────────────── */ const Cover: React.FC<{round: number; frame: number}> = ({frame}) => { const out = interpolate(frame, [T.coverHold, T.cardOut], [0, 1], {...clamp, easing: inExpo}); const ty = -1600 * out; const rot = -6 * out; return (
真心话大冒险 · 猜拳版
敢不敢
跟我猜一把?
先在心里出一个 · 再点进来看我出什么
IF YOU WIN
你赢 → 真心话
{TRUTH.line1}
{TRUTH.line2}
IF YOU LOSE
你输 → 大冒险
{DARE.line1}
{DARE.line2}
); }; /* ───────────────── 倒数 ───────────────── */ const Countdown: React.FC<{frame: number}> = ({frame}) => { if (frame < T.beats[0] - 4 || frame >= T.slam) return null; const words = ['石头', '剪刀', '布!']; let idx = 0; for (let i = 0; i < T.beats.length; i++) if (frame >= T.beats[i]) idx = i; const since = frame - T.beats[idx]; const pop = interpolate(since, [0, 6], [1.9, 1], {...clamp, easing: outBack}); const op = interpolate(since, [0, 2], [0, 1], clamp); // 拳头上下挥动:每拍一下 const bob = Math.sin(((frame - T.beats[0]) / 10) * Math.PI) * -90; const fistRot = Math.sin(((frame - T.beats[0]) / 10) * Math.PI) * -14; const appear = interpolate(frame, [T.beats[0] - 4, T.beats[0]], [0, 1], {...clamp, easing: outExpo}); return (
{words[idx]}
{/* 节拍点 */}
{[0, 1, 2].map((i) => ( ))}
); }; /* ───────────────── 砸下 & 结果 ───────────────── */ const Reveal: React.FC<{hand: Hand; frame: number}> = ({hand, frame}) => { if (frame < T.slam) return null; const s = frame - T.slam; const scale = interpolate(s, [0, 7], [3.2, 1], {...clamp, easing: outBack}); const op = interpolate(s, [0, 2], [0, 1], clamp); const breathe = 1 + Math.sin((s / 14) * Math.PI) * 0.025; const ringR = interpolate(s, [0, 16], [0, 1], {...clamp, easing: outExpo}); const ringO = interpolate(s, [0, 16], [0.9, 0], clamp); const lines = Array.from({length: 18}, (_, i) => i); const label = interpolate(s, [5, 11], [0, 1], {...clamp, easing: outExpo}); const stamp = interpolate(frame, [T.verdict + 10, T.verdict + 16], [0, 1], {...clamp, easing: outBack}); const h = HANDS[hand]; return ( {/* 冲击线 */} {lines.map((i) => { const a = (i / lines.length) * Math.PI * 2; const r0 = 300 + 400 * ringR; const r1 = r0 + 140 + 260 * ringR; return ; })} {/* 手 */}
{/* 我出 + 手势(上下排列,水平居中) */}
我出
{h.zh}
{/* 盖章 */}
别赖皮
); }; /* ───────────────── 主 composition ───────────────── */ export const Game: React.FC = ({hand, round}) => { const frame = useCurrentFrame(); const {fps} = useVideoConfig(); void fps; const heat = interpolate(frame, [T.beats[0], T.slam, T.slam + 10], [0.15, 0.55, 0.85], clamp); // 砸下时的镜头抖动 + 白闪 const s = frame - T.slam; const shakeAmp = s >= 0 ? 26 * Math.exp(-s / 3.2) : 0; const sx = shakeAmp * Math.sin(s * 12.9); const sy = shakeAmp * Math.cos(s * 9.7); const flash = s >= 0 ? interpolate(s, [0, 1, 4], [0.95, 0.6, 0], clamp) : 0; const zoom = s >= 0 ? 1 + 0.06 * Math.exp(-s / 5) : 1; return (