diff --git a/example/src/App.tsx b/example/src/App.tsx index f6815e7..72efe07 100755 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -30,7 +30,7 @@ function App() {
{gameStatus === "waiting" &&

Press space to start

} - {gameStatus === "started" &&

Game running...

} + {gameStatus === "started" &&

Type letters • Press esc to quit

} {gameStatus === "game-over" &&

Game Over! Press space to restart

} {gameStatus === "game-won" &&

You Won! Press space to restart

}
diff --git a/example/src/useKeyBindings.ts b/example/src/useKeyBindings.ts index 63f5690..4dfdf0b 100755 --- a/example/src/useKeyBindings.ts +++ b/example/src/useKeyBindings.ts @@ -25,7 +25,7 @@ export const useKeyBindings = (gameManager: GameManager) => { if (gameStatus === "waiting") return; // quit - if (ev.key === "q" || ev.key === "Q") { + if (ev.key === "Escape") { quitGame(); return; } diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index adb8d96..0b36992 100755 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -3,6 +3,7 @@ import type { GameStatus, FallingLetter } from "../types"; const LETTER_SPEED = 100; // pixels per second const SPAWN_INTERVAL = 1000; // ms between letter spawns +const MAX_ACTIVE_LETTERS = 1; // Only one letter on screen at a time export function useGameStatus(onGameLoopTick?: (deltaTime: number, letters: FallingLetter[]) => void) { const [gameStatus, setGameStatus] = useState("waiting"); @@ -16,8 +17,8 @@ export function useGameStatus(onGameLoopTick?: (deltaTime: number, letters: Fall const deltaTime = currentTime - lastFrameTimeRef.current; lastFrameTimeRef.current = currentTime; - // Spawn new letter if enough time has passed - if (currentTime - lastSpawnRef.current > SPAWN_INTERVAL) { + // Spawn new letter if enough time has passed and no letters active + if (currentTime - lastSpawnRef.current > SPAWN_INTERVAL && lettersRef.current.length < MAX_ACTIVE_LETTERS) { const randomLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26)); // A-Z const randomX = Math.random() * 800; const newLetter: FallingLetter = {