fix(phase1.4): correct score calculation - food worth CURRENT level, level up AFTER
- Add points at CURRENT level FIRST - THEN check if we should level up for NEXT food - Food that triggers level up is worth old level points, not new - Example: eat food 1 (+1), eat food 2 (+1, now level up), eat food 3 (+2) - Correct scoring: 1 + 1 = 2 points at level 1, then 2 + 2 = 4 at level 2
This commit is contained in:
@@ -90,20 +90,17 @@ export function useGameStatus(
|
||||
foodsEatenRef.current += 1;
|
||||
|
||||
setScore((prev) => {
|
||||
let newScore = prev;
|
||||
let currentLevel = levelRef.current;
|
||||
// Add points at CURRENT level first
|
||||
let newScore = prev + levelRef.current;
|
||||
|
||||
// Check if we should level up BEFORE adding points
|
||||
// THEN check if we should level up for NEXT food
|
||||
if (foodsEatenRef.current >= FOODS_PER_LEVEL) {
|
||||
currentLevel = levelRef.current + 1;
|
||||
levelRef.current = currentLevel;
|
||||
setLevel(currentLevel);
|
||||
currentFpsRef.current = INITIAL_FPS + (currentLevel - 1);
|
||||
const newLevel = levelRef.current + 1;
|
||||
levelRef.current = newLevel;
|
||||
setLevel(newLevel);
|
||||
currentFpsRef.current = INITIAL_FPS + (newLevel - 1);
|
||||
foodsEatenRef.current = 0;
|
||||
}
|
||||
|
||||
// Add points at the current (possibly new) level
|
||||
newScore = prev + currentLevel;
|
||||
|
||||
foodManagerRef.current.spawnFood(
|
||||
snakeManagerRef.current.snakeBodyRef.current,
|
||||
|
||||
Reference in New Issue
Block a user