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;
|
foodsEatenRef.current += 1;
|
||||||
|
|
||||||
setScore((prev) => {
|
setScore((prev) => {
|
||||||
let newScore = prev;
|
// Add points at CURRENT level first
|
||||||
let currentLevel = levelRef.current;
|
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) {
|
if (foodsEatenRef.current >= FOODS_PER_LEVEL) {
|
||||||
currentLevel = levelRef.current + 1;
|
const newLevel = levelRef.current + 1;
|
||||||
levelRef.current = currentLevel;
|
levelRef.current = newLevel;
|
||||||
setLevel(currentLevel);
|
setLevel(newLevel);
|
||||||
currentFpsRef.current = INITIAL_FPS + (currentLevel - 1);
|
currentFpsRef.current = INITIAL_FPS + (newLevel - 1);
|
||||||
foodsEatenRef.current = 0;
|
foodsEatenRef.current = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add points at the current (possibly new) level
|
|
||||||
newScore = prev + currentLevel;
|
|
||||||
|
|
||||||
foodManagerRef.current.spawnFood(
|
foodManagerRef.current.spawnFood(
|
||||||
snakeManagerRef.current.snakeBodyRef.current,
|
snakeManagerRef.current.snakeBodyRef.current,
|
||||||
|
|||||||
Reference in New Issue
Block a user