fix(phase1.4): save current level BEFORE leveling up for score calculation
- Save pointsToAdd = levelRef.current at start of setScore - Use saved value for scoring, not levelRef.current which gets changed - This ensures 1st food adds 1 point at level 1, then level up to 2 - 2nd food adds 2 points at level 2, then level up to 3, etc. - Correct sequence: +1, +2, +3, +4... with level ups after each
This commit is contained in:
@@ -95,8 +95,11 @@ export function useGameStatus(
|
|||||||
console.log(`[FOOD] Eaten: ${foodsEatenRef.current}, Will Level Up: ${willLevelUp}, Current Level: ${levelRef.current}`);
|
console.log(`[FOOD] Eaten: ${foodsEatenRef.current}, Will Level Up: ${willLevelUp}, Current Level: ${levelRef.current}`);
|
||||||
|
|
||||||
setScore((prev) => {
|
setScore((prev) => {
|
||||||
|
// Save the current level BEFORE any changes
|
||||||
|
const pointsToAdd = levelRef.current;
|
||||||
|
|
||||||
// Add points at CURRENT level
|
// Add points at CURRENT level
|
||||||
let newScore = prev + levelRef.current;
|
let newScore = prev + pointsToAdd;
|
||||||
|
|
||||||
// Level up AFTER this food if threshold was reached
|
// Level up AFTER this food if threshold was reached
|
||||||
if (willLevelUp) {
|
if (willLevelUp) {
|
||||||
@@ -108,7 +111,7 @@ export function useGameStatus(
|
|||||||
console.log(`[LEVELUP] New Level: ${newLevel}`);
|
console.log(`[LEVELUP] New Level: ${newLevel}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[SCORE] Adding ${levelRef.current} points, Total: ${newScore}`);
|
console.log(`[SCORE] Adding ${pointsToAdd} points, Total: ${newScore}`);
|
||||||
|
|
||||||
foodManagerRef.current.spawnFood(
|
foodManagerRef.current.spawnFood(
|
||||||
snakeManagerRef.current.snakeBodyRef.current,
|
snakeManagerRef.current.snakeBodyRef.current,
|
||||||
|
|||||||
Reference in New Issue
Block a user