diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-21 03:56:19 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-21 03:56:19 +0100 |
| commit | 88f5eb3447073fc6a87786da6a9b6b788f9bde66 (patch) | |
| tree | 2fb30f59e539b08cb53c4b7d7336238acc4ca1ed /src/graphics.cpp | |
| parent | 166c06083212a5657fcaf03328bf530f9eb8b0d8 (diff) | |
| download | mario_sokoban-88f5eb3447073fc6a87786da6a9b6b788f9bde66.tar.gz mario_sokoban-88f5eb3447073fc6a87786da6a9b6b788f9bde66.tar.bz2 mario_sokoban-88f5eb3447073fc6a87786da6a9b6b788f9bde66.zip | |
Added basic game init with string and game display
Diffstat (limited to 'src/graphics.cpp')
| -rw-r--r-- | src/graphics.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp index c434bcc..5846ab7 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -37,7 +37,31 @@ void Graphics::update() void Graphics::drawGame() { + for (size_t i = 0; i < m_game.getHeight(); i++) + for (size_t j = 0; j < m_game.getWidth(); j++) + drawCell(m_game.get(i, j), i, j); +} + +void Graphics::drawCell(Game::Cell cell, int y, int x) +{ + SDL_Rect r; + switch (cell) + { + case Game::CellWall: + SDL_SetRenderDrawColor(m_renderer, 40, 40, 100, 255); + break; + case Game::CellEmpty: + SDL_SetRenderDrawColor(m_renderer, 10, 10, 10, 255); + break; + default: + SDL_SetRenderDrawColor(m_renderer, 150, 150, 150, 255); + } + r.x = x * (m_width / m_game.getWidth()); + r.y = y * (m_height / m_game.getHeight()); + r.w = m_width / m_game.getWidth(); + r.h = m_height / m_game.getHeight(); + SDL_RenderFillRect(m_renderer, &r); } void Graphics::handleEvent() |
