From 81e7bc756d6fa851f9a3071e8fbf43381e9ce49e Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Wed, 5 Nov 2025 09:12:40 +0000 Subject: [PATCH] Make sentences and paragraphs spawn offscreen from top for smoother entrance --- example/src/usePlatformHook/useStateMachine.ts | 2 +- src/useGameStatus/useGameStatus.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/example/src/usePlatformHook/useStateMachine.ts b/example/src/usePlatformHook/useStateMachine.ts index 455c985..3ec877c 100644 --- a/example/src/usePlatformHook/useStateMachine.ts +++ b/example/src/usePlatformHook/useStateMachine.ts @@ -1,5 +1,5 @@ import { useEffect, useRef } from "react"; -import type { GameMode, GameManager } from "../../../src"; +import type { GameMode, GameManager } from "@vimazing/the-last-startyper"; import type { TestScenario } from "./testStateMachines"; interface UseStateMachineProps { diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index 8e702fe..26f7759 100755 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -65,11 +65,18 @@ export function useGameStatus(_onGameLoopTick?: (deltaTime: number, letters: Fal const fullText = getRandomWord(gameModeRef.current, wordListRef.current); const firstChar = fullText[0].toUpperCase(); - // For sentences/paragraphs, spawn centered. For letters/words, spawn randomly - const isCenteredMode = gameModeRef.current === 'sentences' || gameModeRef.current === 'paragraphs'; - const spawnWidth = CANVAS_WIDTH - MARGIN_LEFT - MARGIN_RIGHT; - const spawnX = isCenteredMode ? CANVAS_WIDTH / 2 : (MARGIN_LEFT + Math.random() * spawnWidth); - const randomY = Math.random() * 150; // Between 0-150 (top half of screen) + // For sentences/paragraphs, spawn centered. For letters/words, spawn randomly + const isCenteredMode = gameModeRef.current === 'sentences' || gameModeRef.current === 'paragraphs'; + const spawnWidth = CANVAS_WIDTH - MARGIN_LEFT - MARGIN_RIGHT; + const spawnX = isCenteredMode ? CANVAS_WIDTH / 2 : (MARGIN_LEFT + Math.random() * spawnWidth); + + // Sentences and paragraphs spawn offscreen from top; letters/words spawn in top half + let randomY: number; + if (isCenteredMode) { + randomY = -100 - Math.random() * 100; // Offscreen: -200 to -100 + } else { + randomY = Math.random() * 150; // Between 0-150 (top half of screen) + } const newLetter: FallingLetter = { id: `${currentTime}-${spawnX}`,