diff options
Diffstat (limited to 'src/tileset.h')
-rw-r--r-- | src/tileset.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/tileset.h b/src/tileset.h index 8a565bc..745ea1d 100644 --- a/src/tileset.h +++ b/src/tileset.h | |||
@@ -1,15 +1,53 @@ | |||
1 | #ifndef TILESET_H_B89AE7A1 | 1 | #ifndef TILESET_H_B89AE7A1 |
2 | #define TILESET_H_B89AE7A1 | 2 | #define TILESET_H_B89AE7A1 |
3 | 3 | ||
4 | #include <string> | ||
5 | #include "renderer.h" | ||
4 | #include "enums.h" | 6 | #include "enums.h" |
7 | #include "consts.h" | ||
5 | 8 | ||
6 | class Tileset { | 9 | class Tileset { |
7 | public: | 10 | public: |
8 | 11 | ||
12 | Tileset(SDL_Renderer* ren, std::string filename) | ||
13 | { | ||
14 | surface_ptr surf(IMG_Load(("../res/" + filename).c_str())); | ||
15 | |||
16 | if (!surf) | ||
17 | { | ||
18 | throw img_error(); | ||
19 | } | ||
20 | |||
21 | image_.reset(SDL_CreateTextureFromSurface(ren, surf.get())); | ||
22 | size_ = { surf->w, surf->h }; | ||
23 | numTiles_ = size_.h() / TILE_SIZE.h(); | ||
24 | } | ||
25 | |||
9 | bool canEntityMoveTo(ColliderType collider, size_t tile) const | 26 | bool canEntityMoveTo(ColliderType collider, size_t tile) const |
10 | { | 27 | { |
11 | return true; | 28 | return true; |
12 | } | 29 | } |
30 | |||
31 | const texture_ptr& getImage() const | ||
32 | { | ||
33 | return image_; | ||
34 | } | ||
35 | |||
36 | const vec2i& getSize() const | ||
37 | { | ||
38 | return size_; | ||
39 | } | ||
40 | |||
41 | size_t getNumTiles() const | ||
42 | { | ||
43 | return numTiles_; | ||
44 | } | ||
45 | |||
46 | private: | ||
47 | |||
48 | texture_ptr image_; | ||
49 | vec2i size_; | ||
50 | size_t numTiles_; | ||
13 | }; | 51 | }; |
14 | 52 | ||
15 | #endif /* end of include guard: TILESET_H_B89AE7A1 */ | 53 | #endif /* end of include guard: TILESET_H_B89AE7A1 */ |