Permalink
Browse files

[examples/gtk-tetris.pl] clear lines that are full of blocks

  • Loading branch information...
1 parent d2614f8 commit b08643dd0c91c3c663c95d4b41512351edabeaae @mberends mberends committed Oct 2, 2011
Showing with 19 additions and 2 deletions.
  1. +19 −2 examples/gtk-tetris.pl
View
@@ -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
@@ -113,7 +113,7 @@ ($deltaX, $deltaY)
$canMove;
}
-sub MoveDownOne()
+sub TryMovePieceDown()
{
if CanMovePiece(0, 1) {
++$pieceY;
@@ -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();
}
}

0 comments on commit b08643d

Please sign in to comment.