hwihwalab's picture
feat(wasm): deploy real 60FPS MuJoCo WebAssembly physics engine (Zero Docker, Zero GIFs)
53285d4 verified
Raw History Blame Contribute Delete
96.5 kB
/** * 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 <strong>[C]</strong> 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: "<strong>[C]</strong> ํ‚ค๋กœ ์นด๋ฉ”๋ผ ๋ทฐ ์ฆ‰์‹œ ์ „ํ™˜", 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: <script type="module"> is deferred โ€” DOMContentLoaded may have // already fired before module evaluation. Use readyState check to guarantee init. function safeStep(name, fn) { try { return fn(); } catch (e) { console.error(`[initApp] step '${name}' failed:`, e); if (window.__bootError) window.__bootError(`${name}: ${e && e.message ? e.message : e}`); } } let __appInitStarted = false; async function initApp() { if (__appInitStarted) return; __appInitStarted = true; // Each step isolated: one failure can never block the game list from rendering. safeStep("language", setupLanguageToggle); safeStep("sound", setupSoundToggle); safeStep("bgm", setupBgmToggle); safeStep("fullscreen", setupFullscreenToggle); safeStep("keyboard", setupKeyboardListeners); safeStep("widescreen", setupAutoWidescreen); try { await loadExamples(); } catch (e) { console.error("[initApp] loadExamples failed:", e); if (window.__bootError) window.__bootError("loadExamples: " + (e && e.message ? e.message : e)); } safeStep("translations", applyTranslations); safeStep("actionButtons", updateActionButtons); safeStep("gameStateUI", () => updateGameStateUI()); if (typeof window !== 'undefined' && window.__engineLoadingMgr) { window.__engineLoadingMgr.notifyUiReady(); } // Catastrophic 40s timeout: warn user rather than abruptly hiding loading screen while elements are missing setTimeout(() => { if (typeof window !== 'undefined' && window.__engineLoadingMgr && !window.__engineLoadingMgr.isReady) { console.warn("[initApp] 40s timeout reached without stable scene rendering."); engineLoadingMgr.setMessage("โš ๏ธ ๋„คํŠธ์›Œํฌ ๋กœ๋”ฉ ์ง€์—ฐ ์ค‘... ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•ด ์ฃผ์„ธ์š”.", "โš ๏ธ Network delay... Please refresh if needed."); } }, 40000); } window.__jellyInitApp = initApp; if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initApp); } else { // DOM already parsed (module deferred execution) โ€” init immediately initApp(); } function setupAutoWidescreen() { try { if (window.resizeTo && screen.availWidth && screen.availHeight) { if (window.outerWidth < screen.availWidth * 0.8) { window.moveTo(0, 0); window.resizeTo(screen.availWidth, screen.availHeight); } } } catch (e) {} } function setupFullscreenToggle() { const fsBtn = document.getElementById("fullscreenBtn"); const fsText = document.getElementById("fsText"); if (!fsBtn) return; function updateFsText() { if (document.fullscreenElement) { if (fsText) fsText.textContent = "NORMAL"; fsBtn.title = currentLang === "ko" ? "์ผ๋ฐ˜ ํ™”๋ฉด์œผ๋กœ ๋ณต๊ท€ [F]" : "Exit Widescreen Fullscreen [F]"; } else { if (fsText) fsText.textContent = "WIDE"; fsBtn.title = currentLang === "ko" ? "16:9 ์™€์ด๋“œ ์ „์ฒดํ™”๋ฉด ์ „ํ™˜ [F]" : "Toggle 16:9 Widescreen Fullscreen [F]"; } } fsBtn.addEventListener("click", () => { playPop(); if (!document.fullscreenElement) { if (document.documentElement.requestFullscreen) { document.documentElement.requestFullscreen().catch(() => {}); } } else { if (document.exitFullscreen) { document.exitFullscreen().catch(() => {}); } } }); document.addEventListener("fullscreenchange", updateFsText); updateFsText(); } function setupLanguageToggle() { const toggleBtn = document.getElementById("langToggleBtn"); if (!toggleBtn) return; const langText = document.getElementById("langText"); if (langText) langText.textContent = currentLang.toUpperCase(); toggleBtn.title = currentLang === "en" ? "ํ•œ๊ตญ์–ด๋กœ ๋ณ€๊ฒฝ (Switch to Korean)" : "Switch to English"; toggleBtn.addEventListener("click", () => { currentLang = currentLang === "en" ? "ko" : "en"; try { sessionStorage.setItem("jelly_lang_sess", currentLang); localStorage.removeItem("jelly_lang"); // ๊ธฐ์กด ko ๊ณ ์ • ์บ์‹œ ์ •๋ฆฌ } catch (e) {} if (langText) langText.textContent = currentLang.toUpperCase(); toggleBtn.title = currentLang === "en" ? "ํ•œ๊ตญ์–ด๋กœ ๋ณ€๊ฒฝ (Switch to Korean)" : "Switch to English"; applyTranslations(); renderExampleList(); updateUIHeader(); updateActionButtons(); updateGameStateUI(); playPop(); }); } function setupSoundToggle() { const toggleBtn = document.getElementById("soundToggleBtn"); if (!toggleBtn) return; toggleBtn.addEventListener("click", () => { initAudio(); soundEnabled = !soundEnabled; toggleBtn.classList.toggle("muted", !soundEnabled); toggleBtn.innerHTML = soundEnabled ? '๐Ÿ”Š <span id="soundText">SFX ON</span>' : '๐Ÿ”‡ <span id="soundText">SFX OFF</span>'; if (soundEnabled) playPop(); }); } function setupBgmToggle() { const toggleBtn = document.getElementById("bgmToggleBtn"); if (!toggleBtn) return; toggleBtn.addEventListener("click", () => { toggleBgm(); }); } function applyTranslations() { const dict = I18N[currentLang] || I18N.en; document.querySelectorAll("[data-i18n]").forEach(elem => { const key = elem.getAttribute("data-i18n"); if (dict[key]) { if (dict[key].includes("<")) { elem.innerHTML = dict[key]; } else { elem.textContent = dict[key]; } } }); // ๋ชจ๋“œ ๋„์›€๋ง ๋ฐ ์ธ๋””์ผ€์ดํ„ฐ ์ฆ‰์‹œ ๊ฐฑ์‹  (๋‹จ์ผ ์ด๋ชจ์ง€ ์•„์ด์ฝ˜ ์ ์šฉ) updateModeHelpText(); const indicatorIcon = document.getElementById("indicatorIcon"); const indicatorText = document.getElementById("indicatorText"); if (indicatorIcon) { indicatorIcon.textContent = currentControlMode === "ai" ? "๐Ÿค–" : "๐ŸŽฎ"; } if (indicatorText) { indicatorText.textContent = currentControlMode === "ai" ? (currentLang === "ko" ? "AI ์ž์œจ ์ œ์–ด ๋ชจ๋“œ" : "Autonomous AI Mode") : (currentLang === "ko" ? "์ธ๊ฐ„ ์ˆ˜๋™ ์กฐ์ž‘ ๋ชจ๋“œ" : "Human Manual Mode"); } } // ============================================================================ // ๐ŸŽฅ 3-Way Camera Controller // ============================================================================ async function setCamera(camName) { playPop(); currentCamera = camName; document.getElementById("btnCamFront")?.classList.toggle("active", camName === "cam_front"); document.getElementById("btnCamQuarter")?.classList.toggle("active", camName === "cam_quarter"); document.getElementById("btnCamTopdown")?.classList.toggle("active", camName === "cam_topdown"); if (useWasm && wasmPlayer) { wasmPlayer.setCamera(camName); return; } try { await fetch("/api/camera", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ camera: camName }) }); } catch (err) { console.error("Camera switch error:", err); } } function cycleCamera() { const order = ["cam_front", "cam_quarter", "cam_topdown"]; const curIdx = order.indexOf(currentCamera); const nextCam = order[(curIdx + 1) % order.length]; setCamera(nextCam); } // ============================================================================ // ๐Ÿš€ WASM Real-Time Physics Engine Controller (Singleton Promise) // ============================================================================ let wasmInitPromise = null; async function initWasmEngine() { if (wasmPlayer && wasmPlayer.isReady) { return wasmPlayer; } if (wasmInitPromise) return wasmInitPromise; wasmInitPromise = (async () => { const container = document.querySelector('.screen-wrapper'); const streamImg = document.getElementById("mjpegStream"); if (streamImg) streamImg.style.display = "none"; const statusLabel = document.getElementById("streamStatus"); if (statusLabel) statusLabel.textContent = "WASM 60FPS"; engineLoadingMgr.setProgress(25, "๐Ÿฌ 3D ๋ฌผ๋ฆฌ ์—”์ง„ ์ปค๋„ ์ดˆ๊ธฐํ™” ์ค‘...", "๐Ÿฌ Initializing 3D Physics Engine..."); try { if (!MujocoWasmPlayer) { engineLoadingMgr.setProgress(50, "๐Ÿ“ฆ MuJoCo WebAssembly ๋ชจ๋“ˆ ๋กœ๋”ฉ ์ค‘...", "๐Ÿ“ฆ Loading MuJoCo WASM Module..."); const mod = await import(withSign("./mujoco_wasm_player.js?v=20261107_v30")); MujocoWasmPlayer = mod.MujocoWasmPlayer; } wasmPlayer = new MujocoWasmPlayer(container); engineLoadingMgr.setProgress(75, "โš™๏ธ 60FPS ๋ฌผ๋ฆฌ ์—ฐ์‚ฐ ์ฝ”์–ด ์ปดํŒŒ์ผ ์ค‘...", "โš™๏ธ Compiling 60FPS Physics Core..."); await wasmPlayer.init(); engineLoadingMgr.setProgress(92, "๐ŸŽจ 3D ์นด๋‹ˆ๋ฐœ ํ…Œ๋งˆํŒŒํฌ ํ™˜๊ฒฝ ๋นŒ๋“œ ์ค‘...", "๐ŸŽจ Building 3D Carnival Arena..."); wasmPlayer.onTelemetryUpdate = (t) => { updateHUD(t); if (t.victory_banner && currentGameState !== "victory") { currentGameState = "victory"; playCheer(); triggerConfetti(); updateGameStateUI(t); } }; wasmPlayer.onCoinCollected = (coins) => { playCoinSound(); triggerConfetti(); const el = document.getElementById("hudCoins"); if (el) el.textContent = coins; }; wasmPlayer.onStateChange = (state, data) => { currentGameState = state; updateGameStateUI(data); if (state === "victory") { playCheer(); triggerConfetti(); } else if (state === "gameover") { playGameOver(); } }; console.log("๐Ÿš€ MujocoWasmPlayer successfully initialized!"); return wasmPlayer; } catch (err) { console.error("โŒ Failed to initialize MujocoWasmPlayer:", err); if (window.__bootError) window.__bootError("Physics engine: " + (err && err.message ? err.message : err)); throw err; } })(); return wasmInitPromise; } function updateHUD(t) { if (!t) return; if (t.survival_time !== undefined) { const el = document.getElementById("hudScore"); if (el) el.textContent = `${t.survival_time.toFixed(2)}s`; } if (t.best_score !== undefined) { const el = document.getElementById("hudBest"); if (el) el.textContent = `${t.best_score.toFixed(2)}s`; } if (t.pole_angle_deg !== undefined) { const el = document.getElementById("hudAngle"); if (el) el.textContent = `${t.pole_angle_deg}ยฐ`; } if (t.coins_collected !== undefined) { const el = document.getElementById("hudCoins"); if (el) el.textContent = t.coins_collected; } if (t.demolition_rate !== undefined) { const el = document.getElementById("hudDemo"); if (el) el.textContent = t.demolition_rate.toFixed(1); } if (t.beans_landed !== undefined) { const el = document.getElementById("hudBeansLanded"); if (el) el.textContent = `${t.beans_landed} (${t.beans_dropped || 4} drops)`; } if (t.pinball_score !== undefined) { const el = document.getElementById("hudPinballScore"); if (el) el.textContent = t.pinball_score; } if (t.domino_cleared !== undefined) { const el = document.getElementById("hudDominoStatus"); if (el) el.textContent = t.domino_cleared ? "Cleared! (0.83s) ๐ŸŒŸ" : "Standing ๐ŸŒŸ"; } if (t.swing_angle_deg !== undefined) { const el = document.getElementById("hudSwingAngle"); if (el) el.textContent = `${t.swing_angle_deg}ยฐ (Loops: ${t.swing_loops || 0})`; } if (t.somersault_count !== undefined) { const el = document.getElementById("hudAcroCombo"); if (el) el.textContent = `${Math.min(3, t.somersault_count)} / 3 ๐Ÿคธ`; } if (t.race_leader !== undefined) { const el = document.getElementById("hudRaceLeader"); if (el) el.textContent = t.race_winner ? `${t.race_winner} Won! ๐Ÿ†` : t.race_leader; } if (t.claw_height !== undefined) { const el = document.getElementById("hudClawHeight"); if (el) el.textContent = `${t.claw_height.toFixed(2)}m`; } } // ============================================================================ // ๐ŸŽฎ ์˜ˆ์ œ ๊ด€๋ฆฌ & ์„ ํƒ (100% ๋กœ์ปฌ ๋™๋“ฑ ๋ฌผ๋ฆฌ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์ง๊ฒฐ) // ============================================================================ async function loadExamples() { // 1. EMBEDDED_EXAMPLES ๋™๊ธฐ ๋กœ๋“œ ๋ฐ ์ดˆ๊ธฐ UI ์„ธํŒ… if (typeof window.EMBEDDED_EXAMPLES !== "undefined" && Object.keys(window.EMBEDDED_EXAMPLES).length > 0) { examplesData = window.EMBEDDED_EXAMPLES; } // ๊ธฐ๋ณธ ๊ฒŒ์ž„ ID ๊ฒฐ์ • (์œ ์ € ํด๋ฆญ ๋Œ€๊ธฐ๊ฐ’ ๋˜๋Š” ํ”Œ๋ž˜๊ทธ์‹ญ 7๋ฒˆ) const pending = Number(window.__pendingSelect) || 7; currentExampleId = pending; // ์ขŒ์ธก ๊ฒŒ์ž„ ๋ฆฌ์ŠคํŠธ ๋ฐ UI ํ—ค๋” ๋™๊ธฐ ์ฆ‰๊ฐ ๋ Œ๋”๋ง renderExampleList(); updateUIHeader(); updateActionButtons(); updateGameStateUI(); if (typeof window !== 'undefined' && window.__engineLoadingMgr) { window.__engineLoadingMgr.notifyUiReady(); } // 2. ๐Ÿš€ MuJoCo WebAssembly ์‹ค์‹œ๊ฐ„ ๋ฌผ๋ฆฌ ์—”์ง„ ์ฆ‰์‹œ ๊ฐ€๋™ useWasm = true; try { await initWasmEngine(); if (wasmPlayer) { wasmPlayer.loadGame(currentExampleId); } } catch (err) { console.error("WASM startup error:", err); if (window.__engineLoadingMgr) { window.__engineLoadingMgr.setMessage("โš ๏ธ WASM ๋ฌผ๋ฆฌ ์—”์ง„ ๋กœ๋”ฉ ์˜ค๋ฅ˜", "โš ๏ธ WASM Loading Error"); window.__engineLoadingMgr.complete(); } } } function renderExampleList() { const listEl = document.getElementById("brickList"); if (!listEl) return; listEl.innerHTML = ""; for (let i = 1; i <= 10; i++) { const meta = examplesData[i]; if (!meta) continue; const item = document.createElement("div"); item.className = `brick-item ${i === currentExampleId ? "active" : ""}`; item.onclick = () => { playPop(); selectExample(i); }; const title = currentLang === "ko" ? meta.title_kr : `${i.toString().padStart(2, "0")} ยท ${meta.title}`; item.innerHTML = ` <div class="brick-item-top"> <span class="brick-num">#${i.toString().padStart(2, "0")}</span> <span class="brick-category-tag">${meta.badge}</span> </div> <div class="brick-title">${title}</div> `; listEl.appendChild(item); } } async function selectExample(id) { currentExampleId = id; renderExampleList(); updateUIHeader(); updateActionButtons(); currentGameState = "ready"; currentControlMode = "manual"; document.getElementById("btnModeManual")?.classList.add("active"); document.getElementById("btnModeAI")?.classList.remove("active"); const indicatorIcon = document.getElementById("indicatorIcon"); const indicatorText = document.getElementById("indicatorText"); if (indicatorIcon) indicatorIcon.textContent = "๐ŸŽฎ"; if (indicatorText) { indicatorText.textContent = currentLang === "ko" ? "์ธ๊ฐ„ ์ˆ˜๋™ ์กฐ์ž‘ ๋ชจ๋“œ" : "Human Manual Mode"; } updateModeHelpText(); updateGameStateUI(); // ๐Ÿš€ WASM ๋ฌผ๋ฆฌ ์—”์ง„์œผ๋กœ ์ง๊ฒฐ (์ง€์—ฐ ์ œ๋กœ, 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ 3D ๋ฌผ๋ฆฌ ์ฆ‰์‹œ ๋กœ๋“œ) if (useWasm) { if (wasmPlayer && wasmPlayer.isReady) { wasmPlayer.loadGame(id); } else { initWasmEngine().then(player => { if (player && player.isReady) player.loadGame(id); }).catch(err => { console.error("selectExample wasm load error:", err); }); } return; } } function nextExample() { const nextId = currentExampleId >= 10 ? 1 : currentExampleId + 1; selectExample(nextId); } function updateUIHeader() { const meta = examplesData[currentExampleId]; if (!meta) return; const title = currentLang === "ko" ? meta.title_kr : `${currentExampleId.toString().padStart(2, "0")} ยท ${meta.title}`; document.getElementById("activeTitle").textContent = title; document.getElementById("activeBadge").textContent = meta.badge; // 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์ „์šฉ HUD ์œ„์ ฏ ๊ฐ€์‹œ์„ฑ ์ œ์–ด const setHudDisplay = (id, show) => { const el = document.getElementById(id); if (el) el.style.display = show ? "flex" : "none"; }; const isCartpole = currentExampleId === 7; setHudDisplay("scoreHud", isCartpole); setHudDisplay("bestHud", isCartpole); setHudDisplay("angleHud", isCartpole); setHudDisplay("beanHud", currentExampleId === 1); setHudDisplay("pinballHud", currentExampleId === 2); setHudDisplay("dominoHud", currentExampleId === 3); setHudDisplay("swingHud", currentExampleId === 4); setHudDisplay("acroHud", currentExampleId === 5); setHudDisplay("raceHud", currentExampleId === 6); setHudDisplay("coinHud", currentExampleId === 8); setHudDisplay("clawHud", currentExampleId === 9); setHudDisplay("demoHud", currentExampleId === 10); // ๋ชจ๋“œ ์นด๋“œ ์ƒ์‹œ ํ™œ์„ฑํ™” (10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์ „์ฒด ์Šค๋งˆํŠธ AI ์ž์œจ์ฃผํ–‰/์˜คํ† ํ”Œ๋ ˆ์ด ์ง€์›) document.getElementById("modeCard").style.display = "flex"; document.getElementById("cannonCard").style.display = currentExampleId === 10 ? "flex" : "none"; updateModeHelpText(); } // ============================================================================ // ๐ŸŽ›๏ธ ์ƒํ™ฉ๋ณ„ 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์กฐ์ž‘ ๋ฒ„ํŠผ ๋ฐ”์ธ๋” // ============================================================================ function updateActionButtons() { const grid = document.getElementById("actionBtnGrid"); if (!grid) return; grid.innerHTML = ""; const isKo = currentLang === "ko"; if (currentExampleId === 1) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('drop_bean')"> ๐ŸŽˆ ${isKo ? "์ ค๋ฆฌ๋นˆ ๊ณต์ค‘ ํˆฌํ•˜! (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Drop Extra Bean! (Space)"} </button> <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px;"> <button class="btn-action-trigger" onclick="sendAction('bounce_cushion', -1)"> โ—€ ${isKo ? "์ขŒ์ธก ํŠ•๊ธฐ๊ธฐ (โ† / A)" : "Bounce Left (โ† / A)"} </button> <button class="btn-action-trigger" onclick="sendAction('bounce_cushion', 1)"> ${isKo ? "์šฐ์ธก ํŠ•๊ธฐ๊ธฐ โ–ถ (โ†’ / D)" : "Bounce Right โ–ถ (โ†’ / D)"} </button> </div> `; } else if (currentExampleId === 2) { grid.innerHTML = ` <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;"> <button class="btn-action-trigger" onmousedown="sendAction('flip_left')" onmouseup="sendAction('flip_stop')"> โ—€ ${isKo ? "์ขŒ์ธก ํ”Œ๋ฆฌํผ (A)" : "Left Flipper (A)"} </button> <button class="btn-action-trigger" onmousedown="sendAction('flip_right')" onmouseup="sendAction('flip_stop')"> ${isKo ? "์šฐ์ธก ํ”Œ๋ฆฌํผ โ–ถ (D)" : "Right Flipper โ–ถ (D)"} </button> </div> <button class="btn-action-trigger" style="margin-top: 6px;" onclick="sendAction('ball_rain')"> โ˜” ${isKo ? "์ ค๋ฆฌ๋ณผ ํญํฌ์ˆ˜ (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Gumball Rain (Space)"} </button> `; } else if (currentExampleId === 3) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('push_domino')"> ๐Ÿ‘‰ ${isKo ? "1๋ฒˆ ๋„๋ฏธ๋…ธ ๋ฐ€๊ธฐ! (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Strike 1st Domino! (Space)"} </button> `; } else if (currentExampleId === 4) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('swing_pump')"> ๐ŸŽก ${isKo ? "๊ทธ๋„ค ๋ฐ˜๋™ ๊ฐ€์† (W / โ†‘ / ์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Pump Momentum (W / โ†‘ / Space)"} </button> `; } else if (currentExampleId === 5) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('acrobatic_flip')"> ๐Ÿคธ ${isKo ? "์•„ํฌ๋กœ๋ฐ”ํ‹ฑ ํ‚ฅ (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Acrobatic Kick (Space)"} </button> `; } else if (currentExampleId === 6) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('start_race')"> ๐Ÿ ${isKo ? "์›Œํ„ฐ ์Šฌ๋ผ์ด๋“œ ์ถœ๋ฐœ! (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Start Slide Race! (Space)"} </button> <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px;"> <button class="btn-action-trigger" onclick="sendAction('slide_boost_pink')">${isKo ? "๐Ÿš€ ํ•‘ํฌ๋นˆ ๋ถ€์Šคํ„ฐ (A / โ†)" : "๐Ÿš€ Pink Turbo Boost (A / โ†)"}</button> <button class="btn-action-trigger" onclick="sendAction('slide_boost_mint')">${isKo ? "๐Ÿš€ ๋ฏผํŠธ๋นˆ ๋ถ€์Šคํ„ฐ (D / โ†’)" : "๐Ÿš€ Mint Turbo Boost (D / โ†’)"}</button> </div> `; } else if (currentExampleId === 7) { grid.innerHTML = ` <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;"> <button class="btn-action-trigger" onmousedown="sendAction('cart_left')" onmouseup="sendAction('cart_stop')"> โ—€ ${isKo ? "์ขŒ์ธก ์ด๋™ (A / โ†)" : "Push Left (A / โ†)"} </button> <button class="btn-action-trigger" onmousedown="sendAction('cart_right')" onmouseup="sendAction('cart_stop')"> ${isKo ? "์šฐ์ธก ์ด๋™ โ–ถ (D / โ†’)" : "Push Right โ–ถ (D / โ†’)"} </button> </div> `; } else if (currentExampleId === 8) { grid.innerHTML = ` <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;"> <button class="btn-action-trigger" onmousedown="sendAction('car_forward')" onmouseup="sendAction('car_stop')"> โ–ฒ ${isKo ? "์ „์ง„ (W / โ†‘)" : "Throttle (W / โ†‘)"} </button> <button class="btn-action-trigger" onmousedown="sendAction('car_backward')" onmouseup="sendAction('car_stop')"> โ–ผ ${isKo ? "ํ›„์ง„ (S / โ†“)" : "Reverse (S / โ†“)"} </button> <button class="btn-action-trigger" onmousedown="sendAction('car_left')" onmouseup="sendAction('car_stop')"> โ—€ ${isKo ? "์ขŒํšŒ์ „ (A / โ†)" : "Steer Left (A / โ†)"} </button> <button class="btn-action-trigger" onmousedown="sendAction('car_right')" onmouseup="sendAction('car_stop')"> ${isKo ? "์šฐํšŒ์ „ โ–ถ (D / โ†’)" : "Steer Right โ–ถ (D / โ†’)"} </button> </div> <p style="font-size: 11px; color: var(--candy-yellow); font-weight: 700; margin-top: 6px; text-align: center;"> โญ ${isKo ? "5๋Œ€ ํ™ฉ๊ธˆ ์ฝ”์ธ์„ ๋ชจ๋‘ ํš๋“ํ•˜์„ธ์š”!" : "Collect all 5 Golden Star Coins!"} </p> `; } else if (currentExampleId === 9) { grid.innerHTML = ` <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 6px;"> <button class="btn-action-trigger" onclick="sendAction('arm_shoulder_up')">${isKo ? "์–ด๊นจ ๊ด€์ ˆ โ†‘ (W / โ†‘)" : "Shoulder โ†‘ (W / โ†‘)"}</button> <button class="btn-action-trigger" onclick="sendAction('arm_shoulder_down')">${isKo ? "์–ด๊นจ ๊ด€์ ˆ โ†“ (S / โ†“)" : "Shoulder โ†“ (S / โ†“)"}</button> <button class="btn-action-trigger" onclick="sendAction('arm_elbow_up')">${isKo ? "ํŒ”๊ฟˆ์น˜ โ†— (D / โ†’)" : "Elbow โ†— (D / โ†’)"}</button> <button class="btn-action-trigger" onclick="sendAction('arm_elbow_down')">${isKo ? "ํŒ”๊ฟˆ์น˜ โ†˜ (A / โ†)" : "Elbow โ†˜ (A / โ†)"}</button> </div> <button class="btn-action-trigger" style="margin-top: 6px;" onclick="sendAction('claw_magnet_toggle')"> ๐Ÿงฒ ${isKo ? "์ž์„ ํฌ๋ ˆ์ธ ํก์ฐฉ ON/OFF (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Magnet Grip Suction (Space)"} </button> `; } else if (currentExampleId === 10) { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('fire_cannon')"> ๐Ÿš€ ${isKo ? "์ ค๋ฆฌ๋นˆ ๋Œ€ํฌ ๋ฐœ์‚ฌ! (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "FIRE CANNONBALL! (Space)"} </button> `; } else { grid.innerHTML = ` <button class="btn-action-trigger" onclick="sendAction('start')"> โ–ถ ${isKo ? "๋ฌผ๋ฆฌ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์‹œ์ž‘ (์ŠคํŽ˜์ด์Šค๋ฐ”)" : "Trigger Physics (Space)"} </button> `; } } function triggerStaticVictory(exampleId) { currentGameState = "victory"; playCheer(); triggerConfetti(); const banner = (currentLang === "ko" ? VICTORY_BANNERS_KR[exampleId] : VICTORY_BANNERS[exampleId]) || { icon: "๐ŸŒŸ", title: "VICTORY!", sub: "Stage Cleared!" }; const iconEl = document.getElementById("vicIcon"); const titleEl = document.getElementById("vicTitle"); const subEl = document.getElementById("vicSub"); if (iconEl) iconEl.textContent = banner.icon; if (titleEl) titleEl.textContent = banner.title; if (subEl) subEl.textContent = banner.sub; updateGameStateUI(); } function startStaticAISimulation(exampleId) { if (staticLifecycleTimer) { clearTimeout(staticLifecycleTimer); staticLifecycleTimer = null; } if (staticBalanceInterval) { clearInterval(staticBalanceInterval); staticBalanceInterval = null; } const screenImg = document.getElementById("mjpegStream"); // 01 ์Šค์นด์ด๋‹ค์ด๋น™ AI ๋ฆฌ๋“ฌ ํˆฌํ•˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ (1.2์ดˆ ๊ฐ„๊ฒฉ 4ํšŒ ํˆฌํ•˜ ํ›„ ์Šน๋ฆฌ) if (exampleId === 1) { let aiLanded = 0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentControlMode !== "ai" || currentExampleId !== 1) { clearInterval(staticBalanceInterval); return; } aiLanded++; const beanEl = document.getElementById("hudBeansLanded"); if (beanEl) beanEl.textContent = `${aiLanded} / 4 ๐ŸŽˆ`; playBoing(); if (aiLanded >= 4) { clearInterval(staticBalanceInterval); triggerStaticVictory(1); } }, 700); } // 02 ์บ”๋”” ํ•€๋ณผ ๋ณผํ’€์žฅ AI ์ž๋™ ํ”Œ๋ฆฌํ•‘ ๋ฐ 1000์  ๋ŒํŒŒ else if (exampleId === 2) { staticPinballScore = 0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentControlMode !== "ai" || currentExampleId !== 2) { clearInterval(staticBalanceInterval); return; } staticPinballScore += Math.floor(Math.random() * 60) + 120; const pinEl = document.getElementById("hudPinballScore"); if (pinEl) pinEl.textContent = staticPinballScore; playBoing(); if (staticPinballScore >= 1000) { clearInterval(staticBalanceInterval); triggerStaticVictory(2); } }, 320); } // 03 ๋„๋ฏธ๋…ธ ์ŠคํŠธ๋ผ์ดํฌ AI ํƒ„๋„ ์ž„ํŽ„์Šค ๊ฒฉ๋ฐœ else if (exampleId === 3) { staticLifecycleTimer = setTimeout(() => { if (currentGameState !== "playing" || currentExampleId !== 3) return; if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[3]) { screenImg.src = EMBEDDED_CLEARED[3]; } const domEl = document.getElementById("hudDominoStatus"); if (domEl) domEl.textContent = "AI Cleared! (0.83s) ๐ŸŒŸ"; triggerStaticVictory(3); }, 2400); } // 04 ์ž์ด์–ธํŠธ ๊ทธ๋„ค AI ๊ณต์ง„ ํŽŒํ•‘ 360๋„ ๋ฃจํ”„ else if (exampleId === 4) { let aiAngle = 0.0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentControlMode !== "ai" || currentExampleId !== 4) { clearInterval(staticBalanceInterval); return; } aiAngle += 72.0; const swingEl = document.getElementById("hudSwingAngle"); if (swingEl) swingEl.textContent = `${aiAngle.toFixed(1)}ยฐ (${Math.min(1, Math.floor(aiAngle / 360))} loop)`; playBoing(); if (aiAngle >= 360.0) { clearInterval(staticBalanceInterval); triggerStaticVictory(4); } }, 550); } // 05 ํŠธ์œˆ ์•„ํฌ๋กœ๋ฐ”ํ‹ฑ ์Šค์œ™ AI 3์—ฐ์† ํ…€๋ธ”๋ง ํ‚ฅ else if (exampleId === 5) { let aiCombos = 0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentControlMode !== "ai" || currentExampleId !== 5) { clearInterval(staticBalanceInterval); return; } aiCombos++; const acroEl = document.getElementById("hudAcroCombo"); if (acroEl) acroEl.textContent = `${aiCombos} / 3 ๐Ÿคธ`; playBoing(); if (aiCombos >= 3) { clearInterval(staticBalanceInterval); triggerStaticVictory(5); } }, 800); } // 06 ์Šฌ๋ผ์ด๋“œ ๋ ˆ์ด์Šค AI ์Šฌ๋ฆฝ์ŠคํŠธ๋ฆผ ์ถ”์›” ์—ญ์ „์Šน else if (exampleId === 6) { staticLifecycleTimer = setTimeout(() => { if (currentGameState !== "playing" || currentExampleId !== 6) return; if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[6]) { screenImg.src = EMBEDDED_CLEARED[6]; } const leaderEl = document.getElementById("hudRaceLeader"); if (leaderEl) leaderEl.textContent = "Pink Bean Won! ๐Ÿ†"; triggerStaticVictory(6); }, 2400); } // 07 ์นดํŠธํด LQR AI ํผํŽ™ํŠธ ๋ฐธ๋Ÿฐ์‹ฑ (3.5์ดˆ ๋ฐ๋ชจ ํ›„ ์Šน๋ฆฌ) else if (exampleId === 7) { staticSurvivalTime = 0.0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentExampleId !== 7) { clearInterval(staticBalanceInterval); return; } staticSurvivalTime += 0.5; const scoreEl = document.getElementById("hudScore"); const angleEl = document.getElementById("hudAngle"); if (scoreEl) scoreEl.textContent = `${staticSurvivalTime.toFixed(2)}s`; if (angleEl) { const sway = (Math.sin(staticSurvivalTime * 3.5) * 0.8).toFixed(1); angleEl.textContent = `${sway > 0 ? "+" : ""}${sway}ยฐ`; } if (staticSurvivalTime >= 3.5) { clearInterval(staticBalanceInterval); triggerStaticVictory(7); } }, 250); } // 08 ๋ฒ”ํผ์นด Pure Pursuit AI ์ฝ”์ธ ์ˆœ์ฐจ 5/5 ์ˆ˜์ง‘ else if (exampleId === 8) { let aiCoins = 0; staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentControlMode !== "ai" || currentExampleId !== 8) { clearInterval(staticBalanceInterval); return; } aiCoins++; const coinEl = document.getElementById("hudCoins"); if (coinEl) coinEl.textContent = aiCoins; playBoing(); if (aiCoins >= 5) { clearInterval(staticBalanceInterval); triggerStaticVictory(8); } }, 650); } // 09 ์ธํ˜•๋ฝ‘๊ธฐ 3๋‹จ๊ณ„ IK ์ž์„ ํฌ๋ ˆ์ธ ๊ตฌ์ถœ else if (exampleId === 9) { const clawEl = document.getElementById("hudClawHeight"); if (clawEl) clawEl.textContent = "0.25m (Targeting ๐ŸŽฏ)"; staticLifecycleTimer = setTimeout(() => { if (currentGameState !== "playing" || currentExampleId !== 9) return; if (clawEl) clawEl.textContent = "0.45m (Grip ON ๐Ÿงฒ)"; playBoing(); staticLifecycleTimer = setTimeout(() => { if (currentGameState !== "playing" || currentExampleId !== 9) return; if (clawEl) clawEl.textContent = "Rescued! ๐Ÿงธ"; triggerStaticVictory(9); }, 1200); }, 1000); } // 10 ๋งˆ์นด๋กฑ ๋ฉ”๊ฐ€ํƒ€์›Œ ํƒ„๋„ํ•™ CoM ์ €๊ฒฉ ์™„ํŒŒ else if (exampleId === 10) { staticLifecycleTimer = setTimeout(() => { if (currentGameState !== "playing" || currentExampleId !== 10) return; if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[10]) { screenImg.src = EMBEDDED_CLEARED[10]; } const demoEl = document.getElementById("hudDemo"); if (demoEl) demoEl.textContent = "100.0"; triggerStaticVictory(10); }, 2300); } } // ============================================================================ // ๐Ÿ“ก ์„œ๋ฒ„ ์•ก์…˜ ์ „์†ก & ์ŠคํŽ˜์ด์Šค ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ์ƒํƒœ ๋จธ์‹  // ============================================================================ async function sendAction(actionType, value = 0.0) { const isStatic = (typeof IS_STATIC_SPACE !== "undefined" && IS_STATIC_SPACE) || (typeof EMBEDDED_ANIMATIONS !== "undefined"); const screenImg = document.getElementById("mjpegStream"); // ๐Ÿค– ์œ ์ € ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ์กฐ์ž‘ ์‹œ ์Šค๋งˆํŠธ AI ๋ชจ๋“œ โž” ์ธ๊ฐ„ ์ˆ˜๋™ ๋ชจ๋“œ๋กœ ์ž๋™ ์ „ํ™˜ (Human Takeover) if (currentControlMode === "ai" && actionType !== "start" && actionType !== "reset") { setControlMode("manual"); } // ๐Ÿš€ Client-Side MuJoCo WebAssembly Engine Handler (Instant Response) if (useWasm) { if (!wasmPlayer || !wasmPlayer.isReady) { await initWasmEngine(); } if (wasmPlayer) { if (actionType === "start") { playStart(); } else if (actionType === "reset") { playPop(); } else { playBoing(); } try { wasmPlayer.applyAction(actionType, value); } catch (err) { console.warn("wasmPlayer.applyAction suppressed error:", err); } currentGameState = wasmPlayer.gameState; updateGameStateUI(); return; } } if (actionType === "start" || actionType === "fire_cannon" || actionType === "push_domino" || actionType === "start_race") { playStart(); currentGameState = "playing"; updateGameStateUI(); if (isStatic && screenImg) { if (staticLifecycleTimer) clearTimeout(staticLifecycleTimer); if (staticBalanceInterval) clearInterval(staticBalanceInterval); // ๋ชจ๋“œ์— ๋”ฐ๋ผ ์™„์ „ํžˆ ๋ถ„๋ฆฌ๋œ ๊ฒŒ์ž„ ๋ฃจํ”„ ์‹คํ–‰! if (currentControlMode === "ai") { // [๐Ÿค– ์Šค๋งˆํŠธ AI ๋ชจ๋“œ]: ์ž์œจ ์ฃผํ–‰ ๋ฌผ๋ฆฌ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๊ฐ€๋™ ๋ฐ ์ „ 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ 100% ํด๋ฆฌ์–ด ์‹œ์—ฐ! if (typeof EMBEDDED_ANIMATIONS !== "undefined" && EMBEDDED_ANIMATIONS[currentExampleId]) { screenImg.src = EMBEDDED_ANIMATIONS[currentExampleId] + "?t=" + Date.now(); } startStaticAISimulation(currentExampleId); } else { // [๐ŸŽฎ ์ธ๊ฐ„ ์ˆ˜๋™ ์กฐ์ž‘ ๋ชจ๋“œ]: // ์œ ์ €๊ฐ€ ํ‚ค๋ฅผ ์ง์ ‘ ๋ˆ„๋ฅด๊ธฐ ์ „๊นŒ์ง€๋Š” ์ •์ง€ ์Šคํ‹ธ์ปท(Still)์„ ์œ ์ง€ํ•˜์—ฌ ํ˜ผ์ž ์‹คํ–‰๋˜๋Š” ํ˜„์ƒ ์›์ฒœ ์ฐจ๋‹จ! if (actionType === "fire_cannon" || (currentExampleId === 10 && actionType === "start" && value === 1.0)) { // 10๋ฒˆ ๋Œ€ํฌ: ์œ ์ €๊ฐ€ ์ŠคํŽ˜์ด์Šค๋ฐ”๋‚˜ ๋ฐœ์‚ฌ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ๋งŒ ๊ฒฉ๋ฐœ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์žฌ์ƒ ๋ฐ ํด๋ฆฌ์–ด! if (typeof EMBEDDED_ANIMATIONS !== "undefined" && EMBEDDED_ANIMATIONS[10]) { screenImg.src = EMBEDDED_ANIMATIONS[10] + "?t=" + Date.now(); } staticLifecycleTimer = setTimeout(() => { if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[10]) { screenImg.src = EMBEDDED_CLEARED[10]; } const demoEl = document.getElementById("hudDemo"); if (demoEl) demoEl.textContent = "100.0"; triggerStaticVictory(10); }, 2300); } else if (actionType === "push_domino" || (currentExampleId === 3 && actionType === "start" && value === 1.0)) { // 03๋ฒˆ ๋„๋ฏธ๋…ธ: ์œ ์ €๊ฐ€ ์ŠคํŽ˜์ด์Šค๋ฐ”๋‚˜ ๋„๋ฏธ๋…ธ ๋ฐ€๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ๋งŒ ์—ฐ์‡„ ์ „๋„ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์žฌ์ƒ ๋ฐ ํด๋ฆฌ์–ด! if (typeof EMBEDDED_ANIMATIONS !== "undefined" && EMBEDDED_ANIMATIONS[3]) { screenImg.src = EMBEDDED_ANIMATIONS[3] + "?t=" + Date.now(); } staticLifecycleTimer = setTimeout(() => { if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[3]) { screenImg.src = EMBEDDED_CLEARED[3]; } const domEl = document.getElementById("hudDominoStatus"); if (domEl) domEl.textContent = "Cleared! (0.83s) ๐ŸŒŸ"; triggerStaticVictory(3); }, 2400); } else if (actionType === "start_race" || (currentExampleId === 6 && actionType === "start" && value === 1.0)) { // 06๋ฒˆ ์Šฌ๋ผ์ด๋“œ: ๋ ˆ์ด์Šค ์ถœ๋ฐœ ์‹ ํ˜ธ ์‹œ ์Šฌ๋ผ์ด๋“œ ๋‹ค์šด ์• ๋‹ˆ๋ฉ”์ด์…˜ ์žฌ์ƒ ๋ฐ ํด๋ฆฌ์–ด! if (typeof EMBEDDED_ANIMATIONS !== "undefined" && EMBEDDED_ANIMATIONS[6]) { screenImg.src = EMBEDDED_ANIMATIONS[6] + "?t=" + Date.now(); } staticLifecycleTimer = setTimeout(() => { if (screenImg && typeof EMBEDDED_CLEARED !== "undefined" && EMBEDDED_CLEARED[6]) { screenImg.src = EMBEDDED_CLEARED[6]; } const leaderEl = document.getElementById("hudRaceLeader"); if (leaderEl) leaderEl.textContent = "Pink Bean Won! ๐Ÿ†"; triggerStaticVictory(6); }, 2400); } else if (currentExampleId === 7) { // 07๋ฒˆ ์นดํŠธํด: 15์ดˆ ์ƒ์กด ๋„์ „ ์นด์šดํŠธ๋‹ค์šด staticSurvivalTime = 0.0; if (typeof EMBEDDED_ANIMATIONS !== "undefined" && EMBEDDED_ANIMATIONS[7]) { screenImg.src = EMBEDDED_ANIMATIONS[7] + "?t=" + Date.now(); } staticBalanceInterval = setInterval(() => { if (currentGameState !== "playing" || currentExampleId !== 7) { clearInterval(staticBalanceInterval); return; } staticSurvivalTime += 0.1; const scoreEl = document.getElementById("hudScore"); const angleEl = document.getElementById("hudAngle"); if (scoreEl) scoreEl.textContent = `${staticSurvivalTime.toFixed(2)}s`; if (angleEl) { const sway = (Math.sin(staticSurvivalTime * 3.5) * 1.2).toFixed(1); angleEl.textContent = `${sway > 0 ? "+" : ""}${sway}ยฐ`; } if (staticSurvivalTime >= 15.0) { clearInterval(staticBalanceInterval); triggerStaticVictory(7); } }, 100); } else { // 01, 02, 04, 05, 08, 09๋ฒˆ: ๊ฒŒ์ž„ ์‹œ์ž‘ ์‹œ ์ •์ง€ ์Šคํ‹ธ์ปท(Still)์„ ์œ ์ง€ํ•˜์—ฌ ํ˜ผ์ž ์‹คํ–‰๋˜๋Š” ํ˜„์ƒ ์ฐจ๋‹จ! if (typeof EMBEDDED_STILLS !== "undefined" && EMBEDDED_STILLS[currentExampleId]) { screenImg.src = EMBEDDED_STILLS[currentExampleId]; } } } } } else if (actionType === "reset") { playPop(); currentGameState = "ready"; if (staticLifecycleTimer) { clearTimeout(staticLifecycleTimer); staticLifecycleTimer = null; } if (staticBalanceInterval) { clearInterval(staticBalanceInterval); staticBalanceInterval = null; } staticBeanCounter = 0; staticPinballScore = 0; staticSwingLoops = 0; staticAcroCombo = 0; staticCoinCounter = 0; staticClawMagnet = false; staticSurvivalTime = 0.0; // ๋Œ€๊ธฐ ์ƒํƒœ์˜ ๊นจ๋—ํ•œ ์ •์ง€ ์Šคํ‹ธ์ปท์œผ๋กœ ๋ณต๊ท€ if (isStatic && screenImg && typeof EMBEDDED_STILLS !== "undefined" && EMBEDDED_STILLS[currentExampleId]) { screenImg.src = EMBEDDED_STILLS[currentExampleId]; } updateGameStateUI(); // 10๋Œ€ ๋ฏธ๋‹ˆ๊ฒŒ์ž„ ์ „์ฒด HUD ์ˆ˜์น˜ ๋ฆฌ์…‹ const scoreEl = document.getElementById("hudScore"); if (scoreEl) scoreEl.textContent = "0.00s"; const angleEl = document.getElementById("hudAngle"); if (angleEl) angleEl.textContent = "0.0ยฐ"; const coinEl = document.getElementById("hudCoins"); if (coinEl) coinEl.textContent = "0"; const demoEl = document.getElementById("hudDemo"); if (demoEl) demoEl.textContent = "0.0"; const beanEl = document.getElementById("hudBeansLanded"); if (beanEl) beanEl.textContent = "0 / 4 ๐ŸŽˆ"; const pinEl = document.getElementById("hudPinballScore"); if (pinEl) pinEl.textContent = "0"; const domEl = document.getElementById("hudDominoStatus"); if (domEl) domEl.textContent = "Ready ๐ŸŒŸ"; const acroEl = document.getElementById("hudAcroCombo"); if (acroEl) acroEl.textContent = "0 / 3 ๐Ÿคธ"; const clawEl = document.getElementById("hudClawHeight"); if (clawEl) clawEl.textContent = "0.12m ๐Ÿงธ"; const leaderEl = document.getElementById("hudRaceLeader"); if (leaderEl) leaderEl.textContent = "Ready to Race ๐Ÿ"; const swingEl = document.getElementById("hudSwingAngle"); if (swingEl) swingEl.textContent = "0.0ยฐ"; } else { playBoing(); } if (useWasm && wasmPlayer) { wasmPlayer.applyAction(actionType, value); currentGameState = wasmPlayer.gameState; updateGameStateUI(); return; } try { const res = await fetch("/api/action", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action_type: actionType, value: value }) }); if (res.ok) { const data = await res.json(); if (data.game_state) { currentGameState = data.game_state; updateGameStateUI(data); } } } catch (err) { if (!useWasm) { useWasm = true; await initWasmEngine(); if (wasmPlayer) { wasmPlayer.loadGame(currentExampleId); wasmPlayer.applyAction(actionType, value); } } } } function handleMainStartClick() { if (currentGameState === "playing") { sendAction("reset"); } else { sendAction("start"); } } function updateGameStateUI(telemetry = null) { const readyOverlay = document.getElementById("readyOverlay"); const gameoverOverlay = document.getElementById("gameoverOverlay"); const victoryOverlay = document.getElementById("victoryOverlay"); const mainStartBtn = document.getElementById("mainStartBtn"); const dict = I18N[currentLang] || I18N.en; if (currentGameState === "ready") { if (readyOverlay) readyOverlay.style.display = "flex"; if (gameoverOverlay) gameoverOverlay.style.display = "none"; if (victoryOverlay) victoryOverlay.style.display = "none"; if (mainStartBtn) mainStartBtn.textContent = dict.btn_start_game; } else if (currentGameState === "playing") { if (readyOverlay) readyOverlay.style.display = "none"; if (gameoverOverlay) gameoverOverlay.style.display = "none"; if (victoryOverlay) victoryOverlay.style.display = "none"; if (mainStartBtn) mainStartBtn.textContent = dict.btn_playing; } else if (currentGameState === "gameover") { if (readyOverlay) readyOverlay.style.display = "none"; if (gameoverOverlay) gameoverOverlay.style.display = "flex"; if (victoryOverlay) victoryOverlay.style.display = "none"; if (mainStartBtn) mainStartBtn.textContent = dict.btn_retry; if (telemetry) { const resSurv = document.getElementById("resSurvival"); if (resSurv) resSurv.textContent = `${(telemetry.survival_time || 0).toFixed(2)}s`; const resRnk = document.getElementById("resRank"); if (resRnk) resRnk.textContent = telemetry.rank || "B"; } } else if (currentGameState === "victory") { if (readyOverlay) readyOverlay.style.display = "none"; if (gameoverOverlay) gameoverOverlay.style.display = "none"; if (victoryOverlay) victoryOverlay.style.display = "flex"; if (mainStartBtn) mainStartBtn.textContent = dict.btn_play_again; if (telemetry && telemetry.victory_banner) { const iconEl = document.getElementById("vicIcon"); const titleEl = document.getElementById("vicTitle"); const subEl = document.getElementById("vicSub"); if (iconEl) iconEl.textContent = telemetry.victory_banner.icon || "๐ŸŒŸ"; if (titleEl) titleEl.textContent = telemetry.victory_banner.title || "VICTORY!"; if (subEl) subEl.textContent = telemetry.victory_banner.sub || "Great job!"; } else { const banner = (currentLang === "ko" ? VICTORY_BANNERS_KR[currentExampleId] : VICTORY_BANNERS[currentExampleId]); if (banner) { const iconEl = document.getElementById("vicIcon"); const titleEl = document.getElementById("vicTitle"); const subEl = document.getElementById("vicSub"); if (iconEl) iconEl.textContent = banner.icon; if (titleEl) titleEl.textContent = banner.title; if (subEl) subEl.textContent = banner.sub; } } } } // ============================================================================ // ๐Ÿค– ์กฐ์ž‘ ๋ชจ๋“œ ๋ฐ ํŒŒ๋ผ๋ฏธํ„ฐ ์กฐ์ ˆ // ============================================================================ async function setControlMode(mode) { playPop(); currentControlMode = mode; document.getElementById("btnModeManual").classList.toggle("active", mode === "manual"); document.getElementById("btnModeAI").classList.toggle("active", mode === "ai"); const indicatorIcon = document.getElementById("indicatorIcon"); const indicatorText = document.getElementById("indicatorText"); if (indicatorIcon) { indicatorIcon.textContent = mode === "ai" ? "๐Ÿค–" : "๐ŸŽฎ"; } if (indicatorText) { indicatorText.textContent = mode === "ai" ? (currentLang === "ko" ? "AI ์ž์œจ ์ œ์–ด ๋ชจ๋“œ" : "Autonomous AI Mode") : (currentLang === "ko" ? "์ธ๊ฐ„ ์ˆ˜๋™ ์กฐ์ž‘ ๋ชจ๋“œ" : "Human Manual Mode"); } updateModeHelpText(); if (useWasm && wasmPlayer) { wasmPlayer.setMode(mode); return; } if (mode === "ai" && currentGameState === "ready") { sendAction("start"); } try { await fetch("/api/set_mode", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ mode: mode }) }); } catch (err) { // offline } } async function updateGravity(val) { const g = parseFloat(val); document.getElementById("gravityVal").textContent = `${g.toFixed(2)} m/sยฒ`; if (useWasm && wasmPlayer && wasmPlayer.model) { wasmPlayer.model.opt.gravity[2] = g; return; } try { await fetch("/api/set_gravity", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ gravity: g }) }); } catch (err) {} } function setGravityPreset(g) { playPop(); document.getElementById("gravitySlider").value = g; updateGravity(g); document.querySelectorAll(".preset-pill").forEach(btn => { btn.classList.toggle("active", parseFloat(btn.textContent.match(/-?\d+\.?\d*/)?.[0] || 0) === g); }); } async function updateCannonPower(val) { const p = parseFloat(val); document.getElementById("cannonPowerVal").textContent = `${p.toFixed(1)}x`; if (useWasm && wasmPlayer) { wasmPlayer.cannonPower = p; return; } try { await fetch("/api/cannon_power", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ power: p }) }); } catch (err) {} } function setCannonPowerPreset(p) { playPop(); document.getElementById("cannonSlider").value = p; updateCannonPower(p); } // ============================================================================ // โŒจ๏ธ ํ‚ค๋ณด๋“œ ์ž…๋ ฅ ๋ฐ ์‹œ๊ฐํ™” // ============================================================================ function setupKeyboardListeners() { window.addEventListener("keydown", (e) => { if (e.repeat) return; const code = e.code; activeKeySet.add(code); highlightKeyBox(code, true); // ๊ณตํ†ต ๋ฆฌ์…‹ if (code === "KeyR") { sendAction("reset"); return; } // ์นด๋ฉ”๋ผ ์ „ํ™˜ ๋‹จ์ถ•ํ‚ค [C] if (code === "KeyC") { cycleCamera(); return; } // ์™€์ด๋“œ ์ „์ฒดํ™”๋ฉด ์ „ํ™˜ ๋‹จ์ถ•ํ‚ค [F] if (code === "KeyF") { const fsBtn = document.getElementById("fullscreenBtn"); if (fsBtn) fsBtn.click(); return; } // ๋ชจ๋“œ ํ† ๊ธ€ [M] if (code === "KeyM") { setControlMode(currentControlMode === "manual" ? "ai" : "manual"); return; } // ์ŠคํŽ˜์ด์Šค ํ‚ค if (code === "Space") { e.preventDefault(); if (currentGameState === "ready" || currentGameState === "gameover") { if (currentExampleId === 3) { sendAction("push_domino"); } else if (currentExampleId === 6) { sendAction("start_race"); } else if (currentExampleId === 10) { sendAction("fire_cannon"); } else { sendAction("start"); } } else if (currentExampleId === 1) { sendAction("drop_bean"); } else if (currentExampleId === 2) { sendAction("ball_rain"); } else if (currentExampleId === 3) { sendAction("push_domino"); } else if (currentExampleId === 4) { sendAction("swing_pump"); } else if (currentExampleId === 5) { sendAction("acrobatic_flip"); } else if (currentExampleId === 6) { sendAction("start_race"); } else if (currentExampleId === 9) { sendAction("claw_magnet_toggle"); } else if (currentExampleId === 10) { sendAction("fire_cannon"); } return; } // ๊ฒŒ์ž„ 01 ์Šค์นด์ด๋‹ค์ด๋น™ (A/D ๋ฐ ์ขŒ์šฐ ๋ฐฉํ–ฅํ‚ค๋กœ ์ฟ ์…˜ ํŠ•๊ธฐ๊ธฐ) if (currentExampleId === 1) { if (code === "KeyA" || code === "ArrowLeft") sendAction("bounce_cushion", -1); if (code === "KeyD" || code === "ArrowRight") sendAction("bounce_cushion", 1); } // ๊ฒŒ์ž„ 02 ํ•€๋ณผ (A/D ๋ฐ ์ขŒ์šฐ ๋ฐฉํ–ฅํ‚ค ๋™์‹œ ์ง€์›) else if (currentExampleId === 2) { if (code === "KeyA" || code === "ArrowLeft") sendAction("flip_left"); if (code === "KeyD" || code === "ArrowRight") sendAction("flip_right"); } // ๊ฒŒ์ž„ 04 ๊ทธ๋„ค ํŽŒํ•‘ (W, Up, Space) else if (currentExampleId === 4) { if (code === "KeyW" || code === "ArrowUp") sendAction("swing_pump"); } // ๊ฒŒ์ž„ 05 ์•„ํฌ๋กœ๋ฐ”ํ‹ฑ ๊ด€์ ˆ ์ œ์–ด (W/S: ๊ด€์ ˆ1, A/D: ๊ด€์ ˆ2) else if (currentExampleId === 5) { if (code === "KeyW" || code === "ArrowUp") sendAction("acrobatic_j1_up"); if (code === "KeyS" || code === "ArrowDown") sendAction("acrobatic_j1_down"); if (code === "KeyA" || code === "ArrowLeft") sendAction("acrobatic_j2_up"); if (code === "KeyD" || code === "ArrowRight") sendAction("acrobatic_j2_down"); } // ๊ฒŒ์ž„ 06 ์Šฌ๋ผ์ด๋“œ ๋ถ€์Šคํ„ฐ (A/Left: ํ•‘ํฌ๋นˆ, D/Right: ๋ฏผํŠธ๋นˆ) else if (currentExampleId === 6) { if (code === "KeyA" || code === "ArrowLeft") sendAction("slide_boost_pink"); if (code === "KeyD" || code === "ArrowRight") sendAction("slide_boost_mint"); } // ๊ฒŒ์ž„ 07 ์นดํŠธํด ๋ฐธ๋Ÿฐ์„œ (A/D ๋ฐ ๋ฐฉํ–ฅํ‚ค ์ขŒ์šฐ ๋™์‹œ ์ง€์›) else if (currentExampleId === 7) { if (code === "KeyA" || code === "ArrowLeft") sendAction("cart_left"); if (code === "KeyD" || code === "ArrowRight") sendAction("cart_right"); } // ๊ฒŒ์ž„ 08 ๋ฒ”ํผ์นด ๋“œ๋ผ์ด๋ธŒ (WASD ๋ฐ ๋ฐฉํ–ฅํ‚ค ์ƒํ•˜์ขŒ์šฐ ๋™์‹œ ์ง€์›) else if (currentExampleId === 8) { if (code === "KeyW" || code === "ArrowUp") sendAction("car_forward"); if (code === "KeyS" || code === "ArrowDown") sendAction("car_backward"); if (code === "KeyA" || code === "ArrowLeft") sendAction("car_left"); if (code === "KeyD" || code === "ArrowRight") sendAction("car_right"); } // ๊ฒŒ์ž„ 09 ๋กœ๋ด‡ํŒ” ํฌ๋ ˆ์ธ (WASD ๋ฐ ๋ฐฉํ–ฅํ‚ค ๋™์‹œ ์ง€์›) else if (currentExampleId === 9) { if (code === "ArrowUp" || code === "KeyW") sendAction("arm_shoulder_up"); if (code === "ArrowDown" || code === "KeyS") sendAction("arm_shoulder_down"); if (code === "ArrowRight" || code === "KeyD") sendAction("arm_elbow_up"); if (code === "ArrowLeft" || code === "KeyA") sendAction("arm_elbow_down"); } // ๊ฒŒ์ž„ 10 ๋งˆ์นด๋กฑ ๋Œ€ํฌ ํŒŒ์›Œ ์กฐ์ ˆ (W/โ†‘: ํŒŒ์›Œ ์ฆํญ, S/โ†“: ํŒŒ์›Œ ๊ฐ์‡ ) else if (currentExampleId === 10) { const slider = document.getElementById("cannonSlider"); if (slider) { if (code === "ArrowUp" || code === "KeyW") { const newVal = Math.min(2.5, +(parseFloat(slider.value) + 0.1).toFixed(1)); slider.value = newVal; updateCannonPower(newVal); } else if (code === "ArrowDown" || code === "KeyS") { const newVal = Math.max(0.4, +(parseFloat(slider.value) - 0.1).toFixed(1)); slider.value = newVal; updateCannonPower(newVal); } } } }); window.addEventListener("keyup", (e) => { const code = e.code; activeKeySet.delete(code); highlightKeyBox(code, false); // 02 ํ•€๋ณผ if (currentExampleId === 2) { const leftHeld = activeKeySet.has("KeyA") || activeKeySet.has("ArrowLeft"); const rightHeld = activeKeySet.has("KeyD") || activeKeySet.has("ArrowRight"); if (!leftHeld && !rightHeld) sendAction("flip_stop"); else if (leftHeld) sendAction("flip_left"); else if (rightHeld) sendAction("flip_right"); } // 05 ์•„ํฌ๋กœ๋ฐ”ํ‹ฑ else if (currentExampleId === 5) { sendAction("acrobatic_stop"); } // 07 ์นดํŠธํด (A/D ๋ฐ ์ขŒ์šฐ ๋ฐฉํ–ฅํ‚ค ๋™์‹œ ์ง€์›) else if (currentExampleId === 7) { const leftHeld = activeKeySet.has("KeyA") || activeKeySet.has("ArrowLeft"); const rightHeld = activeKeySet.has("KeyD") || activeKeySet.has("ArrowRight"); if (!leftHeld && !rightHeld) sendAction("cart_stop"); else if (leftHeld) sendAction("cart_left"); else if (rightHeld) sendAction("cart_right"); } // 08 ๋ฒ”ํผ์นด (๋ณตํ•ฉ ์ž…๋ ฅ ํ™€๋“œ ๋ณด์กด) else if (currentExampleId === 8) { const upHeld = activeKeySet.has("KeyW") || activeKeySet.has("ArrowUp"); const downHeld = activeKeySet.has("KeyS") || activeKeySet.has("ArrowDown"); const leftHeld = activeKeySet.has("KeyA") || activeKeySet.has("ArrowLeft"); const rightHeld = activeKeySet.has("KeyD") || activeKeySet.has("ArrowRight"); if (upHeld) sendAction("car_forward"); else if (downHeld) sendAction("car_backward"); else if (leftHeld) sendAction("car_left"); else if (rightHeld) sendAction("car_right"); else sendAction("car_stop"); } }); } function highlightKeyBox(code, isActive) { const keyMap = { KeyW: "keyW", ArrowUp: "keyW", KeyA: "keyA", ArrowLeft: "keyLeft", KeyS: "keyS", ArrowDown: "keyS", KeyD: "keyD", ArrowRight: "keyRight", Space: "keySpace", KeyR: "keyR", KeyC: "keyC" }; const elemId = keyMap[code]; if (elemId) { const el = document.getElementById(elemId); if (el) el.classList.toggle("active", isActive); } } // ============================================================================ // ๐Ÿ”„ ์‹ค์‹œ๊ฐ„ ํ…”๋ ˆ๋ฉ”ํŠธ๋ฆฌ ํด๋ง ๋ฃจํ”„ // ============================================================================ function startTelemetryLoop() { setInterval(async () => { if (useWasm) return; if ((typeof IS_STATIC_SPACE !== "undefined" && IS_STATIC_SPACE) || (typeof EMBEDDED_ANIMATIONS !== "undefined")) { return; } try { const res = await fetch("/api/telemetry"); if (!res.ok) return; const data = await res.json(); // ์ƒํƒœ ๋ณ€ํ™” ๊ฐ์ง€ if (data.game_state !== currentGameState) { const prevState = currentGameState; currentGameState = data.game_state; if (currentGameState === "gameover" && prevState !== "gameover") { playGameOver(); } else if (currentGameState === "victory" && prevState !== "victory") { playCheer(); triggerConfetti(); } else if (currentGameState === "playing" && prevState === "ready") { playStart(); triggerConfetti(); } updateGameStateUI(data); } // ์‚ฌ์šด๋“œ FX ์•Œ๋ฆผ (์ฝ”์ธ ํš๋“ ๋“ฑ) if (data.new_coin_sound) { playCoinSound(); triggerConfetti(); } // 1. ์Šค์นด์ด๋‹ค์ด๋น™ if (data.example_id === 1) { const beanEl = document.getElementById("hudBeansLanded"); if (beanEl) beanEl.textContent = `${data.beans_landed} (${data.beans_dropped} drops)`; } // 2. ์บ”๋”” ํ•€๋ณผ else if (data.example_id === 2) { const pinEl = document.getElementById("hudPinballScore"); if (pinEl) pinEl.textContent = data.pinball_score || 0; } // 3. ๋„๋ฏธ๋…ธ ์ŠคํŠธ๋ผ์ดํฌ else if (data.example_id === 3) { const domEl = document.getElementById("hudDominoStatus"); if (domEl) { domEl.textContent = data.domino_cleared ? "Cleared! (0.83s) ๐ŸŒŸ" : (data.survival_time > 0 ? `${data.survival_time.toFixed(2)}s ๐Ÿƒ` : "Ready ๐ŸŒŸ"); } } // 4. ์ž์ด์–ธํŠธ ๊ทธ๋„ค else if (data.example_id === 4) { const swingEl = document.getElementById("hudSwingAngle"); if (swingEl) swingEl.textContent = `${data.swing_angle_deg}ยฐ (Loops: ${data.swing_loops})`; } // 5. ์•„ํฌ๋กœ๋ฐ”ํ‹ฑ ํŠธ์œˆ else if (data.example_id === 5) { const acroEl = document.getElementById("hudAcroCombo"); if (acroEl) acroEl.textContent = `${data.somersault_count} / 3 ๐Ÿคธ`; } // 6. ์Šฌ๋ผ์ด๋“œ ๋ ˆ์ด์Šค else if (data.example_id === 6) { const leaderEl = document.getElementById("hudRaceLeader"); if (leaderEl) { leaderEl.textContent = data.race_winner ? `${data.race_winner} Won! ๐Ÿ†` : (data.race_leader || "Racing downhill..."); } } // 7. ์นดํŠธํด ๋ฐธ๋Ÿฐ์„œ else if (data.example_id === 7) { const scoreEl = document.getElementById("hudScore"); if (scoreEl) scoreEl.textContent = `${data.survival_time.toFixed(2)}s`; const bestEl = document.getElementById("hudBest"); if (bestEl) bestEl.textContent = `${data.best_score.toFixed(2)}s`; const angleEl = document.getElementById("hudAngle"); if (angleEl) angleEl.textContent = `${data.pole_angle_deg}ยฐ`; } // 8. ๋ฒ”ํผ์นด ์ฝ”์ธ ๋Œ€์‹œ else if (data.example_id === 8) { const coinsEl = document.getElementById("hudCoins"); if (coinsEl) coinsEl.textContent = data.coins_collected; } // 9. ์ธํ˜•๋ฝ‘๊ธฐ ํฌ๋ ˆ์ธ else if (data.example_id === 9) { const clawEl = document.getElementById("hudClawHeight"); if (clawEl) { clawEl.textContent = data.plushie_grabbed ? "Rescued! ๐Ÿงธ" : (data.claw_magnet_on ? `${(data.plushie_z || 0.12).toFixed(2)}m (Grip ON ๐Ÿงฒ)` : `${(data.plushie_z || 0.12).toFixed(2)}m ๐ŸŽฏ`); } } // 10. ๋งˆ์นด๋กฑ ํƒ€์›Œ ๋Œ€ํฌ else if (data.example_id === 10) { const demoEl = document.getElementById("hudDemo"); if (demoEl) demoEl.textContent = data.demolition_rate.toFixed(1); } } catch (e) { // ignore } }, 80); } // ============================================================================ // ๐Ÿ“‹ ์ฝ”๋“œ ๋‚ด๋ณด๋‚ด๊ธฐ ๋ชจ๋‹ฌ // ============================================================================ async function openCodeModal() { playPop(); const modal = document.getElementById("codeModal"); modal.style.display = "flex"; document.getElementById("modalBrickTitle").textContent = `Brick #${currentExampleId.toString().padStart(2, "0")} Code Export`; if (typeof EMBEDDED_CODES !== "undefined" && EMBEDDED_CODES[String(currentExampleId)]) { currentCodeData = EMBEDDED_CODES[String(currentExampleId)]; renderModalCode(); return; } if (typeof window !== "undefined" && window.PREMIUM_GAME_XMLS && window.PREMIUM_GAME_XMLS[String(currentExampleId)]) { const rawXml = window.PREMIUM_GAME_XMLS[String(currentExampleId)]; currentCodeData = { xml: rawXml, python: `# MuJoCo Standalone Executable Brick #${currentExampleId}\nimport mujoco\nimport mujoco.viewer\n\nxml = """${rawXml}"""\n\nmodel = mujoco.MjModel.from_xml_string(xml)\ndata = mujoco.MjData(model)\nmujoco.viewer.launch(model, data)\n` }; renderModalCode(); return; } } function closeCodeModal() { playPop(); document.getElementById("codeModal").style.display = "none"; } function switchCodeTab(tab) { playPop(); currentCodeTab = tab; document.getElementById("tabPy").classList.toggle("active", tab === "py"); document.getElementById("tabXml").classList.toggle("active", tab === "xml"); renderModalCode(); } function renderModalCode() { if (!currentCodeData) return; const viewer = document.getElementById("codeViewer"); viewer.textContent = currentCodeTab === "py" ? currentCodeData.python : currentCodeData.xml; } function copyCurrentCode() { playCheer(); triggerConfetti(); const text = document.getElementById("codeViewer").textContent; navigator.clipboard.writeText(text).then(() => { alert(currentLang === "ko" ? "๐Ÿ“‹ ์ฝ”๋“œ๊ฐ€ ํด๋ฆฝ๋ณด๋“œ์— ๋ณต์‚ฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!" : "๐Ÿ“‹ Code copied to clipboard! Paste it into Antigravity."); }); } // Expose all interactive functions to window for HTML onclick / onchange handlers if (typeof window !== "undefined") { window.setCamera = setCamera; window.selectExample = selectExample; window.nextExample = nextExample; window.sendAction = sendAction; window.setControlMode = setControlMode; window.setGravityPreset = setGravityPreset; window.updateGravity = updateGravity; window.setCannonPowerPreset = setCannonPowerPreset; window.updateCannonPower = updateCannonPower; window.handleMainStartClick = handleMainStartClick; window.openCodeModal = openCodeModal; window.closeCodeModal = closeCodeModal; window.switchCodeTab = switchCodeTab; window.copyCurrentCode = copyCurrentCode; window.toggleBgm = toggleBgm; }
/**
* 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 <strong>[C]</strong> 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",