make this a web version ui instead of titlebar const CHARACTER = { BOTTOM: "▗", TOP:…
- User
make this a web version ui instead of titlebar
const CHARACTER = { BOTTOM: "▗", TOP: "▝", OVER: "▞", UNDER: "▚", CRASH: "⭒", }; const BOX = { BOTTOM: "▖", TOP: "▘", }; const MISC = { FLAG_DARK: "⚑", FLAG_LIGHT: "⚐", PLAY: "▸", STAR_DARK: "★", STAR_LIGHT: "⭒", }; const COLLISION = "collision";
const JUMP_TIMEOUT = -1; const JUMP_LENGTH = 3; const DELAY_LOOP = 210; const DELAY_INITIAL = 1000;
const MAPS = { 1: " ▖ ▖ ▘ ▖ ▖ ▘ ▖ ⚑", 2: " ▖ ▖ ▘ ▖ ▘ ▖ ▖ ▘ ▖ ▖ ▖ ▘ ▖ ▖ ▘ ▖ ⚑", 3: " ▖ ▖ ▘ ▖ ▖ ▘ ▖ ▖ ▖ ▘ ▖ ▖ ▘ ▖ ⚑", };
const GAME_URL = new URL(window.location.href); const MAP = GAME_URL.searchParams.get("map") in MAPS ? GAME_URL.searchParams.get("map") : 1; const DEBUG = !!GAME_URL.searchParams.get("debug") != undefined;
let map = loadMap(MAP); let jump = JUMP_TIMEOUT; let ticks = 0; let playing = false; let win = true;
const commands = { ArrowUp: () => { if (!playing) return commands.s(); if (jump <= JUMP_TIMEOUT) jump = JUMP_LENGTH; }, s: async () => { if (playing) return;
faviconize("", 0); loopGame();}, " ": () => commands.ArrowUp(), r: async () => { playing = false; await dotDotDot("Restarting"); location.reload(); }, m: async () => { playing = false; clearStorage(); await dotDotDot("Clearing"); location.reload(); }, };
document.addEventListener("keydown", (event) => { if (event.isComposing || event.keyCode === 229) { return; } log(event.key); if (event.key in commands) { event.preventDefault(); return commandsevent.key; } if (event.key in MAPS) { event.preventDefault(); return (location.href =
${location.origin}${location.pathname}?map=${event.key}); } });// todo: add onblur message and favicon
// main loopPreGame();
async function loopPreGame() { const welcomeMessage = MAP == 1 ? "Hit S to play!" :
MAP ${MAP};faviconize(MISC.PLAY, 102);
await sleep(DELAY_INITIAL); while (!playing) { render(
${MISC.FLAG_DARK} ${welcomeMessage}); await sleep(DELAY_LOOP); render(${MISC.FLAG_LIGHT} ${welcomeMessage}); await sleep(DELAY_LOOP); } }async function loopGame() { playing = true; while (playing && map.length > 0) { const character = getCharacter(jump, map[0]);
if (character == COLLISION) { faviconize(MISC.STAR_LIGHT, 101); render(CHARACTER.CRASH, map, `SCORE ${ticks}`); win = false; break; } map = map.slice(1, map.length); render(character, map); ticks++; if (jump > JUMP_TIMEOUT) jump--; await sleep(DELAY_LOOP);}
if (win) loopWin(ticks); }
async function loopWin(score) { faviconize(MISC.FLAG_LIGHT, 104);
- Assistant
- User
NOO LIKE TO RUN IT ON A BOOKMARKLET
- Assistant