Walls And Holes  1
tile.h
Go to the documentation of this file.
1 #ifndef TILE_H
2 #define TILE_H
3 
4 #include "tiletemplate.h"
5 #include "tilematerial.h"
6 
7 #include <QObject>
8 #include <QVector2D>
9 
13 class Tile : public QObject
14 {
15  Q_OBJECT
16 
17 public:
18  explicit Tile(TileTemplate *tileTemplate = nullptr,
19  int xPos = -1,
20  int yPos = -1,
21  QObject *parent = nullptr);
22 
23  bool hasTileTemplate() const { return mTileTemplate != nullptr; }
24  TileTemplate *tileTemplate() const { return mTileTemplate; }
25 
26  float thickness() const;
27  float height() const;
28  QVector2D position() const;
29 
30  float relativeThickness() const { return mRelativeThickness; }
31  float relativeHeight() const { return mRelativeHeight; }
32  QVector2D relativePosition() const { return mRelativePosition; }
33 
34  const TileMaterial *topMaterial() const;
35  const TileMaterial *sideMaterial() const;
36 
52  //will be clipped so that walls don't leave tilebounds
53  QVector2D setRelativePosition(QVector2D relativePosition);
54 
59  void resetTile(TileTemplate *newTileTemplate);
60 
61 signals:
62  void tileChanged(int x, int y);
63  void tilePinged(int x, int y);
64 
65 public slots:
66  //by calling the respective set functions, it is ensured that the tile wont go out of bounds.
67  //the signal tileChanged is also emited as expected
68  void templateThicknessChanged() { setRelativeThickness(mRelativeThickness); }
69  void templatePositionChanged() { setRelativePosition(mRelativePosition); }
70 
71 private:
72  void makeTemplateConnections();
73 
74  TileTemplate *mTileTemplate;
75 
76  const int mXPos;
77  const int mYPos;
78 
79  //The thickness of the tile relative to the base tile types thickness:
80  //If tileId 1 has base thickness 0.5, and mTileId = 1 and mRelativeSize = 0.2,
81  //then this tile will have thickness 0.7. The total should not exceed 1 or be
82  //equal to or less than 0
83  float mRelativeThickness;
84 
85  //The height of the tile relative to the base tile types thickness:
86  //As with above, this is added to the base tileHeights height
87  float mRelativeHeight;
88 
89  //let w = (1 - mSize) / 2;
90  //then both x and y are between -w and w (inclusive)
91  //This is the offset of the tile relative to the center of it's grid position
92  //(0.5,0.5 would be the centered regardless of the tiles coordinates)
93  QVector2D mRelativePosition;
94 
95  //other properties to come as we develop further
96 };
97 
98 #endif // TILE_H
void tilePinged(int x, int y)
void setRelativeHeight(float relativeHeight)
Definition: tile.cpp:104
TileTemplate * tileTemplate() const
Definition: tile.h:24
float thickness() const
Definition: tile.cpp:20
void tileChanged(int x, int y)
float relativeThickness() const
Definition: tile.h:30
void templateThicknessChanged()
Definition: tile.h:68
Class to represent each tile on the tileMap.
Definition: tile.h:13
const TileMaterial * topMaterial() const
Definition: tile.cpp:44
QVector2D setRelativePosition(QVector2D relativePosition)
Definition: tile.cpp:114
QVector2D position() const
Definition: tile.cpp:36
Tile(TileTemplate *tileTemplate=nullptr, int xPos=-1, int yPos=-1, QObject *parent=nullptr)
Definition: tile.cpp:5
QVector2D relativePosition() const
Definition: tile.h:32
const TileMaterial * sideMaterial() const
Definition: tile.cpp:52
float height() const
Definition: tile.cpp:28
void templatePositionChanged()
Definition: tile.h:69
bool hasTileTemplate() const
Definition: tile.h:23
Definition: tiletemplate.h:13
void resetTile(TileTemplate *newTileTemplate)
Definition: tile.cpp:142
Definition: tilematerial.h:8
float relativeHeight() const
Definition: tile.h:31
float setRelativeThickness(float relativeThickness)
setRelativeThickness
Definition: tile.cpp:64