I am making a tetris clone for a project. I have done quite a lot, but my clear-cut class has an error that I cannot shake. I created a 10 * 20 grid into which I draw sprites. When I get a line on the floor, it works fine, but above, it just deletes the line and moves everything under it too. This is the code for my clear line class:
public static void ClearLines()
{
for (int CountY = Game1.LandedBlocks.GetLength(1) - 1; CountY >= 0; CountY--)
{
bool clearLine = true;
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
clearLine &= Game1.LandedBlocks[CountX, CountY] != -1;
}
if (clearLine)
{
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
Game1.LandedBlocks[CountX, CountY] = -1;
}
for (int y = Game1.LandedBlocks.GetLength(1) - 1; y > 0; y--)
{
for (int CountX = 0; CountX < Game1.LandedBlocks.GetLength(0); CountX++)
{
Game1.LandedBlocks[CountX, y] = Game1.LandedBlocks[CountX, y - 1];
}
}
CountY++;
Game1.rows++;
Game1.score += 100;
}
}
}
If anyone could shed light on what to do, I would really appreciate it. I tried so much and nothing works :(
source
share