diff options
Diffstat (limited to 'src/games/minesweeper/Minesweeper.cpp')
| -rw-r--r-- | src/games/minesweeper/Minesweeper.cpp | 33 |
1 files changed, 25 insertions, 8 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); } } } |
