import { useState, useEffect, useCallback } from 'react'; import { ArrowUp, ArrowDown, ArrowLeft, ArrowRight, Repeat } from 'lucide-react'; export default function Game() { const [playerPos, setPlayerPos] = useState({ x: 50, y: 300 }); const [velocity, setVelocity] = useState({ x: 0, y: 0 }); const [isJumping, setIsJumping] = useState(false); const [deaths, setDeaths] = useState(0); const [gameStarted, setGameStarted] = useState(false); // Platform positions - extremely challenging layout const platforms = [ { x: 50, y: 350, width: 100, height: 20 }, { x: 200, y: 280, width: 60, height: 20 }, { x: 320, y: 200, width: 40, height: 20 }, { x: 420, y: 150, width: 30, height: 20 }, { x: 520, y: 100, width: 20, height: 20 }, ]; // Deadly spikes const spikes = [ { x: 150, y: 340, width: 40, height: 30 }, { x: 260, y: 270, width: 40, height: 30 }, { x: 370, y: 190, width: 40, height: 30 }, { x: 470, y: 140, width: 40, height: 30 }, ]; const checkCollision = useCallback((pos, obj) => { return pos.x < obj.x + obj.width && pos.x + 30 > obj.x && pos.y < obj.y + obj.height && pos.y + 30 > obj.y; }, []); const gameLoop = useCallback(() => { if (!gameStarted) return; setPlayerPos(prev => { const newPos = { x: prev.x + velocity.x, y: prev.y + velocity.y }; // Check platform collisions let onPlatform = false; platforms.forEach(platform => { if (checkCollision(newPos, platform)) { if (velocity.y > 0) { newPos.y = platform.y - 30; setVelocity(v => ({ ...v, y: 0 })); setIsJumping(false); onPlatform = true; } } }); // Check spike collisions spikes.forEach(spike => { if (checkCollision(newPos, spike)) { setDeaths(d => d + 1); newPos.x = 50; newPos.y = 300; setVelocity({ x: 0, y: 0 }); } }); // Apply gravity if not on platform if (!onPlatform) { setVelocity(v => ({ ...v, y: Math.min(v.y + 0.5, 10) })); } // Screen boundaries newPos.x = Math.max(0, Math.min(newPos.x, 570)); newPos.y = Math.max(0, Math.min(newPos.y, 370)); return newPos; }); }, [velocity, gameStarted, checkCollision]); useEffect(() => { const interval = setInterval(gameLoop, 16); return () => clearInterval(interval); }, [gameLoop]); const handleKeyDown = useCallback((e) => { if (!gameStarted) return; switch(e.key) { case 'ArrowLeft': setVelocity(v => ({ ...v, x: -5 })); break; case 'ArrowRight': setVelocity(v => ({ ...v, x: 5 })); break; case 'ArrowUp': case ' ': if (!isJumping) { setVelocity(v => ({ ...v, y: -10 })); setIsJumping(true); } break; default: break; } }, [gameStarted, isJumping]); const handleKeyUp = useCallback((e) => { if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { setVelocity(v => ({ ...v, x: 0 })); } }, []); useEffect(() => { window.addEventListener('keydown', handleKeyDown); window.addEventListener('keyup', handleKeyUp); return () => { window.removeEventListener('keydown', handleKeyDown); window.removeEventListener('keyup', handleKeyUp); }; }, [handleKeyDown, handleKeyUp]); return (
{!gameStarted ? (

IMPOSSIBLE GAME

) : ( <>
{/* Player */}
Anime Character
{/* Platforms */} {platforms.map((platform, i) => (
))} {/* Spikes */} {spikes.map((spike, i) => (
))}
Deaths: {deaths}
Move Left
Move Right
Jump
)}
); }