feat: add dynamic ship tracking for sentences mode
- Ship now moves to center of each character as you type - Calculate and store X position of current character during rendering - Ship smoothly tracks typing progress across both lines - Handles line transitions seamlessly - Creates engaging targeting effect as ship 'shoots' each letter
This commit is contained in:
@@ -37,6 +37,8 @@ export type FallingLetter = {
|
||||
// For line transitions in sentences/paragraphs
|
||||
lineTransition?: boolean;
|
||||
lineTransitionTime?: number;
|
||||
// For ship tracking in sentences
|
||||
currentCharX?: number; // X position of current character to type
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@@ -359,6 +359,8 @@ export function useBoard() {
|
||||
ctx.fillStyle = `rgba(0, 255, 0, ${topOpacity})`; // Green - completed
|
||||
} else if (charIdx === charIndex) {
|
||||
ctx.fillStyle = `rgba(255, 255, 0, ${topOpacity})`; // Yellow - current
|
||||
// Store position of current character for ship tracking
|
||||
letter.currentCharX = line2X + ctx.measureText(char).width / 2;
|
||||
} else {
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${topOpacity})`; // White - remaining
|
||||
}
|
||||
@@ -380,6 +382,8 @@ export function useBoard() {
|
||||
ctx.fillStyle = "#00ff00"; // Green - completed
|
||||
} else if (i === charIndex) {
|
||||
ctx.fillStyle = "#ffff00"; // Yellow - current
|
||||
// Store position of current character for ship tracking
|
||||
letter.currentCharX = line1X + ctx.measureText(char).width / 2;
|
||||
} else {
|
||||
ctx.fillStyle = "#ffffff"; // White - remaining
|
||||
}
|
||||
|
||||
+11
-4
@@ -28,7 +28,7 @@ export function useGame(
|
||||
gameStatusManager.updatePlayerX(playerPos.x);
|
||||
|
||||
// For words/letters, auto-track to falling letters
|
||||
// For sentences/paragraphs, keep ship centered
|
||||
// For sentences/paragraphs, track to current character position
|
||||
if (gameModeRef.current !== 'sentences' && gameModeRef.current !== 'paragraphs') {
|
||||
if (letters.length > 0) {
|
||||
const letter = letters[0];
|
||||
@@ -37,9 +37,16 @@ export function useGame(
|
||||
|
||||
cursorManager.moveTowardTarget(deltaTime);
|
||||
} else {
|
||||
// Keep ship centered for sentence/paragraph mode
|
||||
cursorManager.setTargetX(400); // Canvas center
|
||||
cursorManager.moveTowardTarget(deltaTime); // Move to center but don't track letters
|
||||
// For sentences: track to current character position
|
||||
if (letters.length > 0) {
|
||||
const letter = letters[0];
|
||||
// Use the stored character position or default to center
|
||||
const targetX = letter.currentCharX || 400;
|
||||
cursorManager.setTargetX(targetX);
|
||||
} else {
|
||||
cursorManager.setTargetX(400); // Default to center when no letters
|
||||
}
|
||||
cursorManager.moveTowardTarget(deltaTime);
|
||||
}
|
||||
|
||||
renderBoardWrapped(letters);
|
||||
|
||||
Reference in New Issue
Block a user