Skip to content
Browse files

Added score text to tetris

  • Loading branch information...
1 parent a4aa96c commit e647a53edea82a70aa80141d6d2f20a4d9400d35 @kthakore kthakore committed
Showing with 7 additions and 1 deletion.
  1. +7 −1 code_listings/tetris.pl
View
8 code_listings/tetris.pl
@@ -20,7 +20,9 @@
);
# create our game objects
-my $score = SDLx::Text->new( font => 'font.ttf', h_align => 'center' );
+my $score_text = SDLx::Text->new( font => 'font.ttf', h_align => 'center', color => [255,255,255,255] );
+my $score = 0;
+
my $back = SDLx::Surface->load( 'data/tetris_back.png' );
my @piece = (undef);
push(@piece, SDLx::Surface->load( "data/tetris_$_.png" )) for(1..7);
@@ -205,6 +207,7 @@ sub server_event_handler {
# deleting lines
foreach(@to_delete) {
splice(@{$store}, $_*10, 10);
+ $score++;
}
# adding blank rows to the top
@@ -249,6 +252,9 @@ sub server_event_handler {
}
}
}
+
+ $score_text->write_xy( $app, 248,20, "Next Piece");
+ $score_text->write_xy( $app, 248,240, "Score: ".$score);
# finally, we update the screen
$app->update;
}

0 comments on commit e647a53

Please sign in to comment.
Something went wrong with that request. Please try again.