File size: 42,442 Bytes
8d71d5e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VOID.LOOM - Cosmic Rhythm Puzzle</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Major+Mono+Display&display=swap">
<style>
@keyframes pulse-glow {
0% { opacity: 0.8; box-shadow: 0 0 5px currentColor; }
50% { opacity: 1; box-shadow: 0 0 20px currentColor; }
100% { opacity: 0.8; box-shadow: 0 0 5px currentColor; }
}
@keyframes title-glow {
0% { text-shadow: 0 0 5px #7f5af0; }
50% { text-shadow: 0 0 20px #7f5af0, 0 0 30px #2cb67d; }
100% { text-shadow: 0 0 5px #7f5af0; }
}
@keyframes pulse-enter {
from { transform: scale(0.5); opacity: 0; }
to { transform: scale(1); opacity: 1; }
}
@keyframes static-flicker {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
.title-glow {
animation: title-glow 3s ease-in-out infinite;
}
.pulse-animation {
animation: pulse-glow 1.5s infinite, pulse-enter 0.3s ease-out;
}
.static-effect {
background:
linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%),
linear-gradient(45deg, #000 25%, transparent 25%, transparent 75%, #000 75%);
background-size: 4px 4px;
background-position: 0 0, 2px 2px;
animation: static-flicker 0.2s linear infinite;
}
.danger-low { background-color: rgba(44, 182, 125, 0.1); }
.danger-medium { background-color: rgba(255, 159, 10, 0.1); }
.danger-high { background-color: rgba(239, 71, 111, 0.1); }
.danger-critical { background-color: rgba(239, 71, 111, 0.3); }
#gameContainer {
aspect-ratio: 1/1;
transition: all 0.3s;
}
#tutorialOverlay {
backdrop-filter: blur(5px);
transition: opacity 0.3s;
}
#tutorialOverlay:not(.active) {
opacity: 0;
pointer-events: none;
}
.pulse-top { --direction: 0deg; color: #7f5af0; }
.pulse-right { --direction: 90deg; color: #2cb67d; }
.pulse-bottom { --direction: 180deg; color: #ef476f; }
.pulse-left { --direction: 270deg; color: #ffffff; }
.pulse-low { --size: 40px; }
.pulse-mid { --size: 30px; }
.pulse-high { --size: 20px; }
</style>
</head>
<body class="bg-black text-gray-100 font-mono min-h-screen flex flex-col items-center p-4" style="font-family: 'Major Mono Display', monospace;">
<!-- Header Area -->
<header class="w-full max-w-2xl flex justify-between items-center mb-4">
<h1 class="text-4xl md:text-5xl title-glow">VOID.LOOM</h1>
<div class="flex gap-2">
<button id="audioToggle" class="px-3 py-1 bg-gray-800 hover:bg-gray-700 rounded-lg flex items-center">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M9.383 3.076A1 1 0 0110 4v12a1 1 0 01-1.707.707L4.586 13H2a1 1 0 01-1-1V8a1 1 0 011-1h2.586l3.707-3.707a1 1 0 011.09-.217zM14.657 2.929a1 1 0 011.414 0A9.972 9.972 0 0119 10a9.972 9.972 0 01-2.929 7.071 1 1 0 01-1.414-1.414A7.971 7.971 0 0017 10c0-2.21-.894-4.208-2.343-5.657a1 1 0 010-1.414zm-2.829 2.828a1 1 0 011.415 0A5.983 5.983 0 0115 10a5.984 5.984 0 01-1.757 4.243 1 1 0 01-1.415-1.415A3.984 3.984 0 0013 10a3.983 3.983 0 00-1.172-2.828 1 1 0 010-1.415z" clip-rule="evenodd" />
</svg>
</button>
<button id="fullscreenBtn" class="px-3 py-1 bg-gray-800 hover:bg-gray-700 rounded-lg">
⛶ Fullscreen
</button>
<button id="tutorialBtn" class="px-3 py-1 bg-gray-800 hover:bg-gray-700 rounded-lg">
❓ Tutorial
</button>
</div>
</header>
<!-- Game Container -->
<div id="gameContainer" class="relative w-full max-w-md bg-gray-900 rounded-lg border border-gray-800 overflow-hidden mb-6">
<!-- Void Grid Background -->
<div class="absolute inset-0 grid grid-cols-8 grid-rows-8">
<div class="border border-gray-800/50"></div>
<!-- 63 more grid cells generated by JS -->
</div>
<!-- Center Node -->
<div id="centerNode" class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-1/4 h-1/4 rounded-full bg-gray-800 border-2 border-purple-500 flex items-center justify-center pulse-animation">
<div class="w-1/2 h-1/2 rounded-full bg-purple-500/50"></div>
</div>
<!-- Game HUD -->
<div class="absolute top-2 left-2 bg-black/70 p-2 rounded-lg text-sm">
<div>Score: <span id="scoreDisplay">0</span></div>
<div>Combo: <span id="comboDisplay">1x</span></div>
<div>Wave: <span id="waveDisplay">1</span></div>
</div>
<!-- Time Slow Indicator -->
<div id="timeSlowIndicator" class="absolute top-2 right-2 bg-black/70 p-2 rounded-lg text-sm hidden">
⏱️ SLOW TIME
</div>
<!-- Danger Meter -->
<div class="absolute bottom-2 left-2 right-2 h-4 bg-gray-800 rounded-full overflow-hidden">
<div id="dangerMeter" class="h-full danger-low transition-all duration-300" style="width: 0%"></div>
</div>
<!-- Game Messages -->
<div id="gameMessage" class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-2xl text-center opacity-0 transition-opacity"></div>
<!-- Start Button -->
<button id="startButton" class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 px-6 py-3 bg-purple-600 hover:bg-purple-500 rounded-lg text-xl">
ENTER VOID
</button>
</div>
<!-- Game Controls -->
<div class="flex flex-col sm:flex-row gap-4 mb-6 w-full max-w-md">
<div class="flex-1 text-center bg-gray-900/50 p-3 rounded-lg border border-gray-800">
<p class="text-sm mb-1">Movement:</p>
<p class="text-xs">Arrow Keys or WASD</p>
</div>
<div class="flex-1 text-center bg-gray-900/50 p-3 rounded-lg border border-gray-800">
<p class="text-sm mb-1">Harmonize:</p>
<p class="text-xs">SPACE or Click Center</p>
</div>
<div class="flex-1 text-center bg-gray-900/50 p-3 rounded-lg border border-gray-800">
<p class="text-sm mb-1">Slow Time:</p>
<p class="text-xs">SHIFT Key</p>
</div>
</div>
<!-- Leaderboard Section -->
<div class="w-full max-w-2xl bg-gray-900/50 rounded-lg border border-gray-800 overflow-hidden mb-6">
<div class="flex justify-between items-center bg-gray-800/50 p-3">
<h2 class="text-xl">🏆 LEADERBOARD</h2>
<div class="flex gap-2">
<button id="exportScoresBtn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded text-sm">
Export
</button>
<button id="clearScoresBtn" class="px-3 py-1 bg-red-900/50 hover:bg-red-800/50 rounded text-sm">
Clear
</button>
</div>
</div>
<div id="leaderboardList" class="divide-y divide-gray-800 max-h-96 overflow-y-auto">
<div class="p-3 text-center text-gray-500">No scores yet</div>
</div>
</div>
<!-- Score Submission (hidden until game over) -->
<div id="scoreSubmission" class="w-full max-w-md bg-gray-900/50 p-4 rounded-lg border border-gray-800 hidden mb-6">
<h3 class="text-xl mb-3 text-center">VOID COLLAPSED</h3>
<p class="text-center mb-3">Final Score: <span id="finalScore" class="text-2xl">0</span></p>
<div class="flex flex-col sm:flex-row gap-2 mb-3">
<input type="text" id="initialsInput" maxlength="3" placeholder="Your initials"
class="flex-1 px-3 py-2 bg-gray-800 border border-gray-700 rounded-lg uppercase text-center">
<button id="submitScoreBtn" class="px-4 py-2 bg-purple-600 hover:bg-purple-500 rounded-lg">
Submit
</button>
</div>
<div id="shareSection" class="hidden">
<div class="flex gap-2 mb-2">
<input type="text" id="shareCode" readonly class="flex-1 px-3 py-1 bg-gray-800 rounded-lg text-xs">
<button id="copyShareBtn" class="px-3 py-1 bg-gray-700 hover:bg-gray-600 rounded-lg text-sm">
Copy
</button>
</div>
<p class="text-xs text-center text-gray-400">Share this code to challenge others</p>
</div>
</div>
<!-- Tutorial Overlay -->
<div id="tutorialOverlay" class="fixed inset-0 bg-black/80 z-50 flex items-center justify-center p-4">
<div class="bg-gray-900 border border-gray-800 rounded-lg max-w-md w-full max-h-[90vh] overflow-y-auto">
<div class="p-4 border-b border-gray-800 flex justify-between items-center">
<h2 class="text-xl">VOID.LOOM TUTORIAL</h2>
<button id="closeTutorialBtn" class="p-1 rounded-full hover:bg-gray-800">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div class="p-4 space-y-4">
<div class="flex items-start gap-3">
<div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0">1</div>
<div>
<h3 class="font-bold mb-1">Cosmic Pulses</h3>
<p class="text-sm text-gray-400">Pulses enter from four directions, each with unique colors and tones. Your goal is to harmonize with them.</p>
</div>
</div>
<div class="flex items-start gap-3">
<div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0">2</div>
<div>
<h3 class="font-bold mb-1">Movement</h3>
<p class="text-sm text-gray-400">Use <span class="bg-gray-800 px-1 rounded">Arrow Keys</span> or <span class="bg-gray-800 px-1 rounded">WASD</span> to shift your node's position.</p>
</div>
</div>
<div class="flex items-start gap-3">
<div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0">3</div>
<div>
<h3 class="font-bold mb-1">Harmonization</h3>
<p class="text-sm text-gray-400">Press <span class="bg-gray-800 px-1 rounded">SPACE</span> or click the center node when pulses align to harmonize.</p>
</div>
</div>
<div class="flex items-start gap-3">
<div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0">4</div>
<div>
<h3 class="font-bold mb-1">Time Control</h3>
<p class="text-sm text-gray-400">Hold <span class="bg-gray-800 px-1 rounded">SHIFT</span> to slow time temporarily when overwhelmed.</p>
</div>
</div>
<div class="flex items-start gap-3">
<div class="bg-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0">5</div>
<div>
<h3 class="font-bold mb-1">Danger Meter</h3>
<p class="text-sm text-gray-400">Each missed pulse increases danger. Fill the meter completely and the void collapses.</p>
</div>
</div>
</div>
<div class="p-4 border-t border-gray-800 flex justify-end">
<button id="startFromTutorialBtn" class="px-4 py-2 bg-purple-600 hover:bg-purple-500 rounded-lg">
Enter Void
</button>
</div>
</div>
</div>
<!-- Export Modal -->
<div id="exportModal" class="fixed inset-0 bg-black/80 z-50 flex items-center justify-center p-4 hidden">
<div class="bg-gray-900 border border-gray-800 rounded-lg max-w-md w-full">
<div class="p-4 border-b border-gray-800">
<h2 class="text-xl">EXPORT SCORES</h2>
</div>
<div class="p-4">
<textarea id="exportData" class="w-full h-40 bg-gray-800 p-3 rounded-lg font-mono text-sm mb-3" readonly></textarea>
<div class="flex justify-end gap-2">
<button id="closeExportBtn" class="px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg">
Close
</button>
<button id="copyExportBtn" class="px-4 py-2 bg-purple-600 hover:bg-purple-500 rounded-lg">
Copy Data
</button>
</div>
</div>
</div>
</div>
<script>
// Game State
const gameState = {
score: 0,
combo: 1,
wave: 1,
danger: 0,
isPlaying: false,
isTimeSlow: false,
activePulses: [],
harmonizedPulses: 0,
missedPulses: 0,
gameStartTime: 0,
gameEndTime: 0,
currentSeed: Date.now(),
audioEnabled: true,
nodePosition: { x: 0, y: 0 } // -1 to 1 range
};
// DOM Elements
const gameContainer = document.getElementById('gameContainer');
const centerNode = document.getElementById('centerNode');
const scoreDisplay = document.getElementById('scoreDisplay');
const comboDisplay = document.getElementById('comboDisplay');
const waveDisplay = document.getElementById('waveDisplay');
const dangerMeter = document.getElementById('dangerMeter');
const gameMessage = document.getElementById('gameMessage');
const startButton = document.getElementById('startButton');
const timeSlowIndicator = document.getElementById('timeSlowIndicator');
const audioToggle = document.getElementById('audioToggle');
const fullscreenBtn = document.getElementById('fullscreenBtn');
const tutorialBtn = document.getElementById('tutorialBtn');
const leaderboardList = document.getElementById('leaderboardList');
const clearScoresBtn = document.getElementById('clearScoresBtn');
const exportScoresBtn = document.getElementById('exportScoresBtn');
const scoreSubmission = document.getElementById('scoreSubmission');
const initialsInput = document.getElementById('initialsInput');
const submitScoreBtn = document.getElementById('submitScoreBtn');
const finalScore = document.getElementById('finalScore');
const shareSection = document.getElementById('shareSection');
const shareCode = document.getElementById('shareCode');
const copyShareBtn = document.getElementById('copyShareBtn');
const tutorialOverlay = document.getElementById('tutorialOverlay');
const closeTutorialBtn = document.getElementById('closeTutorialBtn');
const startFromTutorialBtn = document.getElementById('startFromTutorialBtn');
const exportModal = document.getElementById('exportModal');
const exportData = document.getElementById('exportData');
const closeExportBtn = document.getElementById('closeExportBtn');
const copyExportBtn = document.getElementById('copyExportBtn');
// Audio Elements (Base64 encoded short samples)
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const audioBuffers = {};
// Base64 encoded audio samples (shortened for example)
const audioSamples = {
pulseTop: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU...",
pulseRight: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU...",
pulseBottom: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU...",
pulseLeft: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU...",
success: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU...",
fail: "UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU..."
};
// Initialize audio buffers
async function initAudio() {
for (const [key, base64] of Object.entries(audioSamples)) {
try {
const response = await fetch(`data:audio/wav;base64,${base64}`);
const arrayBuffer = await response.arrayBuffer();
audioBuffers[key] = await audioContext.decodeAudioData(arrayBuffer);
} catch (error) {
console.error(`Error loading audio ${key}:`, error);
// Fallback to silent buffer
const buffer = audioContext.createBuffer(1, 22050, 22050);
audioBuffers[key] = buffer;
}
}
}
// Play sound
function playSound(name, volume = 0.7) {
if (!gameState.audioEnabled) return;
try {
const source = audioContext.createBufferSource();
source.buffer = audioBuffers[name];
const gainNode = audioContext.createGain();
gainNode.gain.value = volume;
source.connect(gainNode);
gainNode.connect(audioContext.destination);
source.start(0);
} catch (error) {
console.error("Error playing sound:", error);
}
}
// Initialize game grid
function initGameGrid() {
const grid = gameContainer.querySelector('.grid');
if (grid) grid.remove();
const gridDiv = document.createElement('div');
gridDiv.className = 'absolute inset-0 grid grid-cols-8 grid-rows-8';
for (let i = 0; i < 64; i++) {
const cell = document.createElement('div');
cell.className = 'border border-gray-800/50';
gridDiv.appendChild(cell);
}
gameContainer.insertBefore(gridDiv, gameContainer.firstChild);
}
// Generate a pulse from a random edge
function generatePulse() {
if (!gameState.isPlaying) return;
const directions = ['top', 'right', 'bottom', 'left'];
const tones = ['low', 'mid', 'high'];
const direction = directions[Math.floor(Math.random() * 4)];
const tone = tones[Math.floor(Math.random() * 3)];
const pulse = document.createElement('div');
pulse.className = `pulse pulse-${direction} pulse-${tone} pulse-animation absolute rounded-full`;
// Position pulse at edge
const containerRect = gameContainer.getBoundingClientRect();
const centerRect = centerNode.getBoundingClientRect();
const centerX = containerRect.width / 2;
const centerY = containerRect.height / 2;
let startX, startY;
switch (direction) {
case 'top':
startX = Math.random() * containerRect.width;
startY = 0;
break;
case 'right':
startX = containerRect.width;
startY = Math.random() * containerRect.height;
break;
case 'bottom':
startX = Math.random() * containerRect.width;
startY = containerRect.height;
break;
case 'left':
startX = 0;
startY = Math.random() * containerRect.height;
break;
}
// Set pulse size based on tone
const size = tone === 'low' ? 40 : tone === 'mid' ? 30 : 20;
pulse.style.width = `${size}px`;
pulse.style.height = `${size}px`;
// Position pulse
pulse.style.left = `${startX - size/2}px`;
pulse.style.top = `${startY - size/2}px`;
gameContainer.appendChild(pulse);
// Calculate animation duration based on distance
const distance = Math.sqrt(
Math.pow(centerX - startX, 2) +
Math.pow(centerY - startY, 2)
);
const baseDuration = 2000;
const duration = gameState.isTimeSlow ? baseDuration * 1.5 : baseDuration;
// Store pulse data
const pulseData = {
element: pulse,
direction: direction,
tone: tone,
startTime: Date.now(),
duration: duration,
harmonized: false
};
gameState.activePulses.push(pulseData);
// Play pulse sound
playSound(`pulse${direction.charAt(0).toUpperCase() + direction.slice(1)}`, 0.5);
// Animate pulse
setTimeout(() => {
const endX = centerX + (gameState.nodePosition.x * (containerRect.width * 0.3));
const endY = centerY + (gameState.nodePosition.y * (containerRect.height * 0.3));
pulse.style.transition = `all ${duration}ms linear`;
pulse.style.left = `${endX - size/2}px`;
pulse.style.top = `${endY - size/2}px`;
setTimeout(() => {
if (!pulseData.harmonized) {
handleMissedPulse();
pulse.remove();
}
}, duration);
}, 10);
// Schedule next pulse
const nextPulseDelay = Math.max(500, 1500 - (gameState.wave * 50));
setTimeout(generatePulse, nextPulseDelay);
}
// Handle harmonization (player action)
function handleHarmonize() {
if (!gameState.isPlaying) return;
const now = Date.now();
let harmonizedAny = false;
for (let i = gameState.activePulses.length - 1; i >= 0; i--) {
const pulse = gameState.activePulses[i];
const progress = (now - pulse.startTime) / pulse.duration;
if (progress > 0.8 && progress < 1.2 && !pulse.harmonized) {
// Successful harmonization
pulse.harmonized = true;
harmonizedAny = true;
// Visual feedback
pulse.element.style.backgroundColor = 'white';
pulse.element.style.boxShadow = '0 0 20px white';
// Remove pulse after short delay
setTimeout(() => {
pulse.element.remove();
gameState.activePulses.splice(i, 1);
}, 200);
// Calculate score based on accuracy
const accuracy = 1 - Math.abs(1 - progress);
const points = Math.floor(100 * accuracy * gameState.combo);
gameState.score += points;
gameState.combo++;
gameState.harmonizedPulses++;
// Reduce danger
gameState.danger = Math.max(0, gameState.danger - 5);
updateDangerMeter();
// Play success sound
playSound('success');
// Show combo effect
showGameMessage(`${gameState.combo}x COMBO!`, 'text-purple-300');
// Check for wave completion
if (gameState.harmonizedPulses >= gameState.wave * 3) {
nextWave();
}
break; // Only harmonize one pulse per keypress
}
}
if (!harmonizedAny) {
// Failed harmonization (too early/late)
gameState.combo = 1;
gameState.danger += 10;
updateDangerMeter();
// Play fail sound
playSound('fail');
// Show static effect
gameContainer.classList.add('static-effect');
setTimeout(() => {
gameContainer.classList.remove('static-effect');
}, 200);
showGameMessage('MISS!', 'text-red-400');
if (gameState.danger >= 100) {
endGame();
}
}
updateScoreDisplay();
}
// Handle missed pulse (reached center without player action)
function handleMissedPulse() {
gameState.missedPulses++;
gameState.combo = 1;
gameState.danger += 15;
updateDangerMeter();
// Play fail sound
playSound('fail', 0.3);
if (gameState.danger >= 100) {
endGame();
}
updateScoreDisplay();
}
// Move center node
function moveNode(direction) {
if (!gameState.isPlaying) return;
const moveAmount = 0.2;
switch (direction) {
case 'up':
gameState.nodePosition.y = Math.max(-1, gameState.nodePosition.y - moveAmount);
break;
case 'right':
gameState.nodePosition.x = Math.min(1, gameState.nodePosition.x + moveAmount);
break;
case 'down':
gameState.nodePosition.y = Math.min(1, gameState.nodePosition.y + moveAmount);
break;
case 'left':
gameState.nodePosition.x = Math.max(-1, gameState.nodePosition.x - moveAmount);
break;
}
// Update node position
centerNode.style.transform = `translate(-50%, -50%) translate(${gameState.nodePosition.x * 30}px, ${gameState.nodePosition.y * 30}px)`;
}
// Toggle time slow
function toggleTimeSlow(enable) {
gameState.isTimeSlow = enable;
if (enable) {
timeSlowIndicator.classList.remove('hidden');
// Slow down all active pulses
gameState.activePulses.forEach(pulse => {
const remaining = pulse.duration - (Date.now() - pulse.startTime);
pulse.element.style.transitionDuration = `${remaining * 1.5}ms`;
});
} else {
timeSlowIndicator.classList.add('hidden');
// Return pulses to normal speed
gameState.activePulses.forEach(pulse => {
const remaining = pulse.duration - (Date.now() - pulse.startTime);
pulse.element.style.transitionDuration = `${remaining}ms`;
});
}
}
// Advance to next wave
function nextWave() {
gameState.wave++;
gameState.harmonizedPulses = 0;
// Visual feedback
showGameMessage(`WAVE ${gameState.wave}`, 'text-yellow-300');
// Update displays
waveDisplay.textContent = gameState.wave;
}
// Update score display
function updateScoreDisplay() {
scoreDisplay.textContent = gameState.score;
comboDisplay.textContent = `${gameState.combo}x`;
}
// Update danger meter
function updateDangerMeter() {
dangerMeter.style.width = `${gameState.danger}%`;
// Update danger class
dangerMeter.className = 'h-full transition-all duration-300';
if (gameState.danger < 40) {
dangerMeter.classList.add('danger-low');
} else if (gameState.danger < 70) {
dangerMeter.classList.add('danger-medium');
} else if (gameState.danger < 90) {
dangerMeter.classList.add('danger-high');
} else {
dangerMeter.classList.add('danger-critical');
}
}
// Show game message
function showGameMessage(text, colorClass = 'text-purple-300') {
gameMessage.textContent = text;
gameMessage.className = `absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-2xl text-center ${colorClass} opacity-100 transition-opacity`;
setTimeout(() => {
gameMessage.classList.add('opacity-0');
}, 1000);
}
// Start game
function startGame() {
// Reset game state
gameState.score = 0;
gameState.combo = 1;
gameState.wave = 1;
gameState.danger = 0;
gameState.isPlaying = true;
gameState.isTimeSlow = false;
gameState.activePulses = [];
gameState.harmonizedPulses = 0;
gameState.missedPulses = 0;
gameState.nodePosition = { x: 0, y: 0 };
gameState.gameStartTime = Date.now();
gameState.currentSeed = Date.now();
// Update UI
startButton.classList.add('hidden');
timeSlowIndicator.classList.add('hidden');
scoreSubmission.classList.add('hidden');
shareSection.classList.add('hidden');
updateScoreDisplay();
updateDangerMeter();
waveDisplay.textContent = gameState.wave;
// Reset node position
centerNode.style.transform = 'translate(-50%, -50%)';
// Clear any existing pulses
document.querySelectorAll('.pulse').forEach(p => p.remove());
// Start pulse generation
setTimeout(generatePulse, 1000);
// Show start message
showGameMessage('BEGIN!', 'text-green-400');
}
// End game
function endGame() {
gameState.isPlaying = false;
gameState.gameEndTime = Date.now();
// Clear any active pulses
gameState.activePulses.forEach(p => p.element.remove());
gameState.activePulses = [];
// Show game over
showGameMessage('VOID COLLAPSED', 'text-red-500');
// Show score submission
finalScore.textContent = gameState.score;
scoreSubmission.classList.remove('hidden');
initialsInput.focus();
}
// Submit score to leaderboard
function submitScore() {
const initials = initialsInput.value.trim().toUpperCase().substring(0, 3) || '???';
const duration = Math.floor((gameState.gameEndTime - gameState.gameStartTime) / 1000);
const scoreEntry = {
initials: initials,
score: gameState.score,
wave: gameState.wave,
harmonized: gameState.harmonizedPulses,
missed: gameState.missedPulses,
duration: duration,
date: new Date().toISOString(),
seed: gameState.currentSeed
};
// Get existing scores
const scores = JSON.parse(localStorage.getItem('voidloom_scores') || '[]');
scores.push(scoreEntry);
// Sort by score (descending)
scores.sort((a, b) => b.score - a.score);
// Store back to localStorage
localStorage.setItem('voidloom_scores', JSON.stringify(scores));
// Update leaderboard display
updateLeaderboard();
// Show share option
shareCode.value = generateShareCode(scoreEntry);
shareSection.classList.remove('hidden');
}
// Generate a shareable code for the score
function generateShareCode(scoreEntry) {
const data = {
i: scoreEntry.initials,
s: scoreEntry.score,
w: scoreEntry.wave,
h: scoreEntry.harmonized,
m: scoreEntry.missed,
d: scoreEntry.duration,
t: scoreEntry.date.substring(0, 10),
x: scoreEntry.seed.toString(36).slice(-4)
};
return btoa(JSON.stringify(data)).substring(0, 16);
}
// Update leaderboard display
function updateLeaderboard() {
const scores = JSON.parse(localStorage.getItem('voidloom_scores') || '[]');
if (scores.length === 0) {
leaderboardList.innerHTML = '<div class="p-3 text-center text-gray-500">No scores yet</div>';
return;
}
leaderboardList.innerHTML = '';
scores.slice(0, 10).forEach((score, index) => {
const entry = document.createElement('div');
entry.className = 'leaderboard-entry p-3 flex justify-between items-center';
const rankClass = index < 3 ?
(index === 0 ? 'text-yellow-400' : index === 1 ? 'text-gray-300' : index === 2 ? 'text-amber-700' : '') :
'text-gray-500';
entry.innerHTML = `
<div class="flex items-center">
<span class="w-6 text-right mr-3 ${rankClass}">${index + 1}.</span>
<span class="font-bold w-12">${score.initials}</span>
</div>
<div class="text-right">
<div class="text-lg">${score.score}</div>
<div class="text-xs text-gray-500">Wave ${score.wave} • ${score.duration}s</div>
</div>
`;
leaderboardList.appendChild(entry);
});
}
// Export scores
function exportScores() {
const scores = JSON.parse(localStorage.getItem('voidloom_scores') || '[]');
exportData.value = JSON.stringify(scores, null, 2);
exportModal.classList.remove('hidden');
}
// Clear all scores
function clearScores() {
if (confirm('Are you sure you want to clear all scores?')) {
localStorage.removeItem('voidloom_scores');
updateLeaderboard();
}
}
// Toggle audio
function toggleAudio() {
gameState.audioEnabled = !gameState.audioEnabled;
audioToggle.innerHTML = gameState.audioEnabled ?
'<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M9.383 3.076A1 1 0 0110 4v12a1 1 0 01-1.707.707L4.586 13H2a1 1 0 01-1-1V8a1 1 0 011-1h2.586l3.707-3.707a1 1 0 011.09-.217zM14.657 2.929a1 1 0 011.414 0A9.972 9.972 0 0117 10a9.972 9.972 0 01-2.929 7.071 1 1 0 01-1.414-1.414A7.971 7.971 0 0017 10c0-2.21-.894-4.208-2.343-5.657a1 1 0 010-1.414zm-2.829 2.828a1 1 0 011.415 0A5.983 5.983 0 0115 10a5.984 5.984 0 01-1.757 4.243 1 1 0 01-1.415-1.415A3.984 3.984 0 0013 10a3.983 3.983 0 00-1.172-2.828 1 1 0 010-1.415z" clip-rule="evenodd" /></svg>' :
'<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M9.383 3.076A1 1 0 0110 4v12a1 1 0 01-1.707.707L4.586 13H2a1 1 0 01-1-1V8a1 1 0 011-1h2.586l3.707-3.707a1 1 0 011.09-.217zM12.828 4.172a1 1 0 011.415 0L16 6.343l1.757-1.757a1 1 0 111.415 1.415L17.414 7.757l1.758 1.757a1 1 0 01-1.415 1.415L16 9.172l-1.757 1.757a1 1 0 01-1.415-1.415L14.586 7.757l-1.757-1.757a1 1 0 010-1.415z" clip-rule="evenodd" /></svg>';
}
// Toggle fullscreen
function toggleFullscreen() {
if (!document.fullscreenElement) {
gameContainer.requestFullscreen().catch(err => {
console.error(`Error attempting to enable fullscreen: ${err.message}`);
});
fullscreenBtn.innerHTML = '↙ Exit Fullscreen';
} else {
document.exitFullscreen();
fullscreenBtn.innerHTML = '⛶ Fullscreen';
}
}
// Show tutorial
function showTutorial() {
tutorialOverlay.classList.add('active');
}
// Initialize game
async function init() {
await initAudio();
initGameGrid();
updateLeaderboard();
// Check if first time playing
if (!localStorage.getItem('voidloom_firstTime')) {
showTutorial();
localStorage.setItem('voidloom_firstTime', 'true');
}
// Event listeners
startButton.addEventListener('click', startGame);
centerNode.addEventListener('click', handleHarmonize);
document.addEventListener('keydown', (e) => {
if (!gameState.isPlaying) return;
switch (e.code) {
case 'Space':
e.preventDefault();
handleHarmonize();
break;
case 'ShiftLeft':
case 'ShiftRight':
toggleTimeSlow(true);
break;
case 'ArrowUp':
case 'KeyW':
moveNode('up');
break;
case 'ArrowRight':
case 'KeyD':
moveNode('right');
break;
case 'ArrowDown':
case 'KeyS':
moveNode('down');
break;
case 'ArrowLeft':
case 'KeyA':
moveNode('left');
break;
}
});
document.addEventListener('keyup', (e) => {
if (e.code === 'ShiftLeft' || e.code === 'ShiftRight') {
toggleTimeSlow(false);
}
});
submitScoreBtn.addEventListener('click', submitScore);
clearScoresBtn.addEventListener('click', clearScores);
exportScoresBtn.addEventListener('click', exportScores);
audioToggle.addEventListener('click', toggleAudio);
fullscreenBtn.addEventListener('click', toggleFullscreen);
tutorialBtn.addEventListener('click', showTutorial);
closeTutorialBtn.addEventListener('click', () => tutorialOverlay.classList.remove('active'));
startFromTutorialBtn.addEventListener('click', () => {
tutorialOverlay.classList.remove('active');
startGame();
});
closeExportBtn.addEventListener('click', () => exportModal.classList.add('hidden'));
copyExportBtn.addEventListener('click', () => {
exportData.select();
document.execCommand('copy');
copyExportBtn.textContent = 'Copied!';
setTimeout(() => {
copyExportBtn.textContent = 'Copy Data';
}, 2000);
});
copyShareBtn.addEventListener('click', () => {
shareCode.select();
document.execCommand('copy');
copyShareBtn.textContent = 'Copied!';
setTimeout(() => {
copyShareBtn.textContent = 'Copy';
}, 2000);
});
// Handle fullscreen change
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) {
fullscreenBtn.innerHTML = '⛶ Fullscreen';
}
});
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', init);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Sharkadre/void-loom" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |