"use client"; import { useState, useEffect, useRef } from "react"; export default function DarknetPingPong() { const [ballPos, setBallPos] = useState({ x: 50, y: 50 }); const [isHaunted, setIsHaunted] = useState(false); const containerRef = useRef(null); // Simulate shared state with a simple interval or WebSocket-like behavior // In a real app, this would use Pusher, Socket.io, or a backend useEffect(() => { const interval = setInterval(() => { // Random "haunted" movement to simulate other users or ghosts if (Math.random() > 0.95) { setBallPos(prev => ({ x: Math.max(10, Math.min(90, prev.x + (Math.random() - 0.5) * 20)), y: Math.max(10, Math.min(90, prev.y + (Math.random() - 0.5) * 20)), })); setIsHaunted(true); setTimeout(() => setIsHaunted(false), 500); } }, 2000); return () => clearInterval(interval); }, []); const handleBallClick = (e: React.MouseEvent) => { if (!containerRef.current) return; const rect = containerRef.current.getBoundingClientRect(); const x = ((e.clientX - rect.left) / rect.width) * 100; const y = ((e.clientY - rect.top) / rect.height) * 100; // Move ball to click position setBallPos({ x, y }); // In a real app, you'd emit this to a server: // socket.emit('move_ball', { x, y }); }; return (
{/* The Haunted Ball */}
void
Shared Entity #001 - Darknet Ping Pong
); }