It sounds like you want the game’s falling speed (fallTime) to decrease every 10 levels, but currently, it only decreases once when the player reaches the 10th level. This issue likely arises because the current LevelUp method decreases fallTime every time a new level is reached, but due to how levels are calculated or how LevelUp is invoked, it only effectively triggers once.
To achieve the desired behavior—changing the falling speed every 10 levels—you need to adjust the LevelUp method to detect when the player crosses each 10-level milestone (i.e., levels 10, 20, 30, etc.) and adjust the speed accordingly.
Here’s how you can modify your LevelUp method to accomplish this:
-
Calculate the New Level Correctly:
- Ensure that
newLevel is calculated based on the total lines cleared divided by lines per level.
- If you intend each level to represent a block of lines (e.g., 10 lines per level), integer division will suffice.
-
Detect Crossing 10-Level Milestones:
- Determine if the player has reached a new milestone (every 10 levels).
- Update
fallTime only when a new 10-level milestone is crossed.
-
Handle Multiple Milestones in a Single Update:
- If the player gains multiple levels at once (e.g., clearing enough lines to jump from level 9 to 21), ensure that
fallTime is adjusted for each milestone crossed.
Revised LevelUp Method
void LevelUp()
{
// Calculate the new level based on lines cleared
int newLevel = (LinesCleared / linesPerLevel) + 1;
// Check if the new level is higher than the current level
if (newLevel > currentLevel)
{
// Iterate through each level gained to handle multiple milestones
for (int lvl = currentLevel + 1; lvl <= newLevel; lvl++)
{
// Check if the current level is a multiple of 10
if (lvl % 10 == 0)
{
// Decrease fallTime, ensuring it doesn't go below 0.1f
fallTime = Mathf.Max(0.1f, fallTime - 0.2f);
// Optionally, you can also increase the difficulty or add other effects here
Debug.Log($"Milestone reached! Level: {lvl}. New fall time: {fallTime}");
}
else
{
// For non-milestone levels, you can still log the level up if desired
Debug.Log($"Level Up! New level: {lvl}");
}
}
// Update the current level to the new level
currentLevel = newLevel;
}
}
Explanation of the Changes
-
Loop Through Levels Gained:
- By looping from
currentLevel + 1 to newLevel, you account for cases where multiple levels are gained at once. This ensures that fallTime is adjusted for each 10-level milestone crossed during a single update.
-
Check for Milestones:
- The condition
if (lvl % 10 == 0) checks whether the current level in the loop is a multiple of 10. If it is, fallTime is decreased.
-
Safeguard fallTime:
- Using
Mathf.Max(0.1f, fallTime - 0.2f) ensures that fallTime never goes below 0.1f, preventing the game from becoming unplayably fast.
-
Logging:
- The
Debug.Log statements provide feedback in the console, indicating when a level is increased and when a milestone is reached.
Additional Recommendations
By implementing these changes, fallTime will decrease every 10 levels, enhancing the game's difficulty progression as intended.