game over
This commit is contained in:
13
semestralka1/src/game/game_over.cpp
Normal file
13
semestralka1/src/game/game_over.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// src/game/game_over.cpp
|
||||
#include "game_over.h"
|
||||
#include <cstdio>
|
||||
|
||||
void show_game_over_screen(int seconds) {
|
||||
printf("\033[2J\033[H");
|
||||
printf("==================================\r\n");
|
||||
printf(" G A M E O V E R \r\n");
|
||||
printf("==================================\r\n");
|
||||
printf(" Vydrzal si %d sekund. \r\n", seconds);
|
||||
printf("==================================\r\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
7
semestralka1/src/game/game_over.h
Normal file
7
semestralka1/src/game/game_over.h
Normal file
@@ -0,0 +1,7 @@
|
||||
// src/game/game_over.h
|
||||
#pragma once
|
||||
#include "mbed.h"
|
||||
|
||||
// Displays game over message with elapsed time.
|
||||
// Takes a Timer that was measuring game duration.
|
||||
void show_game_over_screen(int seconds);
|
||||
@@ -26,6 +26,7 @@ struct GameState {
|
||||
int current_speed;
|
||||
ObstacleRenderData obstacles[MAX_RENDER_OBSTACLES];
|
||||
|
||||
int elapsed_seconds;
|
||||
bool game_over;
|
||||
bool need_redraw;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "mbed.h"
|
||||
#include "player.h"
|
||||
#include "background.h"
|
||||
#include "../game/game_over.h"
|
||||
#include "../game/game_state.h"
|
||||
#include "../game/state.h"
|
||||
#include "../game/animation.h"
|
||||
@@ -46,6 +47,8 @@ void logic_loop(void *arg) {
|
||||
int anim_tick_counter = 0;
|
||||
int tick_counter = 0;
|
||||
bool game_over = false;
|
||||
Timer game_timer;
|
||||
game_timer.start();
|
||||
|
||||
// Spawn first obstacle
|
||||
if (speed >= 5)
|
||||
@@ -138,8 +141,11 @@ void logic_loop(void *arg) {
|
||||
ThisThread::sleep_for(25ms);
|
||||
}
|
||||
|
||||
// final update
|
||||
game_timer.stop();
|
||||
int seconds = static_cast<int>(game_timer.elapsed_time().count() / 1000000);
|
||||
|
||||
g_state_mutex.lock();
|
||||
g_state.elapsed_seconds = seconds;
|
||||
g_state.game_over = true;
|
||||
g_state_mutex.unlock();
|
||||
}
|
||||
@@ -154,8 +160,7 @@ void render_loop_thread() {
|
||||
g_state_mutex.unlock();
|
||||
|
||||
if (over) {
|
||||
printf("\033[2J\033[H");
|
||||
printf("GAME OVER\r\n");
|
||||
show_game_over_screen(local.elapsed_seconds);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user