윷놀이 소리·움직임
- 던지기: 휙 + 가락 4개가 멍석에 떨어지는 딱딱 소리(떨어지는 순간에 맞춤), 윷·모 밝은 음, 빽도 내려가는 음, 낙 둔탁한 소리 - 가락마다 다르게 돌고 떨어진 뒤 한 번 튐, 결과 글자 튀어나옴(윷·모 빨강), 낙이면 가락 흔들림 - 말: 한 칸마다 작은 "콩"(튀는 움직임과 같은 때), 도착 시 잡기·업기·나기 소리와 고리(잡기 빨강, 나기 금색) - 잡힌 말은 움직이는 말이 도착할 때까지 남아 있다가 튀어 오르며 사라짐 - 상대·컴퓨터 차례도 화면 변화로 같은 소리·움직임, 숨은 탭의 내 차례 소리는 방 화면에 맡겨 두 번 울리지 않게 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { houseRules, optionsSummary } from './house-rules';
|
||||
import { quickStart } from './quick';
|
||||
import { HOP_MS, moveSound, throwSound } from './sound';
|
||||
|
||||
type From = number | 'home';
|
||||
/** A source the player can pick: a stack (`"7"`, or `"7#2"` when stacks stand apart on 7) or the waiting pieces (`"home"`). */
|
||||
@@ -110,13 +111,21 @@ const CSS = `
|
||||
.yut-sticks { width: 120px; height: 80px; flex: none; overflow: visible; }
|
||||
.yut-result { font-size: 2rem; font-weight: 900; min-width: 3ch; }
|
||||
.yut-toss .yut-stick { transform-box: fill-box; transform-origin: center; animation: yut-toss .8s cubic-bezier(.25,.7,.35,1) both; animation-delay: var(--d, 0ms); }
|
||||
@keyframes yut-toss { 0% { transform: translateY(0) rotate(0deg); } 45% { transform: translateY(-34px) rotate(260deg); } 75% { transform: translateY(2px) rotate(350deg); } 100% { transform: translateY(0) rotate(360deg); } }
|
||||
@keyframes yut-toss { 0% { transform: translateY(0) rotate(0deg); } 45% { transform: translateY(-34px) rotate(calc(var(--spin, 360deg) * .72)); } 75% { transform: translateY(2px) rotate(calc(var(--spin, 360deg) * .97)); } 88% { transform: translateY(-3px) rotate(var(--spin, 360deg)); } 100% { transform: translateY(0) rotate(var(--spin, 360deg)); } }
|
||||
.yut-nak { animation: anim-shake .45s ease both; }
|
||||
.yut-result.big { color: var(--danger); }
|
||||
/* Caught pieces stay put until the mover lands on them, then jump off and vanish. */
|
||||
.yut-caught { transform-box: fill-box; transform-origin: center; animation: yut-caught .5s ease-in both; animation-delay: var(--d, 0ms); pointer-events: none; }
|
||||
@keyframes yut-caught { 0% { transform: none; opacity: 1; } 35% { transform: translateY(-6px) rotate(-25deg) scale(1.1); opacity: 1; } 100% { transform: translateY(4px) rotate(-70deg) scale(.3); opacity: 0; } }
|
||||
/* One ripple where the piece landed (a bigger golden one when it went home). */
|
||||
.yut-ring { transform-box: fill-box; transform-origin: center; animation: yut-ring .55s ease-out both; animation-delay: var(--d, 0ms); pointer-events: none; }
|
||||
@keyframes yut-ring { 0% { opacity: 0; transform: scale(.5); } 10% { opacity: .9; } 100% { opacity: 0; transform: scale(1.7); } }
|
||||
@keyframes yut-glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .0); } 50% { box-shadow: 0 0 0 5px rgba(245, 158, 11, .35); } }
|
||||
@keyframes yut-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
|
||||
@keyframes yut-hop { 0% { transform: translateY(0); } 50% { transform: translateY(-5px); } 100% { transform: translateY(0); } }
|
||||
@keyframes yut-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
|
||||
.yut-can { animation: yut-pulse 1s ease-in-out infinite; }
|
||||
.yut-hop { transform-box: fill-box; transform-origin: center bottom; animation: yut-hop .17s ease-out; }
|
||||
.yut-hop { transform-box: fill-box; transform-origin: center bottom; animation: yut-hop .17s ease-out; pointer-events: none; }
|
||||
.yut-pop { transform-box: fill-box; transform-origin: center; animation: yut-pop .25s ease-out both; }
|
||||
.yut-hit { cursor: pointer; outline: none; }
|
||||
.yut-hit .yut-focus { opacity: 0; }
|
||||
@@ -127,6 +136,7 @@ const CSS = `
|
||||
.yut-badge { display: inline-block; border-radius: 999px; padding: 0 8px; font-weight: 800; font-size: .78rem; color: #fff; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.yut-toss .yut-stick, .yut-can, .yut-hop, .yut-pop, .yut-tray-btn.can { animation: none; }
|
||||
.yut-caught, .yut-ring { display: none; }
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -175,9 +185,9 @@ function TokenIcon({ side, team, size = 22 }: { side: number; team: boolean; siz
|
||||
}
|
||||
|
||||
/** One 윷가락: 배(flat side, light) or 등(round side, dark with marks). Stick 0 carries the 빽도 mark on its flat side. */
|
||||
function Stick({ x, flat, marked, delay }: { x: number; flat: boolean; marked: boolean; delay: number }) {
|
||||
function Stick({ x, flat, marked, delay, spin = 360 }: { x: number; flat: boolean; marked: boolean; delay: number; spin?: number }) {
|
||||
return (
|
||||
<g className="yut-stick" style={{ ['--d' as string]: `${delay}ms` }}>
|
||||
<g className="yut-stick" style={{ ['--d' as string]: `${delay}ms`, ['--spin' as string]: `${spin}deg` }}>
|
||||
<rect x={x} y={8} width={18} height={64} rx={9} fill={flat ? '#f6e4b8' : '#a86b2d'} stroke={flat ? '#9a7432' : '#5c3713'} strokeWidth={2} />
|
||||
{flat ? (
|
||||
<>
|
||||
@@ -195,6 +205,9 @@ function Stick({ x, flat, marked, delay }: { x: number; flat: boolean; marked: b
|
||||
);
|
||||
}
|
||||
|
||||
/** Each stick turns a different amount in the air (whole turns, so the face shown is the one thrown). */
|
||||
const SPINS = [360, -360, 720, -360];
|
||||
|
||||
function Sticks({ view: v, players }: { view: YutView; players: Record<string, PublicUser> }) {
|
||||
const lt = v.lastThrow;
|
||||
const [tossing, setTossing] = useState(false);
|
||||
@@ -213,17 +226,19 @@ function Sticks({ view: v, players }: { view: YutView; players: Record<string, P
|
||||
<div className="yut-sticks-box">
|
||||
<svg className={`yut-sticks${tossing ? ' yut-toss' : ''}`} viewBox="0 0 120 80" role="img" aria-label={lt ? `${nick(players, lt.player)}님이 던진 윷: ${lt.result === 'nak' ? '낙' : THROW_KO[lt.result]}` : '윷가락 네 개'}>
|
||||
{lt?.result === 'nak' ? (
|
||||
<g opacity={0.45} transform="rotate(-18 60 40)">
|
||||
{[0, 1, 2, 3].map((i) => (
|
||||
<Stick key={i} x={8 + i * 27} flat={i % 2 === 0} marked={false} delay={i * 40} />
|
||||
))}
|
||||
<g key={`nak${lt.no}`} className={tossing ? undefined : 'yut-nak'}>
|
||||
<g opacity={0.45} transform="rotate(-18 60 40)">
|
||||
{[0, 1, 2, 3].map((i) => (
|
||||
<Stick key={i} x={8 + i * 27} flat={i % 2 === 0} marked={false} delay={i * 40} spin={SPINS[i]!} />
|
||||
))}
|
||||
</g>
|
||||
</g>
|
||||
) : (
|
||||
sticks.map((f, i) => <Stick key={i} x={8 + i * 27} flat={f} marked={i === 0 && v.options.backdo} delay={i * 40} />)
|
||||
sticks.map((f, i) => <Stick key={i} x={8 + i * 27} flat={f} marked={i === 0 && v.options.backdo} delay={i * 40} spin={SPINS[i]!} />)
|
||||
)}
|
||||
</svg>
|
||||
<div>
|
||||
<div className="yut-result" aria-hidden>
|
||||
<div key={tossing ? 'toss' : `r${lt?.no ?? 0}`} className={`yut-result${lt && !tossing ? ' anim-pop' : ''}${lt && (lt.result === 'yut' || lt.result === 'mo') ? ' big' : ''}`} aria-hidden>
|
||||
{label}
|
||||
</div>
|
||||
{lt && !tossing && <div className="small muted">{nick(players, lt.player)}님</div>}
|
||||
@@ -255,6 +270,7 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
const [announce, setAnnounce] = useState('');
|
||||
const [anim, setAnim] = useState<Anim | null>(null);
|
||||
const [flash, setFlash] = useState<{ text: string; at: [number, number]; key: number } | null>(null);
|
||||
const [landing, setLanding] = useState<{ no: number; at: [number, number]; delayMs: number; goal: boolean; victims: { side: number; count: number }[] } | null>(null);
|
||||
const lastMoveNo = useRef(v.lastMove?.no ?? 0);
|
||||
const lastThrowNo = useRef(v.lastThrow?.no ?? 0);
|
||||
const prevCurrent = useRef(v.current);
|
||||
@@ -289,7 +305,7 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
lastThrowNo.current = lt.no;
|
||||
const who = lt.player === me ? '내가' : `${nick(players, lt.player)}님이`;
|
||||
setAnnounce(lt.result === 'nak' ? `${who} 던진 윷이 판 밖으로 떨어졌어요(낙).` : `${who} ${THROW_KO[lt.result]}를 던졌어요.`);
|
||||
sounds.stone();
|
||||
throwSound(lt.result, !reducedMotion());
|
||||
}
|
||||
}, [v.lastThrow?.no]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
@@ -309,9 +325,13 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
const text = caught ? '잡았다!' : m.to === 'goal' ? '났다!' : m.stacked ? '업었다!' : null;
|
||||
if (text) setFlash({ text, at: end, key: m.no });
|
||||
if (caught) haptic([40, 30, 40]);
|
||||
if (reducedMotion()) return;
|
||||
const pts: [number, number][] = [m.from === 'home' ? HOME_PT : POS[m.from]!, ...m.path.map((n) => POS[n]!)];
|
||||
if (m.to === 'goal') pts.push(HOME_PT);
|
||||
const still = reducedMotion();
|
||||
moveSound(pts.length - 1, caught ? 'capture' : m.to === 'goal' ? 'goal' : m.stacked ? 'stack' : 'plain', !still);
|
||||
// Landing effects (ripple, caught pieces jumping off) wait for the hopping piece.
|
||||
setLanding({ no: m.no, at: end, delayMs: still ? 0 : (pts.length - 1) * HOP_MS, goal: m.to === 'goal', victims: m.captured });
|
||||
if (still) return;
|
||||
setAnim({ no: m.no, pts, i: 0, side: m.side, count: m.count, to: m.to, caught: caught > 0 });
|
||||
}, [v.lastMove?.no]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
@@ -325,6 +345,12 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
return () => clearTimeout(t);
|
||||
}, [anim]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!landing) return;
|
||||
const t = setTimeout(() => setLanding((l) => (l && l.no === landing.no ? null : l)), landing.delayMs + 700);
|
||||
return () => clearTimeout(t);
|
||||
}, [landing]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!flash) return;
|
||||
const t = setTimeout(() => setFlash(null), 1100);
|
||||
@@ -334,7 +360,8 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
useEffect(() => {
|
||||
if (v.current !== prevCurrent.current && v.current === me && v.phase !== 'finished') {
|
||||
haptic(40);
|
||||
sounds.myTurn();
|
||||
// A hidden tab gets the chime from the room page.
|
||||
if (document.visibilityState !== 'hidden') sounds.myTurn();
|
||||
}
|
||||
prevCurrent.current = v.current;
|
||||
}, [v.current]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
@@ -462,6 +489,25 @@ function YutBoard({ view: v, me, players, act, pending, deadline }: BoardProps<Y
|
||||
)}
|
||||
</g>
|
||||
)}
|
||||
{landing &&
|
||||
landing.victims.map((c, k) => (
|
||||
<g key={`c${landing.no}-${k}`} className="yut-caught" style={{ ['--d' as string]: `${landing.delayMs}ms` }}>
|
||||
<Token side={c.side} team={v.team} x={landing.at[0] + (k - (landing.victims.length - 1) / 2) * 5} y={landing.at[1]} r={4.2} count={c.count} />
|
||||
</g>
|
||||
))}
|
||||
{landing && (
|
||||
<circle
|
||||
key={`r${landing.no}`}
|
||||
className="yut-ring"
|
||||
style={{ ['--d' as string]: `${landing.delayMs}ms` }}
|
||||
cx={landing.at[0]}
|
||||
cy={landing.at[1]}
|
||||
r={landing.goal ? 8 : 6}
|
||||
fill="none"
|
||||
stroke={landing.goal ? '#fbbf24' : landing.victims.length ? 'var(--danger)' : 'var(--focus)'}
|
||||
strokeWidth={landing.goal ? 1.6 : 1.1}
|
||||
/>
|
||||
)}
|
||||
{anim && (
|
||||
<g key={`${anim.no}-${anim.i}`} className="yut-hop">
|
||||
<Token side={anim.side} team={v.team} x={anim.pts[anim.i]![0]} y={anim.pts[anim.i]![1]} r={4.4} count={anim.count} />
|
||||
|
||||
72
apps/web/src/games/yut/sound.ts
Normal file
72
apps/web/src/games/yut/sound.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 윷놀이 소리: 나무 윷가락이 멍석에 떨어지는 소리, 말 한 칸씩 콩콩, 잡기·업기·나기.
|
||||
* Everything is played from view changes (mine, other players' and the computer's turns alike);
|
||||
* the site volume is applied inside feedback.ts.
|
||||
*/
|
||||
import type { Throw } from '@bg/games/yut';
|
||||
import { noise, tone } from '../../lib/feedback';
|
||||
|
||||
/** When the tossed sticks hit the mat (ms), matching `yut-toss` in index.tsx (bounce at 75% of 0.8s). */
|
||||
export const STICKS_LAND_MS = 600;
|
||||
/** One hop of a piece along its path (ms), matching the board animation. */
|
||||
export const HOP_MS = 170;
|
||||
|
||||
/** One wooden stick hitting the mat: a short dry knock. */
|
||||
function knock(delay: number, pitch: number, gain = 1): void {
|
||||
tone(420 * pitch, 40, 'triangle', 0.12 * gain, delay, { slideTo: 300 * pitch });
|
||||
noise(32, 0.09 * gain, delay, 'bandpass', 1700 * pitch, 1.2);
|
||||
}
|
||||
|
||||
/** A small piece hopping one node: soft "콩". */
|
||||
function hop(delay: number, gain = 1): void {
|
||||
tone(640, 35, 'triangle', 0.07 * gain, delay, { slideTo: 520 });
|
||||
noise(20, 0.035 * gain, delay, 'bandpass', 2200, 1.4);
|
||||
}
|
||||
|
||||
/**
|
||||
* The sticks: a swish as they leave the hand, four knocks as they land (staggered like the animation), then a
|
||||
* short call for the result. `toss` = false when the animation is off (reduced motion): no swish, no wait.
|
||||
*/
|
||||
export function throwSound(result: Throw | 'nak', toss: boolean): void {
|
||||
const land = toss ? STICKS_LAND_MS : 0;
|
||||
if (toss) noise(260, 0.05, 0, 'bandpass', 700, 0.7);
|
||||
if (result === 'nak') {
|
||||
// Off the mat: one dull thud and a sorry low note.
|
||||
noise(120, 0.12, land, 'lowpass', 500);
|
||||
tone(220, 260, 'triangle', 0.07, land + 120, { slideTo: 150 });
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < 4; i++) knock(land + i * 40 + (i % 2) * 12, 1 + ((i * 7) % 5) * 0.05, 0.8 + (i % 2) * 0.2);
|
||||
const call = land + 220;
|
||||
if (result === 'yut' || result === 'mo') {
|
||||
// 한 번 더! a bright rising run (모 a step higher).
|
||||
const base = result === 'mo' ? [659, 880, 1046, 1318] : [587, 784, 988];
|
||||
base.forEach((f, i) => tone(f, 110, 'triangle', 0.08, call + i * 70));
|
||||
} else if (result === 'backdo') {
|
||||
// 빽도: a little slide back down.
|
||||
tone(700, 220, 'sine', 0.08, call, { slideTo: 350 });
|
||||
}
|
||||
}
|
||||
|
||||
/** A piece moved `steps` nodes: one hop each, then the landing (capture / 업기 / 나기 on the last one). */
|
||||
export function moveSound(steps: number, landing: 'plain' | 'capture' | 'stack' | 'goal', animated: boolean): void {
|
||||
const gap = animated ? HOP_MS : 0;
|
||||
const n = animated ? Math.max(1, steps) : 1;
|
||||
for (let i = 1; i < n; i++) hop(i * gap, 0.8);
|
||||
const at = animated ? n * gap : 0;
|
||||
if (landing === 'capture') {
|
||||
// Landing on them, then the caught pieces knocked off the board.
|
||||
hop(at, 1.3);
|
||||
tone(560, 70, 'square', 0.05, at + 40);
|
||||
tone(280, 150, 'triangle', 0.11, at + 90);
|
||||
noise(140, 0.06, at + 110, 'bandpass', 900, 0.6);
|
||||
} else if (landing === 'stack') {
|
||||
// 업기: two pieces clicking together.
|
||||
hop(at, 1.2);
|
||||
hop(at + 80, 1);
|
||||
tone(988, 60, 'triangle', 0.06, at + 80);
|
||||
} else if (landing === 'goal') {
|
||||
hop(at, 1);
|
||||
[523, 659, 784, 1046].forEach((f, i) => tone(f, 120, 'triangle', 0.08, at + 60 + i * 65));
|
||||
} else hop(at, 1.3);
|
||||
}
|
||||
@@ -241,7 +241,8 @@ interface YutResult {
|
||||
- 조작: 결과 칩을 먼저 누르고 → 움직일 수 있는 말이 반짝이고 → 말을 누르면 도착 자리가 표시되고 → 다시 누르면 확정(오조작 방지 2단계). 결과가 1개이고 움직일 말이 1가지면 "자동 이동" 버튼 강조.
|
||||
- 지역 룰 선택(7.1): 고른 말에 다른 길이나 따로 두기가 있으면 [이동하기] 위에 "갈 길 고르기"(지름길/바깥 길, 방에서는 참먹이 쪽/찌모 쪽, 도착 자리와 잡기 표시)와 "업기(함께 움직임)/따로 두기" 버튼이 나오고, 점선 미리보기가 고른 대로 바뀐다. 말을 한 번 더 누르면 고른 대로 움직인다. 따로 선 무더기는 한 자리에 나란히 작게 그린다. 던진 순서대로(`useOrder = thrown`)면 맨 앞 결과 칩만 눌린다.
|
||||
- 합법 수 하이라이트: 도착 자리에 점선 경로 미리보기. 잡을 수 있으면 빨간 테두리 "잡기!", 업기면 "업기", 나면 "날!" 배지.
|
||||
- 애니메이션: 윷가락 4개가 공중에서 돌다 떨어지는 0.8초 애니메이션(서버 결과를 받은 뒤 재생, 결과 조작 불가). 말은 칸마다 통통 튀며 이동. 잡힌 말은 대기 자리로 날아감.
|
||||
- 애니메이션: 윷가락 4개가 공중에서 가락마다 다르게 돌다 떨어져 한 번 튀는 0.8초 애니메이션(서버 결과를 받은 뒤 재생, 결과 조작 불가), 결과 글자는 톡 튀어나오고 윷·모는 빨간 글씨, 낙이면 가락이 흔들린다. 말은 칸마다 통통 튀며 이동하고(한 칸 0.17초), 도착하면 자리에 고리가 한 번 퍼진다(잡기 빨강, 나기 금색). 잡힌 말은 움직이는 말이 도착할 때까지 그 자리에 있다가 튀어 오르며 돌아 사라진다. 상대·컴퓨터 차례도 똑같이 움직인다.
|
||||
- 효과음(화면 변화 기준, 한 번만, 사이트 음량을 따름, `apps/web/src/games/yut/sound.ts`): 던질 때 휙 + 가락 4개가 멍석에 떨어지는 딱딱 소리(애니메이션과 같은 때), 윷·모는 밝게 올라가는 음(한 번 더), 빽도는 미끄러져 내려가는 음, 낙은 둔탁한 소리. 말이 한 칸 갈 때마다 작은 "콩", 도착할 때 잡기(부딪히고 떨어지는 소리)·업기(두 번 딸깍)·나기(짧게 올라가는 음). 내 차례 알림은 보이는 화면에서만 게임이 내고, 숨은 탭은 방 화면이 낸다.
|
||||
- 초보자 도움말: "규칙 보기"에 그림으로 도~모, 지름길(모서리·방에 멈추면 꺾임), 업기, 잡기 설명. 힌트 옵션을 켜면 추천 수(8.5 우선순위)를 연하게 표시.
|
||||
- 접근성: 결과 칩에 글자(도/개/걸/윷/모/빽도)와 이동 칸 수(1~5, −1)를 함께. 색약 대비로 편마다 모양(원·세모·네모·별) 구분.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user