/**
* 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: