#pragma once #include #include #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 tile_size{0, 0}; /*! * \brief textures - textures to be drawn */ const Sprite textures; /*! * \brief size - overall map dimensions */ static constexpr size2d 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"; };