summary refs log tree commit diff stats
path: root/src/tileset.h
blob: 745ea1d45d0015921ba5101c319420f5ec62173b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef TILESET_H_B89AE7A1
#define TILESET_H_B89AE7A1

#include <string>
#include "renderer.h"
#include "enums.h"
#include "consts.h"

class Tileset {
public:

  Tileset(SDL_Renderer* ren, std::string filename)
  {
    surface_ptr surf(IMG_Load(("../res/" + filename).c_str()));

    if (!surf)
    {
      throw img_error();
    }

    image_.reset(SDL_CreateTextureFromSurface(ren, surf.get()));
    size_ = { surf->w, surf->h };
    numTiles_ = size_.h() / TILE_SIZE.h();
  }

  bool canEntityMoveTo(ColliderType collider, size_t tile) const
  {
    return true;
  }

  const texture_ptr& getImage() const
  {
    return image_;
  }

  const vec2i& getSize() const
  {
    return size_;
  }

  size_t getNumTiles() const
  {
    return numTiles_;
  }

private:

  texture_ptr image_;
  vec2i size_;
  size_t numTiles_;
};

#endif /* end of include guard: TILESET_H_B89AE7A1 */