Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[examples/gtk-tetris.pl] clear lines that are full of blocks
  • Loading branch information
mberends committed Oct 2, 2011
1 parent d2614f8 commit b08643d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions examples/gtk-tetris.pl
Expand Up @@ -78,7 +78,7 @@ ($sender, $eventargs)
$offsetX = (($windowWidth - ($scale * matrixColumns))/2).Int;
$offsetY = (($windowHeight - ($scale * matrixRows ))/2).Int;
$cc.SetSourceRGB(0, 0, 0.4.Num); $cc.Paint; # Dark blue background
MoveDownOne();
TryMovePieceDown(); # also clears full rows and makes new pieces
DrawMatrix($cc);
DrawPiece($cc);
$cc.dispose-hack; # Should be $cc.IDisposable.Dispose but currently
Expand Down Expand Up @@ -113,7 +113,7 @@ ($deltaX, $deltaY)
$canMove;
}

sub MoveDownOne()
sub TryMovePieceDown()
{
if CanMovePiece(0, 1) {
++$pieceY;
Expand All @@ -122,6 +122,23 @@ ()
for @piece -> $x, $y {
@matrix[$y+$pieceY][$x+$pieceX] = $colorindex;
}
# Look for full rows and remove them. TODO: keep score.
for ^matrixRows -> $row {
my $full = True;
for ^matrixColumns -> $column {
if @matrix[$row][$column] == 0 { $full = False; }
}
if $full {
loop (my $moveRow = $row; $moveRow > 0; --$moveRow) {
for ^matrixColumns -> $column {
@matrix[$moveRow][$column] = @matrix[$moveRow-1][$column];
}
}
for ^matrixColumns -> $column {
@matrix[0][$column] = 0;
}
}
}
CreatePiece();
}
}
Expand Down

0 comments on commit b08643d

Please sign in to comment.