aboutsummaryrefslogtreecommitdiff
path: root/src/games/Game.cpp
blob: 0e6af1c2b3eff44553df83e8be6f19523bd5ddc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <games/Game.hpp>
#include <games/tetris/Tetris.hpp>
#include <games/snake/Snake.hpp>
#include <games/minesweeper/Minesweeper.hpp>

#include <assert.h>
#include <memory>


std::unique_ptr<Game>
Game::Select(GameType type)
{
    switch (type) {
    case no_game: {
        return nullptr;
    } break;

    case minesweeper: {
        return std::make_unique<Minesweeper>();
    } break;

    case snake: {
        return std::make_unique<Snake>();
    } break;

    case tetris: {
        return std::make_unique<Tetris>();
    } break;

    InvalidDefaultCase;
    }

    return nullptr;
}

float
Game::ProcessDt()
{
    uint64_t tnow_milliseconds = SDL_GetTicks();
    uint64_t tlast_milliseconds = m_tlast_milliseconds;
    uint64_t dt_milliseconds = tnow_milliseconds - tlast_milliseconds;

    float dt_seconds = float(dt_milliseconds) / 1000.0f;
    dt_seconds += m_dt_remaining_seconds;

    m_tlast_milliseconds = tnow_milliseconds;
    m_dt_remaining_seconds = 0.0f;

    return dt_seconds;
}

void
Game::DrawGameOverMenu()
{
    ImGui::Begin("DefaultGameOverMenu", nullptr, s_imgui_window_flags_menu);
    ImGui::Text("Game Over.");
    if (ImGui::Button("Play Again")) {
        m_game_status = game_starting;
    }
    if (ImGui::Button("Exit")) {
        m_game_status = game_exit;
    }
    ImGui::End();
}

void
Game::DrawGamePausedMenu()
{
    ImGui::Begin("DefaultGamePauseMenu", nullptr, s_imgui_window_flags_menu);
    if (ImGui::Button("Resume")) {
        m_game_status = game_resuming;
    }
    if (ImGui::Button("Restart")) {
        m_game_status = game_starting;
    }
    if (ImGui::Button("Exit")) {
        m_game_status = game_exit;
    }
    ImGui::End();
}