diff options
Diffstat (limited to 'src/games/minesweeper')
| -rw-r--r-- | src/games/minesweeper/Minesweeper.cpp | 33 | ||||
| -rw-r--r-- | src/games/minesweeper/Minesweeper.hpp | 15 |
2 files changed, 32 insertions, 16 deletions
diff --git a/src/games/minesweeper/Minesweeper.cpp b/src/games/minesweeper/Minesweeper.cpp index f6b02ac..9b07362 100644 --- a/src/games/minesweeper/Minesweeper.cpp +++ b/src/games/minesweeper/Minesweeper.cpp @@ -8,13 +8,27 @@ #include <random> #include <cstdio> + // Todo: winning condition (maybe: total_cells - uncovered_cells = mine_count) + +static constexpr Color s_mine_count_colors[8] = { + {0.0f, 0.0f, 1.0f, 1.0f}, // Blue + {0.0f, 0.5f, 0.0f, 1.0f}, // Green + {1.0f, 0.0f, 0.0f, 1.0f}, // Red + {0.0f, 0.0f, 0.5f, 1.0f}, // Dark Blue + {0.5f, 0.0f, 0.0f, 1.0f}, // Dark Red + {0.0f, 0.5f, 0.5f, 1.0f}, // Cyan + {0.0f, 0.0f, 0.0f, 1.0f}, // Black + {0.5f, 0.5f, 0.5f, 1.0f}, // Gray +}; + + Minesweeper::Minesweeper() { - m_font.Init("fonts/dejavu_ttf/DejaVuSansMono.ttf", 16); - for (uint32_t i = 0; i < m_digit_glyphs.size(); ++i) { - m_font.LoadGlyph(m_digit_glyphs[i], i + '0'); + bool font_init = m_font.Init(s_font_filepath, 22); + if (!font_init) { + printf("m_font.Init(...) failed\n"); } } @@ -39,7 +53,7 @@ Minesweeper::Reset(Difficulty difficulty) } - float cell_size = 1.2f * std::min(m_world_height / MAX_MAP_HEIGHT, m_world_width / MAX_MAP_WIDTH); + float cell_size = 1.2f * std::min(m_world_height / max_map_height, m_world_width / max_map_width); float cell_size_without_border = 0.8f * cell_size; V2F32 grid_size = { @@ -399,11 +413,14 @@ Minesweeper::DrawBoard() 256.0f * cell_pos.y, 256.0f }; - size_t mine_count_val = (size_t)m_adjacent_mine_counts[y*m_grid_width + x]; - g_renderer.PushMonoBitmap( - m_digit_glyphs[mine_count_val].bitmap, + int32_t mine_count = m_adjacent_mine_counts[y*m_grid_width + x]; + + Color color = s_mine_count_colors[mine_count-1]; + Glyph& glyph = m_font.GetGlyph('0' + (char32_t)mine_count); + g_renderer.PushAlphaBitmap( + glyph.bitmap, mine_count_pos, - Color{0.0f, 0.0f, 0.0f, 0.0f}); + color); } } } diff --git a/src/games/minesweeper/Minesweeper.hpp b/src/games/minesweeper/Minesweeper.hpp index 867ca6a..24672f0 100644 --- a/src/games/minesweeper/Minesweeper.hpp +++ b/src/games/minesweeper/Minesweeper.hpp @@ -48,9 +48,9 @@ private: private: - static constexpr int32_t MAX_MAP_HEIGHT = 32; - static constexpr int32_t MAX_MAP_WIDTH = 32; - static constexpr std::string_view s_FontFilepath = "./fonts/dejavu_ttf/DejaVuSans.ttf"; + static constexpr int32_t max_map_height = 32; + static constexpr int32_t max_map_width = 32; + static constexpr const char* s_font_filepath = "./fonts/dejavu_ttf/DejaVuSans.ttf"; private: @@ -64,13 +64,12 @@ private: V2F32 m_cell_outer_size; V2F32 m_cell_inner_size; - uint32_t m_is_covered_bitmap[MAX_MAP_HEIGHT] {}; - uint32_t m_is_flagged_bitmap[MAX_MAP_HEIGHT] {}; - uint32_t m_is_mine_bitmap[MAX_MAP_HEIGHT] {}; - int32_t m_adjacent_mine_counts[MAX_MAP_WIDTH * MAX_MAP_HEIGHT] {}; + uint32_t m_is_covered_bitmap[max_map_height] {}; + uint32_t m_is_flagged_bitmap[max_map_height] {}; + uint32_t m_is_mine_bitmap[max_map_height] {}; + int32_t m_adjacent_mine_counts[max_map_width * max_map_height] {}; Font m_font; - std::array<Glyph, 9> m_digit_glyphs; }; |
