Uhm, I admit – I lost a whole day to figure this stupid stuff out. And in the end, i ended up with just a few lines of code. It's true that simplicity is the best way. And after writing, like, fifty lines of code that didn't work, i decided to delete it, and to start over. Basically, I took every single block in the game, and checked if it's floating. If it was, I moved it down… This would be the result:
This is the code that goes in the GoGravity() method:
// So, bassicaly, i just use
// a couple of loops to go trough
// all the fields.
// Looping through columns:
for (int s = 0; s < iWidth; s++)
{
// Looping through rows:
for (int l = 0; l < iHeight; l++)
{
for (int v = iHeight - 1; v > 0; v--)
{
// In every column, I start
// checking from the bottom.
if (Field[v, s] == 0)
{
// If the field is empty, I
// drop the field above it
// down one block.
Field[v, s] = Field[v - 1, s];
Field[v - 1, s] = 0;
}
}
}
}
// And to show the changes,
// I call the Redraw() method:
Redraw();
And this is the code that goes into the Redraw() method:
//Drawing our field and grid:
DrawGrid()
DrawField()
0 comments:
Post a Comment