GameKit  0.0.1a
C++ gamedev tools
Tileset.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Tileset.hpp
5  *
6  * Description:
7  *
8  * Created: 15/02/2019 19:23:29
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_TILESET_HPP_
15 #define GK_TILESET_HPP_
16 
17 #include <vector>
18 
19 #include <gk/gl/Texture.hpp>
20 
21 namespace gk {
22 
23 class Tile {
24  public:
25  Tile(u16 type = 0) : m_type(type) {}
26 
27  struct AnimationFrame {
30  };
31 
32  u16 getFrameCount() const { return m_animation.size(); }
33  const AnimationFrame &getFrame(u16 id) const { return m_animation.at(id); }
35 
36  u16 type() const { return m_type; }
37 
38  private:
39  std::vector<AnimationFrame> m_animation;
40 
41  u16 m_type = 0;
42 };
43 
44 class Tileset : public gk::Texture {
45  public:
46  Tileset() = default;
47  Tileset(const Tileset &) = delete;
48  Tileset(Tileset &&tileset) = default;
49  Tileset(const std::string &filename, const std::string &configFile);
50 
51  void load(const std::string &filename, const std::string &configFile);
52 
53  const std::vector<u16> &info() const { return m_info; }
54 
55  const Tile &getTile(u16 id) const { return m_tiles.at(id); }
56  void setTile(u16 id, Tile &tile) { m_tiles.at(id) = tile; }
57 
58  u16 tileWidth() const { return m_tileWidth; }
59  u16 tileHeight() const { return m_tileHeight; }
60  u16 tileCount() const { return m_tiles.size(); }
61 
62  private:
63  std::vector<u16> m_info;
64 
67 
68  std::vector<Tile> m_tiles;
69 };
70 
71 } // namespace gk
72 
73 #endif // GK_TILESET_HPP_
void setTile(u16 id, Tile &tile)
Definition: Tileset.hpp:56
unsigned short u16
Definition: IntTypes.hpp:22
const Tile & getTile(u16 id) const
Definition: Tileset.hpp:55
std::vector< AnimationFrame > m_animation
Definition: Tileset.hpp:39
Tile(u16 type=0)
Definition: Tileset.hpp:25
const AnimationFrame & getFrame(u16 id) const
Definition: Tileset.hpp:33
u16 m_type
Definition: Tileset.hpp:41
u16 getFrameCount() const
Definition: Tileset.hpp:32
Image living on the graphics card that can be used for drawing.
Definition: Texture.hpp:30
void addAnimationFrame(u16 tileID, u16 duration)
Definition: Tileset.hpp:34
std::vector< u16 > m_info
Definition: Tileset.hpp:63
u16 tileHeight() const
Definition: Tileset.hpp:59
u16 m_tileWidth
Definition: Tileset.hpp:65
u16 tileCount() const
Definition: Tileset.hpp:60
u16 m_tileHeight
Definition: Tileset.hpp:66
const std::vector< u16 > & info() const
Definition: Tileset.hpp:53
std::vector< Tile > m_tiles
Definition: Tileset.hpp:68
u16 type() const
Definition: Tileset.hpp:36
u16 tileWidth() const
Definition: Tileset.hpp:58