From e5091a33e7e2e8dce0c91fa2787f40c01ce38b9b Mon Sep 17 00:00:00 2001 From: Priec Date: Sun, 14 Dec 2025 17:15:50 +0100 Subject: [PATCH] restart button on the game over is now wokring properly well --- semestralka1/src/game/game_over.cpp | 43 ++++++++++++++++++++++++++++- semestralka1/src/main.cpp | 4 ++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/semestralka1/src/game/game_over.cpp b/semestralka1/src/game/game_over.cpp index 232408c..e48b39f 100644 --- a/semestralka1/src/game/game_over.cpp +++ b/semestralka1/src/game/game_over.cpp @@ -1,13 +1,54 @@ // src/game/game_over.cpp #include "game_over.h" +#include "mbed.h" +#include "../render/background.h" +#include "../assets/background_frame.h" #include void show_game_over_screen(int seconds) { printf("\033[2J\033[H"); + + // 34 znakov vo vypise + const int box_width = 34; + const int start_col = (VIEW_WIDTH - box_width) / 2; + + const int box_height = 6; + const int top_padding = (VIEW_HEIGHT - box_height) / 2; + + // Empty rows + for (int i = 0; i < top_padding; i++) { + printf("\r\n"); + } + + for (int i = 0; i < start_col; i++) printf(" "); printf("==================================\r\n"); + + for (int i = 0; i < start_col; i++) printf(" "); printf(" G A M E O V E R \r\n"); + + for (int i = 0; i < start_col; i++) printf(" "); printf("==================================\r\n"); - printf(" Vydrzal si %d sekund. \r\n", seconds); + + for (int i = 0; i < start_col; i++) printf(" "); + printf(" Doba hry %d sekund. \r\n", seconds); + + for (int i = 0; i < start_col; i++) printf(" "); printf("==================================\r\n"); + printf(" Stlacte tlacidlo pre restart. \r\n"); + + fflush(stdout); + + DigitalIn restart_button(BUTTON1); + + int initial_state = restart_button.read(); + while (restart_button.read() == initial_state) { + ThisThread::sleep_for(50ms); + } + int new_state = restart_button.read(); + while (restart_button.read() == new_state) { + ThisThread::sleep_for(50ms); + } + + printf("\033[2J\033[H"); fflush(stdout); } diff --git a/semestralka1/src/main.cpp b/semestralka1/src/main.cpp index 2e0b860..66ea567 100644 --- a/semestralka1/src/main.cpp +++ b/semestralka1/src/main.cpp @@ -21,5 +21,7 @@ int main(void) { serial_port.set_format(8, BufferedSerial::None, 1); printf("Baud: %d, Format: 8-N-1\r\n", BAUD_RATE); - render_loop(1); + while (true) { + render_loop(4); + } }