mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-18 17:59:21 +01:00
Rework Tile detection system
This commit is contained in:
@@ -24,16 +24,20 @@ public:
|
||||
return m_type != rhs.m_type;
|
||||
}
|
||||
|
||||
bool operator== (const GroundTileType* rhs) const {
|
||||
virtual bool operator== (const GroundTileType* rhs) const {
|
||||
return rhs->m_type == m_type;
|
||||
}
|
||||
bool operator!= (const GroundTileType* rhs) const {
|
||||
virtual bool operator!= (const GroundTileType* rhs) const {
|
||||
return rhs->m_type != m_type;
|
||||
}
|
||||
|
||||
virtual std::string getPath() {
|
||||
virtual std::string getPath() const {
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
virtual GroundTileTypes getType() const {
|
||||
return m_type;
|
||||
}
|
||||
protected:
|
||||
std::string m_filePath;
|
||||
private:
|
||||
@@ -42,37 +46,48 @@ private:
|
||||
|
||||
class RandomGroundTile: public GroundTileType {
|
||||
public:
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_variant(utils::randRange(1, maxRandom)) {
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
|
||||
}
|
||||
|
||||
~RandomGroundTile() override = default;
|
||||
|
||||
std::string getPath() override {
|
||||
bool operator== (const GroundTileType* rhs) const override{
|
||||
return rhs->getType() == this->getType();
|
||||
}
|
||||
|
||||
bool operator!= (const GroundTileType* rhs) const override{
|
||||
return rhs->getType() != this->getType();
|
||||
}
|
||||
|
||||
std::string getPath() const override {
|
||||
int variant = utils::randRange(1, m_maxRandom);
|
||||
std::string toReplace{ "[0]" };
|
||||
std::string replacement = std::to_string(m_variant);
|
||||
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
|
||||
|
||||
size_t found = m_filePath.find(toReplace);
|
||||
std::string newFilePath{ m_filePath };
|
||||
std::string newFilePath{ m_filePath };
|
||||
|
||||
if(found != std::string::npos) {
|
||||
newFilePath.replace(found, 3, replacement);
|
||||
}
|
||||
|
||||
return newFilePath;
|
||||
}
|
||||
private:
|
||||
int m_variant;
|
||||
int m_maxRandom;
|
||||
};
|
||||
|
||||
namespace Tiles
|
||||
{
|
||||
static GroundTileType AIR = GroundTileType("", GroundTileTypes::Air);
|
||||
static GroundTileType DIRT = RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 6);
|
||||
static GroundTileType IRON = GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
|
||||
static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air);
|
||||
static GroundTileType* DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
|
||||
static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
|
||||
}
|
||||
|
||||
class WorldTile {
|
||||
public:
|
||||
WorldTile() = default;
|
||||
WorldTile(const Point2f& position, GroundTileType groundTileType, TextureManager* pTextureManager);
|
||||
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager);
|
||||
~WorldTile();
|
||||
|
||||
void Draw() const;
|
||||
@@ -82,8 +97,8 @@ public:
|
||||
|
||||
Point2f GetSize() const { return Point2f{ 50, 50 }; }
|
||||
|
||||
GroundTileType GetTileType() const { return m_GroundTileType; }
|
||||
void SetTileType(GroundTileType type) { m_GroundTileType = type; }
|
||||
GroundTileType* GetTileType() const { return m_GroundTileType; }
|
||||
void SetTileType(GroundTileType* type) { m_GroundTileType = type; }
|
||||
|
||||
Collision::TileCollisionRect GetCollisionRect();
|
||||
|
||||
@@ -92,7 +107,7 @@ public:
|
||||
|
||||
private:
|
||||
Point2f m_Position;
|
||||
GroundTileType m_GroundTileType;
|
||||
GroundTileType* m_GroundTileType;
|
||||
|
||||
Texture* m_pTexture;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user