feat: enforce one active letter at a time (character mode)
- Add MAX_ACTIVE_LETTERS constant set to 1 - Only spawn new letter if no letters are currently active - Prepare for future game modes (word, sentence, paragraph) - Change keybindings to use Escape instead of Q
This commit is contained in:
+1
-1
@@ -30,7 +30,7 @@ function App() {
|
||||
|
||||
<div className="text-center text-sm text-muted-foreground">
|
||||
{gameStatus === "waiting" && <p>Press <kbd className="px-2 py-1 bg-muted rounded">space</kbd> to start</p>}
|
||||
{gameStatus === "started" && <p>Game running...</p>}
|
||||
{gameStatus === "started" && <p>Type letters • Press <kbd className="px-2 py-1 bg-muted rounded">esc</kbd> to quit</p>}
|
||||
{gameStatus === "game-over" && <p>Game Over! Press <kbd className="px-2 py-1 bg-muted rounded">space</kbd> to restart</p>}
|
||||
{gameStatus === "game-won" && <p>You Won! Press <kbd className="px-2 py-1 bg-muted rounded">space</kbd> to restart</p>}
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<GameStatus>("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 = {
|
||||
|
||||
Reference in New Issue
Block a user