Temp commit. Textures not working anymor :(

This commit is contained in:
Bram Verhulst
2024-03-27 11:40:44 +01:00
parent 61d1d17795
commit d441222173
43 changed files with 119 additions and 93 deletions

View File

@@ -3,16 +3,76 @@
#include "Texture.h"
#include "TextureManager.h"
enum class GroundTileTypes
{
Air,
Dirt,
Stone,
Iron
};
class GroundTileType {
public:
GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {}
virtual ~GroundTileType() = default;
bool operator== ( const GroundTileType& rhs ) const {
return m_type == rhs.m_type;
}
bool operator!= ( const GroundTileType& rhs) const {
return m_type != rhs.m_type;
}
bool operator== (const GroundTileType* rhs) const {
return rhs->m_type == m_type;
}
bool operator!= (const GroundTileType* rhs) const {
return rhs->m_type != m_type;
}
virtual std::string getPath() {
return m_filePath;
}
protected:
std::string m_filePath;
private:
GroundTileTypes m_type;
};
class RandomGroundTile: public GroundTileType {
public:
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_variant(utils::randRange(1, maxRandom)) {
}
~RandomGroundTile() override = default;
std::string getPath() override {
std::string toReplace{ "[0]" };
std::string replacement = std::to_string(m_variant);
size_t found = m_filePath.find(toReplace);
std::string newFilePath{ m_filePath };
if(found != std::string::npos) {
newFilePath.replace(found, 3, replacement);
}
return newFilePath;
}
private:
int m_variant;
};
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);
}
class WorldTile {
public:
WorldTile();
WorldTile(const Point2f& position, GroundTileTypes groundTileType, TextureManager* pTextureManager);
WorldTile() = default;
WorldTile(const Point2f& position, GroundTileType groundTileType, TextureManager* pTextureManager);
~WorldTile();
void Draw() const;
@@ -22,8 +82,8 @@ public:
Point2f GetSize() const { return Point2f{ 50, 50 }; }
GroundTileTypes GetTileType() const { return m_GroundTileType; }
void SetTileType(GroundTileTypes type) { m_GroundTileType = type; }
GroundTileType GetTileType() const { return m_GroundTileType; }
void SetTileType(GroundTileType type) { m_GroundTileType = type; }
Collision::TileCollisionRect GetCollisionRect();
@@ -32,7 +92,7 @@ public:
private:
Point2f m_Position;
GroundTileTypes m_GroundTileType;
GroundTileType m_GroundTileType;
Texture* m_pTexture;