Add fly animations

This commit is contained in:
Bram Verhulst
2024-05-29 00:00:29 +02:00
parent 3c83e566dd
commit e1165fdcb4
31 changed files with 580 additions and 157 deletions

View File

@@ -36,20 +36,20 @@ GroundTileType * getRandomGroundTile() {
}
void InitializeGroundTiles() {
Tiles tiles {};
GroundTileTypeManager::GetInstance()->AIR = new GroundTileType("", GroundTileTypes::Air);
GroundTileTypeManager::GetInstance()->DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
GroundTileTypeManager::GetInstance()->AIR = new GroundTileType("", GroundTileTypes::Air, 0);
GroundTileTypeManager::GetInstance()->DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5, 250);
GroundTileTypeManager::GetInstance()->STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3);
GroundTileTypeManager::GetInstance()->LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3);
GroundTileTypeManager::GetInstance()->STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3, 0);
GroundTileTypeManager::GetInstance()->LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3, 0);
GroundTileTypeManager::GetInstance()->IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
GroundTileTypeManager::GetInstance()->BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze);
GroundTileTypeManager::GetInstance()->GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold);
GroundTileTypeManager::GetInstance()->IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron, 1500);
GroundTileTypeManager::GetInstance()->BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze, 3000);
GroundTileTypeManager::GetInstance()->GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold, 12500);
GroundTileTypeManager::GetInstance()->GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2);
GroundTileTypeManager::GetInstance()->HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
GroundTileTypeManager::GetInstance()->GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2, 250);
GroundTileTypeManager::GetInstance()->HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard, 0);
GroundTileTypeManager::GetInstance()->HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard, 0);
GroundTileTypeManager::GetInstance()->HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard, 0);
GroundTileWeights = {
{ GroundTileTypeManager::GetInstance()->AIR, 0.2f },
@@ -70,7 +70,7 @@ WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, T
m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
// m_pTexture = new Texture(dirtPath);
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
m_pTexture = pTextureManager->GetTexture(groundTileType->GetPath());
m_SideTextures[TileDirection::TopLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topLeft.png");
m_SideTextures[TileDirection::TopRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topRight.png");
@@ -90,7 +90,7 @@ WorldTile::~WorldTile() {
void WorldTile::Draw() {
switch (m_GroundTileType->getType()) {
switch (m_GroundTileType->GetType()) {
case GroundTileTypes::Air: {
//check if it's all around dirt
// bool allDirt = true;
@@ -157,17 +157,17 @@ Collision::TileCollisionRect WorldTile::GetCollisionRect() {
void WorldTile::DrawSide(const TileDirection& direction) {
const WorldTile* tile = m_SurroundingTiles.GetTile(direction);
if (tile != nullptr) {
const GroundTileTypes type = tile->GetTileType()->getType();
const GroundTileTypes type = tile->GetTileType()->GetType();
if (direction == TileDirection::BottomMiddle || direction == TileDirection::BottomLeft || direction == TileDirection::BottomRight) {
if (type == GroundTileTypeManager::GetInstance()->GRASS->getType() || type == GroundTileTypeManager::GetInstance()->HARD_LEFT->getType() || type ==
GroundTileTypeManager::GetInstance()->HARD_MIDDLE->getType() || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT->getType()) {
if (type == GroundTileTypeManager::GetInstance()->GRASS->GetType() || type == GroundTileTypeManager::GetInstance()->HARD_LEFT->GetType() || type ==
GroundTileTypeManager::GetInstance()->HARD_MIDDLE->GetType() || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT->GetType()) {
//Fix for edges being renderd on grass / hard tiles
//TODO: Possible fix if i have time
return;
}
}
if (type != GroundTileTypeManager::GetInstance()->AIR->getType()) {
if (type != GroundTileTypeManager::GetInstance()->AIR->GetType()) {
m_SideTextures[direction]->Draw(m_Position);
}
}

View File

@@ -6,8 +6,7 @@
class Camera;
enum class GroundTileTypes
{
enum class GroundTileTypes {
Air,
Dirt,
Grass,
@@ -38,64 +37,67 @@ static std::map<GroundTileTypes, std::string> GroundTileTypeStrings {
GroundTileType * getRandomGroundTile();
class GroundTileType
{
class GroundTileType {
public:
GroundTileType(const std::string&& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
GroundTileType(const std::string&& filePath, GroundTileTypes type, int value): m_FilePath(filePath), m_Type(type), m_Value(value) {
}
virtual ~GroundTileType() = default;
bool operator==(const GroundTileType& rhs) const {
return m_type == rhs.m_type;
return m_Type == rhs.m_Type;
}
bool operator!=(const GroundTileType& rhs) const {
return m_type != rhs.m_type;
return m_Type != rhs.m_Type;
}
virtual bool operator==(const GroundTileType* rhs) const {
return rhs->m_type == m_type;
return rhs->m_Type == m_Type;
}
virtual bool operator!=(const GroundTileType* rhs) const {
return rhs->m_type != m_type;
return rhs->m_Type != m_Type;
}
virtual std::string getPath() const {
return m_filePath;
virtual std::string GetPath() const {
return m_FilePath;
}
virtual GroundTileTypes getType() const {
return m_type;
virtual GroundTileTypes GetType() const {
return m_Type;
}
virtual int GetValue() const {
return m_Value;
}
protected:
std::string m_filePath;
std::string m_FilePath;
private:
GroundTileTypes m_type;
GroundTileTypes m_Type;
int m_Value;
};
class RandomGroundTile : public GroundTileType
{
class RandomGroundTile : public GroundTileType {
public:
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(std::move(filePath), type), m_maxRandom(maxRandom) {
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom, int value): GroundTileType(std::move(filePath), type, value), m_maxRandom(maxRandom) {
}
~RandomGroundTile() override = default;
bool operator==(const GroundTileType* rhs) const override {
return rhs->getType() == this->getType();
return rhs->GetType() == this->GetType();
}
bool operator!=(const GroundTileType* rhs) const override {
return rhs->getType() != this->getType();
return rhs->GetType() != this->GetType();
}
std::string getPath() const override {
std::string GetPath() const override {
int variant = utils::randRange(1, m_maxRandom);
std::string toReplace { "[0]" };
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
size_t found = m_filePath.find(toReplace);
std::string newFilePath { m_filePath };
size_t found = m_FilePath.find(toReplace);
std::string newFilePath { m_FilePath };
if (found != std::string::npos) {
newFilePath.replace(found, 3, replacement);
@@ -108,10 +110,9 @@ private:
int m_maxRandom;
};
class Tiles
{
class Tiles {
public:
};
// static std::map<GroundTileType *, float> GroundTileWeights {
@@ -128,12 +129,11 @@ public:
// { Tiles::Ores::IRON, 0.1f },
// };
static std::map<GroundTileType*, float> GroundTileWeights;
static std::map<GroundTileType *, float> GroundTileWeights;
void InitializeGroundTiles();
class WorldTile
{
class WorldTile {
public:
WorldTile() = default;
WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager);
@@ -158,7 +158,7 @@ public:
}
void SetTileType(GroundTileType* type) {
m_GroundTileType = type;
m_pTexture = TextureManager::GetInstance()->GetTexture(type->getPath()); //Chage the texture when setting a new type
m_pTexture = TextureManager::GetInstance()->GetTexture(type->GetPath()); //Chage the texture when setting a new type
}
Collision::TileCollisionRect GetCollisionRect();
@@ -179,7 +179,7 @@ private:
surroundingTiles m_SurroundingTiles;
std::vector<Texture*> m_SideTextures { 8, nullptr };
std::vector<Texture *> m_SideTextures { 8, nullptr };
Texture* m_pAllTexture;
};