/** * MuJoCo PlayEngine: Interactive Cockpit & Game Loop Controller * Style: Fall Guys & Party Animals Jelly Bean Pop Edition * Features: * - Real-time DeepMind MuJoCo v3.3.0 WebAssembly Physics (60 FPS WebGL) * - 3-Way Camera Perspective Switcher ('cam_front', 'cam_quarter', 'cam_topdown') + [C] shortcut * - Kawaii 8-Bit Chiptune Procedural BGM (0 Bytes asset, pure Web Audio API) * - Victory & Goal Clear Banners across all 10 Mini-Games * - Coin Collection Sound FX & Star Coin Tracker (5/5) * - Full 10 Games Contextual Action Buttons & Keypad Visualizer * - 100% English Default with Korean Toggle */ // โ˜… ROOT-CAUSE FIX (HF Private Space): NO static import here. // A static import chain (app.js โ†’ mujoco_wasm_player.js โ†’ mujoco.js) means that if ANY // sub-module fails to load (e.g. private-Space auth token `__sign` not forwarded to // sub-resource requests), the browser aborts app.js entirely โ†’ empty game list & dead // START button. The physics engine is now lazily imported inside initWasmEngine(). let MujocoWasmPlayer = null; // Forward HF private-Space auth query (`__sign`) to every sub-resource URL. function withSign(url) { try { const sign = new URLSearchParams(window.location.search).get("__sign"); if (!sign) return url; return url + (url.includes("?") ? "&" : "?") + "__sign=" + encodeURIComponent(sign); } catch (e) { return url; } } window.__withSign = withSign; const I18N = { en: { brand_subtitle: "๐Ÿฌ Physical AI Sandbox & Arcade | HWIHWA LAB", menu_title: "10 Jelly Bricks", menu_desc: "Select a jelly brick to play in the sweet bouncy arena!", hud_score: "Survival Time", hud_best: "Best Record", hud_angle: "Pole Angle", hud_coins: "Star Coins", hud_demo: "Demolition Rate", hud_race: "Race Leader", hud_swing: "Swing Angle", hud_beans: "Beans Landed", hud_pinball: "Pinball Score", hud_domino: "Target Status", hud_acro: "Backflip Combo", hud_claw: "Rescue Height", keypad_title: "๐ŸŽฎ Real-time Keyboard Visualizer", cam_label: "๐ŸŽฅ View:", cam_front: "๐ŸŽฅ Front", cam_quarter: "๐Ÿ“ 45ยฐ Quarter", cam_topdown: "๐Ÿš Top-Down", cam_tip: "Press [C] to switch view", control_title: "Control Deck", control_mode_label: "Controller Mode", mode_manual: "๐ŸŽฎ Human Play", mode_ai: "๐Ÿค– Smart AI", mode_help_manual: "Use โ† and โ†’ arrow keys to balance the lollipop! (Survive 15s to Win ๐Ÿ†)", mode_help_ai: "AI PD Controller automatically maintains balance.", action_btn_label: "Quick Actions", cannon_power_label: "๐Ÿ’ฃ Cannon Power", cannon_preset_soft: "Soft (0.6x)", cannon_preset_normal: "Normal (1.0x)", cannon_preset_heavy: "Heavy (1.6x)", cannon_preset_mega: "MEGA (2.0x)", gravity_label: "Bouncy Gravity", gravity_zero: "Floating (0G)", gravity_moon: "Moon (-1.6)", gravity_earth: "Earth (-9.8)", gravity_heavy: "Heavy (-24.8)", btn_start_game: "โ–ถ START GAME (SPACE)", btn_playing: "โธ PLAYING (R to Reset)", btn_retry: "๐Ÿ”„ RETRY (R)", btn_play_again: "๐Ÿ”„ PLAY AGAIN (R)", btn_reset_toy: "๐Ÿ”„ RESET TOY (R)", btn_export_code: "๐Ÿ“‹ COPY PYTHON / XML CODE", ready_title: "READY TO PLAY!", ready_sub: "Press [SPACE] or Click [START] to Play!", overlay_btn_start: "โ–ถ START GAME", gameover_title: "OOPS! TOPPLED!", gameover_sub: "Oops! Toppled! Press [R] key to Retry", label_survived: "SURVIVED:", label_grade: "GRADE:", overlay_btn_retry: "๐Ÿ”„ RETRY (R)", overlay_btn_watch_ai: "๐Ÿค– WATCH SMART AI", overlay_btn_play_again: "๐Ÿ”„ PLAY AGAIN (R)", overlay_btn_next: "โฉ NEXT GAME", mentor_quote: "๐ŸŸข ENGINE LIVE ยท MuJoCo v3.3.0 (500Hz) ยท 30 FPS Stream ยท Zero Assets (100% Procedural) ยท Built with โค๏ธ by HWIHWA LAB", banner_badge: "ENGINE LIVE", modal_desc: "This code is a 100% standalone executable MuJoCo brick. Copy and paste it into Antigravity or Python to build games and AI agents!", modal_tab_py: "Python Script", modal_tab_xml: "MuJoCo XML (Blueprint)", modal_btn_copy: "๐Ÿ“‹ Copy to Clipboard", modal_btn_close: "Close", engine_loading_msg: "๐Ÿฌ Loading 3D Physics Engine... Please wait!" }, ko: { brand_subtitle: "๐Ÿฌ Physical AI Sandbox & Arcade | HWIHWA LAB", menu_title: "10๋Œ€ ์ ค๋ฆฌ ๋ฌผ๋ฆฌ ์›์ž", menu_desc: "ํด๋ฆญํ•˜์—ฌ ํ†ตํ†ต ํŠ€๋Š” ์Šค์œ„ํŠธ ์•„๋ ˆ๋‚˜์—์„œ ํ”Œ๋ ˆ์ดํ•˜์„ธ์š”.", hud_score: "๋ฒ„ํ‹ด ์‹œ๊ฐ„ (์ ์ˆ˜)", hud_best: "์ตœ๊ณ  ๊ธฐ๋ก", hud_angle: "๊ธฐ์šธ๊ธฐ ๊ฐ๋„", hud_coins: "ํ™ฉ๊ธˆ ์ฝ”์ธ", hud_demo: "ํƒ€์›Œ ๋ถ•๊ดด์œจ", hud_race: "์„ ๋‘ ์ฃผ์ž", hud_swing: "์Šค์œ™ ๊ฐ๋„", hud_beans: "์•ˆ์ฐฉํ•œ ์ ค๋ฆฌ", hud_pinball: "ํ•€๋ณผ ์ ์ˆ˜", hud_domino: "ํ™ฉ๊ธˆ๋ณ„ ์ƒํƒœ", hud_acro: "๋ฐฑํ…€๋ธ”๋ง ์ฝค๋ณด", hud_claw: "์ธํ˜• ๊ตฌ์ถœ ๋†’์ด", keypad_title: "๐ŸŽฎ ์‹ค์‹œ๊ฐ„ ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ์‹œ๊ฐํ™”", cam_label: "๐ŸŽฅ ์นด๋ฉ”๋ผ ๋ทฐ:", cam_front: "๐ŸŽฅ ์ •๋ฉด ๋ทฐ", cam_quarter: "๐Ÿ“ 45ยฐ ์ฟผํ„ฐ ๋ทฐ", cam_topdown: "๐Ÿš ํƒ‘๋‹ค์šด ๋ทฐ", cam_tip: "[C] ํ‚ค๋กœ ์นด๋ฉ”๋ผ ๋ทฐ ์ฆ‰์‹œ ์ „ํ™˜", control_title: "์ปจํŠธ๋กค ๋ฐํฌ", control_mode_label: "์กฐ์ž‘ ๋ชจ๋“œ ์„ ํƒ", mode_manual: "๐ŸŽฎ ์ธ๊ฐ„ ํ”Œ๋ ˆ์ด", mode_ai: "๐Ÿค– ์Šค๋งˆํŠธ AI", mode_help_manual: "โ†, โ†’ ๋ฐฉํ–ฅํ‚ค๋กœ ์นดํŠธ๋ฅผ ๋ฐ€์–ด ๋กค๋ฆฌํŒ์˜ ๊ท ํ˜•์„ ์„ธ์›Œ๋ณด์„ธ์š”! (15์ดˆ ์ƒ์กด ์‹œ ๐Ÿ† ๊ณจ๋“  ๋ฐธ๋Ÿฐ์„œ ์Šน๋ฆฌ)", mode_help_ai: "AI(PD ์ปจํŠธ๋กค๋Ÿฌ)๊ฐ€ ๋ชจํ„ฐ๋ฅผ ์ž๋™ ์ œ์–ดํ•˜์—ฌ ์™„๋ฒฝํ•œ ๊ท ํ˜•์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.", action_btn_label: "์ฆ‰๊ฐ ์‹คํ–‰ ์•ก์…˜", cannon_power_label: "๐Ÿ’ฃ ๋Œ€ํฌ ํ™”๋ ฅ ํŒŒ์›Œ", cannon_preset_soft: "์•ฝํ•˜๊ฒŒ (0.6x)", cannon_preset_normal: "๋ณดํ†ต (1.0x)", cannon_preset_heavy: "๊ฐ•ํ•˜๊ฒŒ (1.6x)", cannon_preset_mega: "์ดˆ๊ฐ•๋ ฅ MEGA (2.0x)", gravity_label: "์ค‘๋ ฅ ๊ฐ€์†๋„ ์กฐ์ ˆ (Gravity)", gravity_zero: "๋ฌด์ค‘๋ ฅ (0G)", gravity_moon: "๋‹ฌ ํ‘œ๋ฉด (-1.6)", gravity_earth: "์ง€๊ตฌ (-9.8)", gravity_heavy: "์ดˆ์ค‘๋ ฅ (-24.8)", btn_start_game: "โ–ถ ๊ฒŒ์ž„ ์‹œ์ž‘ (SPACE)", btn_playing: "โธ ํ”Œ๋ ˆ์ด ์ค‘ (Rํ‚ค๋กœ ๋ฆฌ์…‹)", btn_retry: "๐Ÿ”„ ์žฌ๋„์ „ํ•˜๊ธฐ (Rํ‚ค)", btn_play_again: "๐Ÿ”„ ๋‹ค์‹œ ํ”Œ๋ ˆ์ด (Rํ‚ค)", btn_reset_toy: "๐Ÿ”„ ์›์œ„์น˜ ๋ฆฌ์…‹ (R)", btn_export_code: "๐Ÿ“‹ ํŒŒ์ด์ฌ / XML ์ฝ”๋“œ ๋ณต์‚ฌ", ready_title: "ํ”Œ๋ ˆ์ด ์ค€๋น„ ์™„๋ฃŒ!", ready_sub: "[SPACE] ํ‚ค ๋˜๋Š” [์‹œ์ž‘] ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ํ”Œ๋ ˆ์ดํ•˜์„ธ์š”!", overlay_btn_start: "โ–ถ ๊ฒŒ์ž„ ์‹œ์ž‘", gameover_title: "์™€๋ฅด๋ฅด! ์“ฐ๋Ÿฌ์กŒ์Šต๋‹ˆ๋‹ค!", gameover_sub: "์™€๋ฅด๋ฅด ์“ฐ๋Ÿฌ์กŒ์Šต๋‹ˆ๋‹ค! [R] ํ‚ค๋กœ ์žฌ๋„์ „ํ•˜์„ธ์š”.", label_survived: "๋ฒ„ํ‹ด ์‹œ๊ฐ„:", label_grade: "๋„์ „ ๋“ฑ๊ธ‰:", overlay_btn_retry: "๐Ÿ”„ ์žฌ๋„์ „ (R)", overlay_btn_watch_ai: "๐Ÿค– ๋˜‘๋˜‘ํ•œ AI ๊ด€์ „ํ•˜๊ธฐ", overlay_btn_play_again: "๐Ÿ”„ ๋‹ค์‹œ ํ”Œ๋ ˆ์ด (R)", overlay_btn_next: "โฉ ๋‹ค์Œ ๊ฒŒ์ž„", mentor_quote: "๐ŸŸข ENGINE LIVE ยท MuJoCo v3.3.0 (500Hz) ยท 30 FPS Stream ยท Zero Assets (100% Procedural) ยท Built with โค๏ธ by HWIHWA LAB", banner_badge: "์—”์ง„ ๊ตฌ๋™ ์ค‘", modal_desc: "์ด ์ฝ”๋“œ๋Š” ์™„์ „ํžˆ ๋…๋ฆฝ ์‹คํ–‰ ๊ฐ€๋Šฅํ•œ MuJoCo ๋ฌผ๋ฆฌ ๋ฒฝ๋Œ์ž…๋‹ˆ๋‹ค. ๋ณต์‚ฌํ•ด์„œ ์•ˆํ‹ฐ๊ทธ๋ž˜๋น„ํ‹ฐ๋‚˜ ๋กœ์ปฌ ํŒŒ์ด์ฌ์— ๋ถ™์—ฌ๋„ฃ์–ด ๋‚˜๋งŒ์˜ ์›น๊ฒŒ์ž„์ด๋‚˜ AI ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๋กœ ํ™•์žฅํ•˜์„ธ์š”!", modal_tab_py: "ํŒŒ์ด์ฌ ์‹คํ–‰ ์Šคํฌ๋ฆฝํŠธ", modal_tab_xml: "MuJoCo XML ์„ค๊ณ„๋„", modal_btn_copy: "๐Ÿ“‹ ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌ", modal_btn_close: "๋‹ซ๊ธฐ", engine_loading_msg: "๐Ÿฌ 3D ๋ฌผ๋ฆฌ ์—”์ง„ ๋กœ๋”ฉ ์ค‘... ์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค ์ฃผ์„ธ์š”!" } }; // 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„๋ณ„ ๋งž์ถคํ˜• ์ธ๊ฐ„ ์ˆ˜๋™ vs ์Šค๋งˆํŠธ AI ์•ˆ๋‚ด ๋ฌธ๊ตฌ const GAME_MODE_HELP = { 1: { ko: { manual: "์ŠคํŽ˜์ด์Šค๋ฐ”๋ฅผ ๋ˆŒ๋Ÿฌ ์ ค๋ฆฌ๋นˆ์„ ํƒ€์ด๋ฐ์— ๋งž์ถฐ ๋ฐ”๋‹ฅ ๋งคํŠธ๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ๋‚™ํ•˜์‹œํ‚ค์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ 1.6์ดˆ๋งˆ๋‹ค ์ตœ์ ์˜ ๋ฆฌ๋“ฌ์œผ๋กœ ์ ค๋ฆฌ๋นˆ์„ ๊ณต์ค‘ ํˆฌํ•˜ํ•˜์—ฌ ๋งคํŠธ ํŒŒํ‹ฐ๋ฅผ ์™„์„ฑํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [Space] to drop cute jelly beans safely onto the bouncy foam pit!", ai: "Smart AI drops jelly beans in a rhythmic sequence every 1.6s to create a sweet pile!" } }, 2: { ko: { manual: "A / D ํ‚ค๋กœ ์ขŒ์šฐ ํ”Œ๋ฆฌํผ๋ฅผ ์ณ์˜ฌ๋ ค ์ ค๋ฆฌ๋ณผ๋“ค์ด ๋ฐ”๋‹ฅ์œผ๋กœ ๋–จ์–ด์ง€์ง€ ์•Š๊ฒŒ ํŠ•๊ฒจ๋‚ด์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ 10๊ฐœ ๊ตฌ์Šฌ์˜ ์‹ค์‹œ๊ฐ„ ๊ถค์ ์„ ์ถ”์ ํ•˜์—ฌ ํ”Œ๋ฆฌํผ ๋‚™ํ•˜ ๊ตฌ์—ญ ์ง„์ž… ์‹œ ์ดˆ๊ณ ์† ๋ฐ˜์‚ฌ ๋ฐ˜๊ฒฉํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [A] / [D] to flap left and right flippers and keep the gumballs bouncing!", ai: "Smart AI tracks all gumballs in real time and triggers reflex flaps whenever a ball enters the danger zone!" } }, 3: { ko: { manual: "์ŠคํŽ˜์ด์Šค๋ฐ”๋ฅผ ๋ˆŒ๋Ÿฌ ์ ค๋ฆฌ๋นˆ ์ŠคํŠธ๋ผ์ด์ปค๋กœ 1๋ฒˆ ๋„๋ฏธ๋…ธ๋ฅผ ํƒ€๊ฒฉํ•˜๊ณ  ํ™ฉ๊ธˆ๋ณ„์„ ์“ฐ๋Ÿฌ๋œจ๋ฆฌ์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ๋ฌผ๋ฆฌ ์—”์ง„ ์—ฐ์‡„ ๋ฐ˜๊ฒฝ์„ ๊ณ„์‚ฐํ•˜์—ฌ ๋„๋ฏธ๋…ธ ์—ฐ์‡„ ์ „๋„๋ฅผ ์ผ์œผํ‚ค๋Š” ์ž„ํŽ„์Šค ๋Œ์ง„์„ ์ž๋™ ์ง‘ํ–‰ํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [Space] to launch the jelly striker, topple the sweet dominoes, and hit the Gold Star!", ai: "Smart AI calculates optimal impulse physics to trigger a domino chain reaction toppling the Gold Star!" } }, 4: { ko: { manual: "W ๋˜๋Š” โ†‘ ํ‚ค๋ฅผ ์Šค์œ™ ํƒ€์ด๋ฐ์— ๋งž์ถฐ ๋ˆŒ๋Ÿฌ ๋ฐ˜๋™์„ ๊ฐ€์†ํ•˜๊ณ  360๋„ ํšŒ์ „์„ ๋‹ฌ์„ฑํ•˜์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ๊ฐ์†๋„ ๋ถ€ํ˜ธ์™€ ๋™๊ธฐํ™”๋œ ์ตœ์  ๊ณต์ง„ ํŽŒํ•‘(Resonance Pumping) ํ† ํฌ๋ฅผ ์ž๋™ ์ธ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [W] / [โ†‘] in sync with the swing rhythm to pump momentum and achieve a 360ยฐ full loop!", ai: "Smart AI applies optimal resonance pumping torque synchronized with angular velocity to conquer the 360ยฐ loop!" } }, 5: { ko: { manual: "์ŠคํŽ˜์ด์Šค๋ฐ”๋กœ 2๋‹จ ๊ด€์ ˆ์— ์˜ˆ์ธก ๋ถˆ๊ฐ€๋Šฅํ•œ ์นด์˜ค์Šค ํ† ํฌ๋ฅผ ์ฃผ์ž…ํ•˜์—ฌ 3ํšŒ์ „ ๊ณต์ค‘์ œ๋น„๋ฅผ ์„ฑ๊ณต์‹œํ‚ค์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ์ด์ค‘ ์ง„์ž์˜ ๋น„์„ ํ˜• ์œ„์ƒ ๊ณต๊ฐ„์„ ๋ถ„์„ํ•˜์—ฌ ํ™”๋ คํ•œ ๊ณต์ค‘์ œ๋น„ ์ฝค๋ณด๋ฅผ ์œ ๋„ํ•˜๋Š” ์œ„์ƒ ๊ฒฐํ•ฉ ํ† ํฌ๋ฅผ ๋ถ„์‚ฌํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [Space] to inject chaotic torque into the double pendulum and complete 3 acrobatic somersaults!", ai: "Smart AI drives non-linear phase-coupled sinusoidal torques to execute thrilling multi-rotation somersault combos!" } }, 6: { ko: { manual: "์ŠคํŽ˜์ด์Šค๋ฐ”๋กœ ํ•‘ํฌ๋นˆ๊ณผ ๋ฏผํŠธ๋นˆ์˜ ๋ ˆ์ธ๋ณด์šฐ ์›Œํ„ฐ์Šฌ๋ผ์ด๋“œ ๋ ˆ์ด์Šค๋ฅผ ์‹œ์ž‘ํ•˜์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ์–‘ ๋ ˆ์ด์„œ ๊ฐ„์˜ ๊ฑฐ๋ฆฌ ์ฐจ์ด๋ฅผ ๊ฐ์ง€ํ•˜์—ฌ ๋’ค์ฒ˜์ง„ ์ฃผ์ž์—๊ฒŒ ์Šฌ๋ฆฝ์ŠคํŠธ๋ฆผ ๋ถ€์ŠคํŠธ๋ฅผ ์ฃผ์–ด ๊ทน์ ์ธ ๋ฐ•๋น™ ์Šน๋ถ€๋ฅผ ์—ฐ์ถœํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Press [Space] to unleash the thrilling rainbow water slide race between Pink Bean and Mint Bean!", ai: "Smart AI monitors the lead gap and applies dynamic slipstream catch-up boost for a thrilling photo-finish showdown!" } }, 7: { ko: { manual: "โ†, โ†’ ๋ฐฉํ–ฅํ‚ค๋กœ ์นดํŠธ๋ฅผ ๋ฐ€์–ด ๋กค๋ฆฌํŒ์˜ ๊ท ํ˜•์„ ์„ธ์›Œ๋ณด์„ธ์š”! (15์ดˆ ์ƒ์กด ์‹œ ๐Ÿ† ๊ณจ๋“  ๋ฐธ๋Ÿฐ์„œ ์Šน๋ฆฌ)", ai: "[์‚ด์•„ ์ˆจ ์‰ฌ๋Š” ์„œ์ปค์Šค AI] ๋ฏธํ’์— ํ”๋“ค๋ฆฌ๋Š” ๋กค๋ฆฌํŒ์„ ์‹ค์‹œ๊ฐ„ LQR ์ œ์–ด๋กœ ์ขŒ์šฐ 3~4cm์”ฉ ํ†ก! ํ†ก! ์น˜๋ฉฐ ์ค‘์•™ ๊ท ํ˜•์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค." }, en: { manual: "Use โ† and โ†’ arrow keys to balance the lollipop! (Survive 15s to Win ๐Ÿ†)", ai: "[Living Circus AI] Performs real-time LQR balancing, dynamically micro-tapping 3~4cm to hold the center against carnival breezes." } }, 8: { ko: { manual: "W / A / S / D ํ‚ค๋กœ ๋‹ฌ์ฝคํ•œ ๋ฒ”ํผ์นด๋ฅผ ์กฐ์ข…ํ•˜์—ฌ ์•„๋ ˆ๋‚˜ ๊ณณ๊ณณ์˜ 5๋Œ€ ํ™ฉ๊ธˆ ๋งˆ์นด๋กฑ ๋ณ„ ์ฝ”์ธ์„ ๋ชจ๋‘ ์ˆ˜์ง‘ํ•˜์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ Pure Pursuit ์ž์œจ์ฃผํ–‰๊ณผ ์žฅ์• ๋ฌผ ํƒˆ์ถœ ๋ฆฌํ”Œ๋ ‰์Šค๋กœ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ฏธ์ˆ˜์ง‘ ํ™ฉ๊ธˆ ์ฝ”์ธ์„ ์ˆœ์ฐจ ํƒ์ƒ‰ํ•˜์—ฌ ์™„๋ฒฝ ์ฃผํ–‰ํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Drive the sweet bumper car with W / A / S / D to collect all 5 Golden Macaron Star Coins across the arena!", ai: "Smart AI executes a Pure Pursuit autonomous waypoint navigation algorithm with obstacle avoidance to hunt all 5 coins!" } }, 9: { ko: { manual: "W / S (์–ด๊นจ), A / D (ํŒ”๊ฟˆ์น˜), ์ŠคํŽ˜์ด์Šค๋ฐ” (์ž์„ ์˜จ/์˜คํ”„)๋กœ ์ ค๋ฆฌ๋นˆ ์ธํ˜•์„ ์กฐ์ค€ํ•˜์—ฌ ๊ตฌ์ถœํ•˜์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ์—ญ๊ธฐ๊ตฌํ•™ 3๋‹จ๊ณ„ ์‹œํ€€์Šค(์ ‘๊ทผ โž” ํ•˜๊ฐ• & ์ž์„ ํก์ฐฉ โž” ์ƒ์Šน)๋ฅผ ์ˆ˜ํ–‰ํ•˜์—ฌ ์ ค๋ฆฌ๋นˆ ์ธํ˜•์„ ์ž๋™ ๊ตฌ์ถœํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Control shoulder (W/S), elbow (A/D), and spacebar (magnet toggle) to rescue the Jelly Bean plushie!", ai: "Smart AI executes a 3-stage Inverse Kinematics pick-and-place sequence (approach โž” descend & magnet on โž” lift) to rescue the plushie!" } }, 10: { ko: { manual: "์šฐ์ธก ์Šฌ๋ผ์ด๋”๋กœ ๋Œ€ํฌ ํŒŒ์›Œ๋ฅผ ์กฐ์ ˆํ•˜๊ณ , ์ŠคํŽ˜์ด์Šค๋ฐ”๋ฅผ ๋ˆŒ๋Ÿฌ 9๋‹จ ๋งˆ์นด๋กฑ ํƒ€์›Œ๋ฅผ ์ผ๊ฒฉ์— ๋ถ•๊ดด์‹œํ‚ค์„ธ์š”!", ai: "์Šค๋งˆํŠธ AI๊ฐ€ ๋งˆ์นด๋กฑ ํƒ€์›Œ์˜ ์งˆ๋Ÿ‰ ์ค‘์‹ฌ(CoM)๊ณผ ํƒ„๋„ํ•™์„ ๊ณ„์‚ฐํ•˜์—ฌ 80% ์ด์ƒ ์ „๋ณต์„ ์œ ๋„ํ•˜๋Š” ์ตœ์ ์˜ ์ €๊ฒฉ ์‚ฌ๊ฒฉ์„ ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค!" }, en: { manual: "Adjust cannon power with the right slider, then press [Space] to demolish the 9-story macaron tower in one shot!", ai: "Smart AI computes tower center-of-mass and projectile ballistics, automatically firing an optimal sniper shot for total demolition!" } } }; function updateModeHelpText() { const modeHelp = document.getElementById("modeHelpText"); if (!modeHelp) return; const gameHelp = GAME_MODE_HELP[currentExampleId]; if (gameHelp && gameHelp[currentLang] && gameHelp[currentLang][currentControlMode]) { modeHelp.textContent = gameHelp[currentLang][currentControlMode]; } else { modeHelp.textContent = currentControlMode === "ai" ? (I18N[currentLang]?.mode_help_ai || I18N.en.mode_help_ai) : (I18N[currentLang]?.mode_help_manual || I18N.en.mode_help_manual); } } // ์ „์—ญ ์ƒํƒœ ๋ณ€์ˆ˜: ๊ธ€๋กœ๋ฒŒ ํ—ˆ๊น…ํŽ˜์ด์Šค(Hugging Face) ๋ฐ ํ•ด์™ธ ์‚ฌ์šฉ์ž ํ‘œ์ค€ 100% ์˜๋ฌธ(en) ๊ธฐ๋ณธ ์‹œ์ž‘ let currentLang = (function() { try { const urlParams = new URLSearchParams(window.location.search); const paramLang = urlParams.get("lang"); if (paramLang && (paramLang === "ko" || paramLang === "en")) { return paramLang; } // ๊ณผ๊ฑฐ ๋กœ์ปฌ์Šคํ† ๋ฆฌ์ง€์— ko๊ฐ€ ๋‚จ์•„์žˆ๋”๋ผ๋„ ํ”„๋กœ๊ทธ๋žจ ์ฒซ ์‹คํ–‰์€ ํ•ญ์ƒ ์˜๋ฌธ ๊ธฐ๋ณธ์œผ๋กœ ์‹œ์ž‘ // ํ˜„์žฌ ๋ธŒ๋ผ์šฐ์ € ํƒญ ์„ธ์…˜ ๋‚ด์—์„œ๋งŒ ํ† ๊ธ€ ์ƒํƒœ ์œ ์ง€ const sess = sessionStorage.getItem("jelly_lang_sess"); if (sess && (sess === "ko" || sess === "en")) { return sess; } } catch (e) {} return "en"; })(); let currentExampleId = 7; let currentControlMode = "manual"; let currentGameState = "ready"; let currentCamera = "cam_front"; let currentCodeData = null; let currentCodeTab = "py"; let examplesData = (typeof window !== "undefined" && window.EMBEDDED_EXAMPLES) ? window.EMBEDDED_EXAMPLES : {}; let activeKeySet = new Set(); let soundEnabled = true; let bgmEnabled = false; let audioCtx = null; let bgmTimer = null; let bgmStep = 0; // WebAssembly Physics Engine (1st-Class Core Engine for Static Space & Web) let wasmPlayer = null; let useWasm = true; // 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์Šน๋ฆฌ ์ถ•ํ•˜ ๋ฐฐ๋„ˆ ํ…์ŠคํŠธ ํ”„๋ฆฌ์…‹ const VICTORY_BANNERS = { 1: { icon: "๐ŸŽˆ", title: "SKYDIVING PARTY CLEARED!", sub: "All Jelly Beans landed safely on the carnival floor!" }, 2: { icon: "๐ŸŽ‰", title: "PINBALL JACKPOT!", sub: "Gumballs cascade through candy bumpers in high-score style!" }, 3: { icon: "๐ŸŒŸ", title: "DOMINO CLEARED!", sub: "All 7 Dominos Knocked Down & Golden Star Hit! (0.83s)" }, 4: { icon: "๐ŸŽก", title: "360ยฐ SWING COMPLETED!", sub: "Full kinetic somersault loop achieved in carnival sky!" }, 5: { icon: "๐Ÿคธ", title: "ACROBATIC COMBO!", sub: "Twin Gymnast Beans performed 3 consecutive backflips!" }, 6: { icon: "๐Ÿ", title: "PINK BEAN WINS! ๐Ÿ†", sub: "Champion of the Rainbow Waterpark Slide! Splash pool reached!" }, 7: { icon: "โญ", title: "GOLDEN BALANCER MASTER!", sub: "15 seconds balanced on pudding cart! Flawless control!" }, 8: { icon: "๐Ÿ†", title: "COIN DASH MASTER!", sub: "All 5 Golden Star Coins Collected! Master Bumper Driver!" }, 9: { icon: "๐Ÿงธ", title: "PLUSHIE RESCUED!", sub: "Magnetic Crane lifted the plushie bean safely out of the box!" }, 10: { icon: "๐Ÿ’ฅ", title: "TOWER ANNIHILATED!", sub: "9-Story Macaron Tower 100% Demolished! Direct cannon hit!" } }; const VICTORY_BANNERS_KR = { 1: { icon: "๐ŸŽˆ", title: "์Šค์นด์ด๋‹ค์ด๋น™ ํŒŒํ‹ฐ ์„ฑ๊ณต!", sub: "๋ชจ๋“  ์ ค๋ฆฌ๋นˆ์ด ํญ์‹ ํ•œ ์ถ•์ œ ๋ฐ”๋‹ฅ์— ์•ˆ์ „ํ•˜๊ฒŒ ์ฐฉ์ง€ํ–ˆ์Šต๋‹ˆ๋‹ค!" }, 2: { icon: "๐ŸŽ‰", title: "ํ•€๋ณผ ์žญํŒŸ ๋‹ฌ์„ฑ!", sub: "๋‹ฌ์ฝคํ•œ ์บ”๋”” ๋ฒ”ํผ๋ฅผ ํ†ต๊ณผํ•˜๋ฉฐ ์ ค๋ฆฌ๋ณผ ํญํฌ์ˆ˜๊ฐ€ ์Ÿ์•„์ง‘๋‹ˆ๋‹ค!" }, 3: { icon: "๐ŸŒŸ", title: "๋„๋ฏธ๋…ธ ์ „๋„ ์™„๋ฒฝ ์„ฑ๊ณต!", sub: "7์—ฐ์† ๋„๋ฏธ๋…ธ ์ „๋„ & ํ™ฉ๊ธˆ๋ณ„ ๋ช…์ค‘! 0.83์ดˆ ํด๋ฆฌ์–ด" }, 4: { icon: "๐ŸŽก", title: "360๋„ ์ž์ด์–ธํŠธ ์Šค์œ™ ์„ฑ๊ณต!", sub: "์ถ•์ œ ํ•˜๋Š˜์„ ๊ฐ€๋ฅด๋Š” ์™„๋ฒฝํ•œ 360๋„ ๊ณต์ง„ ํšŒ์ „ ๋ฃจํ”„ ๋‹ฌ์„ฑ!" }, 5: { icon: "๐Ÿคธ", title: "์•„ํฌ๋กœ๋ฐ”ํ‹ฑ 3์—ฐ์† ํ‚ฅ!", sub: "์Œ๋‘ฅ์ด ์ ค๋ฆฌ๋นˆ์˜ ๊ณต์ค‘ 3์—ฐ์† ๋ฐฑํ…€๋ธ”๋ง ์„œ์ปค์Šค ์„ฑ๊ณต!" }, 6: { icon: "๐Ÿ", title: "ํ•‘ํฌ๋นˆ 1์œ„ ๊ณจ์ธ! ๐Ÿ†", sub: "๋ฌด์ง€๊ฐœ ์›Œํ„ฐ ์Šฌ๋ผ์ด๋“œ ์ œํŒจ! ์ฒจ๋ฒ™ ํ’€์žฅ ๊ณจ์ธ ์„ฑ๊ณต!" }, 7: { icon: "โญ", title: "15์ดˆ ๊ณจ๋“  ๋ฐธ๋Ÿฐ์„œ ๋‹ฌ์„ฑ!", sub: "ํ‘ธ๋”ฉ ์นดํŠธ ์œ„์—์„œ ์•„์Šฌ์•„์Šฌ 15์ดˆ ๊ท ํ˜• ์œ ์ง€ ์„ฑ๊ณต!" }, 8: { icon: "๐Ÿ†", title: "5๋Œ€ ํ™ฉ๊ธˆ ์ฝ”์ธ ์ „์ฒด ์ˆ˜์ง‘!", sub: "์ถ•์ œ ๋ฒ”ํผ์นด ๋งˆ์Šคํ„ฐ ๋“œ๋ผ์ด๋ฒ„ ๋“ฑ๊ทน! ๋ชจ๋“  ์Šคํƒ€ ์ฝ”์ธ ํš๋“!" }, 9: { icon: "๐Ÿงธ", title: "์ ค๋ฆฌ๋นˆ ์ธํ˜• ๊ตฌ์ถœ ์„ฑ๊ณต!", sub: "์ž์„ ํฌ๋ ˆ์ธ ํก์ฐฉ์œผ๋กœ ํ‘น์‹ ํ•œ ์ธํ˜•๋นˆ์„ ์•ˆ์ „ํ•˜๊ฒŒ ๊ตฌ์ถœํ–ˆ์Šต๋‹ˆ๋‹ค!" }, 10: { icon: "๐Ÿ’ฅ", title: "๋งˆ์นด๋กฑ ํƒ€์›Œ 100% ์™„ํŒŒ!", sub: "9์ธต ๋งˆ์นด๋กฑ ํƒ€์›Œ ํ†ต์พŒํ•œ ์ „๋„ ์™„ํŒŒ ์„ฑ๊ณต! ๋Œ€ํฌ์•Œ ๋ช…์ค‘!" } }; // ์Šคํƒ ๋“œ์–ผ๋ก  / ์ŠคํŽ˜์ด์Šค ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ์ƒํƒœ ๋จธ์‹  ์ œ์–ด ํƒ€์ด๋จธ & ์Šค์ฝ”์–ด ์นด์šดํ„ฐ let staticLifecycleTimer = null; let staticBalanceInterval = null; let staticBeanCounter = 0; let staticPinballScore = 0; let staticSwingLoops = 0; let staticAcroCombo = 0; let staticCoinCounter = 0; let staticClawMagnet = false; let staticSurvivalTime = 0.0; // ============================================================================ // ๐Ÿš€ WASM Real-Time Physics Engine Controller (Singleton Promise) // ============================================================================ class EngineLoadingManager { constructor() { this.currentVal = 6; this.targetVal = 20; this.isSceneStable = false; this.isUiReady = false; this.isFontsReady = false; this.isReady = false; this.isDismissed = false; this.startTime = performance.now(); this.minDurationMs = 1600; // Pacing so users can comfortably perceive milestones this.holdDurationMs = 500; // Hold at 100% for 500ms so user clearly perceives completion this.timer = null; this.overlay = null; // Web Fonts loading check if (typeof document !== "undefined" && document.fonts && document.fonts.ready) { document.fonts.ready.then(() => { this.isFontsReady = true; this._checkReadiness(); }).catch(() => { this.isFontsReady = true; this._checkReadiness(); }); } else { this.isFontsReady = true; } this._startTicker(); } getOverlay() { if (!this.overlay) this.overlay = document.getElementById("engineLoadingOverlay"); return this.overlay; } setMessage(msgKo, msgEn) { const el = document.getElementById("engineLoadingMsg"); if (!el) return; const isKo = (typeof currentLang !== "undefined" ? currentLang : "ko") === "ko"; el.textContent = isKo ? msgKo : msgEn; } setProgress(target, msgKo = null, msgEn = null) { if (this.isReady) return; this.targetVal = Math.max(this.targetVal, Math.min(95, target)); if (msgKo && msgEn) { this.setMessage(msgKo, msgEn); } } notifyUiReady() { this.isUiReady = true; this.setProgress(70, "๐ŸŽจ UI ๋ฐ ๊ฒŒ์ž„ ํŒŒ๋ผ๋ฏธํ„ฐ ๋กœ๋”ฉ ์™„๋ฃŒ", "๐ŸŽจ UI & Parameters Initialized"); this._checkReadiness(); } notifySceneStable() { this.isSceneStable = true; this.setProgress(96, "โœจ 3D ๊ทธ๋ž˜ํ”ฝ ๋ฐ ๋ฌผ๋ฆฌ ๋ Œ๋”๋ง ๊ฒ€์ฆ ์™„๋ฃŒ", "โœจ 3D Graphics & Physics Verified"); this._checkReadiness(); } _checkReadiness() { if (this.isReady) return; // Check all physical and visual DOM criteria const listEl = document.getElementById("brickList"); const hasGameList = listEl && listEl.children.length >= 10; const titleEl = document.getElementById("activeTitle"); const hasHeader = titleEl && titleEl.textContent.trim().length > 0; const canvas = document.querySelector(".screen-wrapper canvas.wasm-canvas"); const hasCanvas = canvas && canvas.clientWidth > 0 && canvas.clientHeight > 0; const isPlayerReady = typeof wasmPlayer !== "undefined" && wasmPlayer && wasmPlayer.isReady && wasmPlayer.isGameLoaded && wasmPlayer.geomMeshes && wasmPlayer.geomMeshes.length > 0; // All screen elements, web fonts, and 3D frames must be 100% verified! if (this.isSceneStable && this.isFontsReady && hasGameList && hasHeader && hasCanvas && isPlayerReady) { this.complete(); } } _startTicker() { if (this.timer) return; this.timer = setInterval(() => { const elapsed = performance.now() - this.startTime; const timeRatio = Math.min(1.0, elapsed / this.minDurationMs); // Desired progress based on minimum pacing and actual milestone let desired = this.targetVal; if (!this.isReady) { // Smoothly pace progress up to 88% while WASM module downloads and compiles desired = Math.min(88, Math.max(this.targetVal, timeRatio * 85)); } else { // Once engine and all elements are ready, glide smoothly all the way to 100% desired = 100; } if (this.currentVal < desired) { // Steady, comfortable step so numbers are clearly readable (never jump wildly) const step = Math.min(1.8, Math.max(0.4, (desired - this.currentVal) * 0.12)); this.currentVal = Math.min(desired, this.currentVal + step); } const bar = document.getElementById("miniProgressBar"); const pct = document.getElementById("loadingPercent"); const rounded = Math.round(this.currentVal); if (bar) bar.style.width = `${rounded}%`; if (pct) pct.textContent = `${rounded}%`; // When reaching 100% after readiness signal if (this.isReady && this.currentVal >= 99.5) { this.currentVal = 100; if (bar) bar.style.width = "100%"; if (pct) { pct.textContent = "100%"; pct.style.color = "#10b981"; // Vibrant Emerald Green pct.style.transform = "scale(1.12)"; } this.setMessage("๐ŸŽ‰ 100% ์ค€๋น„ ์™„๋ฃŒ! ๊ฒŒ์ž„์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค!", "๐ŸŽ‰ 100% Ready! Starting 3D Arena!"); clearInterval(this.timer); this.timer = null; this._dismissWithHold(); } }, 25); } complete() { if (this.isReady) return; this.isReady = true; this.targetVal = 100; this._startTicker(); } _dismissWithHold() { if (this.isDismissed) return; this.isDismissed = true; // Hold at 100% for 500ms so user perceives completion before fade-out begins setTimeout(() => { const ov = this.getOverlay(); if (!ov) return; // Step 1: Smooth opacity fade-out (0.4s ease) ov.classList.add("fade-out"); // Step 2: Clean DOM removal after fade-out transition finishes setTimeout(() => { ov.classList.add("is-hidden"); ov.style.setProperty("display", "none", "important"); ov.style.setProperty("opacity", "0", "important"); ov.style.setProperty("visibility", "hidden", "important"); ov.style.setProperty("pointer-events", "none", "important"); try { ov.remove(); } catch (e) {} // Ensure 3D canvas and viewport dimensions are perfectly synchronized if (typeof wasmPlayer !== "undefined" && wasmPlayer && typeof wasmPlayer.handleResize === "function") { wasmPlayer.handleResize(); } }, 420); }, this.holdDurationMs); } } const engineLoadingMgr = new EngineLoadingManager(); window.__engineLoadingMgr = engineLoadingMgr; function dismissEngineLoadingOverlay() { engineLoadingMgr.complete(); } window.__dismissLoadingOverlay = dismissEngineLoadingOverlay; // ============================================================================ // ๐Ÿ”Š Kawaii Web Audio API Synthesizer (0 ๋ฐ”์ดํŠธ ๋‹ค์šด๋กœ๋“œ, ๋ธŒ๋ผ์šฐ์ € ์ˆœ์ˆ˜ ํ•ฉ์„ฑ์Œ) // ============================================================================ function initAudio() { if (!audioCtx) { const AudioContextClass = window.AudioContext || window.webkitAudioContext; if (AudioContextClass) { audioCtx = new AudioContextClass(); } } if (audioCtx && audioCtx.state === "suspended") { audioCtx.resume(); } } function playBoing() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const now = audioCtx.currentTime; const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); osc.type = "sine"; osc.frequency.setValueAtTime(220, now); osc.frequency.exponentialRampToValueAtTime(560, now + 0.12); osc.frequency.exponentialRampToValueAtTime(280, now + 0.24); gain.gain.setValueAtTime(0.3, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.24); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.24); } catch (e) {} } function playPop() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const now = audioCtx.currentTime; const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); osc.type = "sine"; osc.frequency.setValueAtTime(540, now); osc.frequency.exponentialRampToValueAtTime(140, now + 0.08); gain.gain.setValueAtTime(0.25, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.08); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.08); } catch (e) {} } function playCoinSound() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const now = audioCtx.currentTime; const notes = [987.77, 1318.51]; // B5 -> E6 ์พŒํ™œํ•œ 1-up ์ฝ”์ธ ํš๋“์Œ notes.forEach((freq, idx) => { const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); const t = now + idx * 0.08; osc.type = "sine"; osc.frequency.setValueAtTime(freq, t); gain.gain.setValueAtTime(0.25, t); gain.gain.exponentialRampToValueAtTime(0.01, t + 0.18); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(t); osc.stop(t + 0.18); }); } catch (e) {} } function playStart() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const notes = [261.63, 329.63, 392.00, 523.25]; // C4 -> E4 -> G4 -> C5 notes.forEach((freq, idx) => { const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); const now = audioCtx.currentTime + idx * 0.07; osc.type = "triangle"; osc.frequency.setValueAtTime(freq, now); gain.gain.setValueAtTime(0.2, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.18); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.18); }); } catch (e) {} } function playGameOver() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const notes = [440.00, 392.00, 349.23, 261.63]; // A4 -> G4 -> F4 -> C4 notes.forEach((freq, idx) => { const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); const now = audioCtx.currentTime + idx * 0.11; osc.type = "sawtooth"; osc.frequency.setValueAtTime(freq, now); gain.gain.setValueAtTime(0.18, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.22); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.22); }); } catch (e) {} } function playCheer() { if (!soundEnabled) return; initAudio(); if (!audioCtx) return; try { const notes = [523.25, 659.25, 783.99, 1046.50, 1318.51]; // C5 -> E5 -> G5 -> C6 -> E6 notes.forEach((freq, idx) => { const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); const now = audioCtx.currentTime + idx * 0.07; osc.type = "triangle"; osc.frequency.setValueAtTime(freq, now); gain.gain.setValueAtTime(0.28, now); gain.gain.exponentialRampToValueAtTime(0.01, now + 0.28); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(now); osc.stop(now + 0.28); }); } catch (e) {} } // ============================================================================ // ๐ŸŽต Procedural 8-Bit Chiptune Kawaii BGM (์ˆœ์ˆ˜ Web Audio API ์ฝ”๋“œ ์ƒ์„ฑ) // ============================================================================ const MELODY = [ 523.25, 659.25, 783.99, 1046.50, 880.00, 783.99, 659.25, 523.25, 587.33, 659.25, 783.99, 880.00, 783.99, 659.25, 587.33, 523.25 ]; const BASS = [ 130.81, 130.81, 164.81, 164.81, 220.00, 220.00, 174.61, 196.00 ]; function startBgm() { initAudio(); if (!audioCtx) return; if (bgmTimer) clearInterval(bgmTimer); bgmStep = 0; const stepInterval = 140; // ~107 BPM 16๋น„ํŠธ bgmTimer = setInterval(() => { if (!bgmEnabled || !audioCtx) return; try { const now = audioCtx.currentTime; // 1. ๋ฉœ๋กœ๋”” (๋ฆฌ๋“œ ์‚ฌ๊ฐํŒŒ) const noteFreq = MELODY[bgmStep % MELODY.length]; if (noteFreq) { const lead = audioCtx.createOscillator(); const leadGain = audioCtx.createGain(); lead.type = "square"; lead.frequency.setValueAtTime(noteFreq, now); leadGain.gain.setValueAtTime(0.035, now); leadGain.gain.exponentialRampToValueAtTime(0.002, now + 0.12); lead.connect(leadGain); leadGain.connect(audioCtx.destination); lead.start(now); lead.stop(now + 0.12); } // 2. ๋ฒ ์ด์Šค (ํ†ตํ†ต ํŠ€๋Š” ์‚ผ๊ฐํŒŒ) if (bgmStep % 2 === 0) { const bassFreq = BASS[(bgmStep / 2) % BASS.length]; const bass = audioCtx.createOscillator(); const bassGain = audioCtx.createGain(); bass.type = "triangle"; bass.frequency.setValueAtTime(bassFreq, now); bassGain.gain.setValueAtTime(0.08, now); bassGain.gain.exponentialRampToValueAtTime(0.005, now + 0.22); bass.connect(bassGain); bassGain.connect(audioCtx.destination); bass.start(now); bass.stop(now + 0.22); } bgmStep++; } catch (e) {} }, stepInterval); } function stopBgm() { if (bgmTimer) { clearInterval(bgmTimer); bgmTimer = null; } } function toggleBgm() { initAudio(); bgmEnabled = !bgmEnabled; const btn = document.getElementById("bgmToggleBtn"); const txt = document.getElementById("bgmText"); if (btn) btn.classList.toggle("playing", bgmEnabled); if (txt) txt.textContent = bgmEnabled ? "BGM ON" : "BGM OFF"; if (bgmEnabled) { playPop(); startBgm(); } else { stopBgm(); } } // ============================================================================ // ๐ŸŽ‰ Confetti Particle System // ============================================================================ function triggerConfetti() { const canvas = document.getElementById("confettiCanvas"); if (!canvas) return; const ctx = canvas.getContext("2d"); canvas.width = canvas.clientWidth || 640; canvas.height = canvas.clientHeight || 480; const colors = ["#ff477e", "#06d6a0", "#ffd166", "#118ab2", "#9d4edd", "#ff7b00"]; const particles = []; for (let i = 0; i < 60; i++) { particles.push({ x: canvas.width * 0.5 + (Math.random() - 0.5) * 80, y: canvas.height * 0.45, vx: (Math.random() - 0.5) * 16, vy: -Math.random() * 12 - 6, size: Math.random() * 9 + 4, color: colors[Math.floor(Math.random() * colors.length)], rot: Math.random() * 360, vrot: (Math.random() - 0.5) * 15, alpha: 1.0 }); } let start = null; function render(ts) { if (!start) start = ts; const progress = ts - start; ctx.clearRect(0, 0, canvas.width, canvas.height); let active = false; particles.forEach(p => { p.x += p.vx; p.y += p.vy; p.vy += 0.38; p.rot += p.vrot; p.alpha = Math.max(0, 1 - progress / 1500); if (p.alpha > 0) { active = true; ctx.save(); ctx.translate(p.x, p.y); ctx.rotate((p.rot * Math.PI) / 180); ctx.fillStyle = p.color; ctx.globalAlpha = p.alpha; ctx.fillRect(-p.size / 2, -p.size / 2, p.size, p.size * 0.6); ctx.restore(); } }); if (active && progress < 1600) { requestAnimationFrame(render); } else { ctx.clearRect(0, 0, canvas.width, canvas.height); } } requestAnimationFrame(render); } // ============================================================================ // ๐Ÿš€ DOM Initialization // ============================================================================ // CRITICAL FIX: