void-loom / index.html
Joshua Soro
Add 3 files
8d71d5e verified
Raw History Blame Contribute Delete
42.4 kB
<!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>