GameKit
0.0.1a
C++ gamedev tools
include
gk
graphics
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
{
28
u16
tileID
;
29
u16
duration
;
30
};
31
32
u16
getFrameCount
()
const
{
return
m_animation
.size(); }
33
const
AnimationFrame
&
getFrame
(
u16
id
)
const
{
return
m_animation
.at(
id
); }
34
void
addAnimationFrame
(
u16
tileID
,
u16
duration
) {
m_animation
.emplace_back(
AnimationFrame
{
tileID
, duration}); }
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
65
u16
m_tileWidth
;
66
u16
m_tileHeight
;
67
68
std::vector<Tile>
m_tiles
;
69
};
70
71
}
// namespace gk
72
73
#endif // GK_TILESET_HPP_
Texture.hpp
gk
Definition:
AudioPlayer.hpp:21
gk::Tileset::setTile
void setTile(u16 id, Tile &tile)
Definition:
Tileset.hpp:56
gk::Tile
Definition:
Tileset.hpp:23
u16
unsigned short u16
Definition:
IntTypes.hpp:22
gk::Tileset::getTile
const Tile & getTile(u16 id) const
Definition:
Tileset.hpp:55
gk::Tile::m_animation
std::vector< AnimationFrame > m_animation
Definition:
Tileset.hpp:39
gk::Tile::Tile
Tile(u16 type=0)
Definition:
Tileset.hpp:25
gk::Tile::getFrame
const AnimationFrame & getFrame(u16 id) const
Definition:
Tileset.hpp:33
gk::Tile::m_type
u16 m_type
Definition:
Tileset.hpp:41
gk::Tile::getFrameCount
u16 getFrameCount() const
Definition:
Tileset.hpp:32
gk::Texture
Image living on the graphics card that can be used for drawing.
Definition:
Texture.hpp:30
gk::Tile::AnimationFrame::duration
u16 duration
Definition:
Tileset.hpp:29
gk::Tile::addAnimationFrame
void addAnimationFrame(u16 tileID, u16 duration)
Definition:
Tileset.hpp:34
gk::Tileset::m_info
std::vector< u16 > m_info
Definition:
Tileset.hpp:63
gk::Tile::AnimationFrame
Definition:
Tileset.hpp:27
gk::Tileset::tileHeight
u16 tileHeight() const
Definition:
Tileset.hpp:59
gk::Tileset::m_tileWidth
u16 m_tileWidth
Definition:
Tileset.hpp:65
gk::Tileset::tileCount
u16 tileCount() const
Definition:
Tileset.hpp:60
gk::Tileset
Definition:
Tileset.hpp:44
gk::Tileset::m_tileHeight
u16 m_tileHeight
Definition:
Tileset.hpp:66
gk::Tileset::info
const std::vector< u16 > & info() const
Definition:
Tileset.hpp:53
gk::Tile::AnimationFrame::tileID
u16 tileID
Definition:
Tileset.hpp:28
gk::Tileset::m_tiles
std::vector< Tile > m_tiles
Definition:
Tileset.hpp:68
gk::Tile::type
u16 type() const
Definition:
Tileset.hpp:36
gk::Tileset::tileWidth
u16 tileWidth() const
Definition:
Tileset.hpp:58
Generated by
1.8.12