From 8d2f22affee0ce987b69e610d1f42ac4bc1cf067 Mon Sep 17 00:00:00 2001 From: Nicolas Sauzede Date: Fri, 2 Oct 2020 15:42:05 +0200 Subject: [PATCH] tetris: display lines (#6533) --- examples/tetris/tetris.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/tetris/tetris.v b/examples/tetris/tetris.v index c44111b1fe..f88b9099bf 100644 --- a/examples/tetris/tetris.v +++ b/examples/tetris/tetris.v @@ -104,6 +104,8 @@ struct Game { mut: // Score of the current game score int + // Lines of the current game + lines int // State of the current game state GameState // Position of the current tetro @@ -205,6 +207,7 @@ fn (mut g Game) init_game() { last_row[j] = - 1 } g.score = 0 + g.lines = 0 g.state = .running } @@ -308,6 +311,7 @@ fn (mut g Game) delete_completed_line(y int) { } } g.score += 10 + g.lines++ // Move everything down by 1 position for yy := y - 1; yy >= 1; yy-- { for x := 1; x <= field_width; x++ { @@ -387,6 +391,8 @@ fn (g &Game) draw_field() { fn (mut g Game) draw_ui() { g.gg.draw_text(1, 3, g.score.str(), text_cfg) + lines := g.lines.str() + g.gg.draw_text(win_width - lines.len * text_size, 3, lines, text_cfg) if g.state == .gameover { g.gg.draw_rect(0, win_height / 2 - text_size, win_width, 5 * text_size, ui_color)