diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-12-23 15:28:05 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-12-23 15:28:05 +0100 |
| commit | c055eeef6d41269d11b2ddf7f9aba6f8867da65d (patch) | |
| tree | dcd9baaec93c50a8ab49656be86ea248c17421fd /core/src/cpp/map.h | |
Diffstat (limited to 'core/src/cpp/map.h')
| -rw-r--r-- | core/src/cpp/map.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/core/src/cpp/map.h b/core/src/cpp/map.h new file mode 100644 index 0000000..668305b --- /dev/null +++ b/core/src/cpp/map.h @@ -0,0 +1,63 @@ +#pragma once + +#include <cassert> + +#include <SDL.h> + +#include "size2d.h" +#include "sprite.h" + +struct Map { + explicit Map(SDL_Renderer* renderer); + + // draw the level in the renderer window + void draw(); + + int get(const int i, const int j) const { // retreive the cell, transform character to texture index + assert(i >= 0 && j >= 0 && i < size.w && j < size.h); + return level[i + j * size.w] - '0'; + } + + bool is_empty(const int i, const int j) const { + assert(i >= 0 && j >= 0 && i < size.w && j < size.h); + return level[i + j * size.w] == ' '; + } + + /*! + * \brief renderer - draw here + */ + SDL_Renderer* renderer{nullptr}; + /*! + * \brief tile_size - tile size in the renderer window + */ + size2d<int> tile_size{0, 0}; + + /*! + * \brief textures - textures to be drawn + */ + const Sprite textures; + + /*! + * \brief size - overall map dimensions + */ + static constexpr size2d<int> size{16, 12}; + + /*! + * \brief level - the array level[] has the length + * w*h+1 (+1 for the null character), space character for empty tiles, + * digits indicate the texture index to be used per tile + */ + static constexpr char level[size.w * size.h + 1] = " 123451234012340" + "5 5" + "0 0" + "5 5 5" + "0 0 0" + "512340 12345 5" + "0 0" + "5 51" + "0 50 12" + "5 51234" + "0 12345" + "1234012345052500"; +}; + |
