LPCGame
A Simple 2d Game Engine
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
tile.h
1 #ifndef TILE_H
2 #define TILE_H
3 
4 #include <string>
5 #include "external/json/json.h"
6 #include "rect.h"
7 
8 //TODO: This should be configurable
9 const int TILE_WIDTH = 32;
10 const int TILE_HEIGHT = 32;
11 
13 
16 class Tile{
17 public:
18  Tile(){}
19  /*
20  * Setup the tile with a box, solid property and type
21  * @param box The tile's box
22  * @param solid The tile's solid property
23  * @param type The tile's type, corresponds to its clip number for drawing
24  * @param name The tile's name
25  */
26  Tile(Recti box, bool solid, const std::string name){
27  mBox = box;
28  mSolid = solid;
29  mName = name;
30  }
31  Tile(Json::Value val){
32  Load(val);
33  }
35  Recti Box() const{
36  return mBox;
37  }
39  bool Solid() const{
40  return mSolid;
41  }
43  std::string Name() const{
44  return mName;
45  }
47  std::string Filename() const{
48  return mFilename;
49  }
51  void SetBox(Recti box){
52  mBox = box;
53  }
55  void SetSolid(bool solid){
56  mSolid = solid;
57  }
59  void SetName(const std::string name){
60  mName = name;
61  }
63  void SetFilename(const std::string &file){
64  mFilename = file;
65  }
71  Json::Value val;
72  val["box"] = mBox.Save();
73  val["solid"] = mSolid;
74  val["name"] = mName;
75 
76  return val;
77  }
82  void Load(Json::Value val){
83  mBox.Load(val["box"]);
84  mSolid = val["solid"].asBool();
85  mName = val["name"].asString();
86  }
87 
88 private:
89  Recti mBox;
90  bool mSolid;
91  std::string mName;
92  std::string mFilename;
93 };
94 
95 #endif