mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-17 01:11:47 +01:00
Fix digging
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "structs.h"
|
||||
|
||||
class GroundTileType;
|
||||
static const int WORLD_WIDTH = 34;
|
||||
static const int WORLD_HEIGHT = 34;
|
||||
|
||||
@@ -40,6 +41,18 @@ struct surroundingTiles
|
||||
WorldTile* GetTile(TileDirection direction) {
|
||||
return m_tiles[direction];
|
||||
}
|
||||
|
||||
// bool IsAllType(const GroundTileType& type) {
|
||||
// for (const auto& tile : m_tiles) {
|
||||
// if (tile.second == nullptr) {
|
||||
// return false;
|
||||
// }
|
||||
// if (tile.second->GetTileType() != &type) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
};
|
||||
|
||||
class WorldGridManager
|
||||
|
||||
@@ -32,6 +32,51 @@ WorldTile::~WorldTile() {
|
||||
delete m_pTexture;
|
||||
}
|
||||
void WorldTile::Draw() {
|
||||
|
||||
|
||||
switch (m_GroundTileType->getType()) {
|
||||
case GroundTileTypes::Air: {
|
||||
//check if it's all around dirt
|
||||
bool allDirt = true;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
if(tile != nullptr) { //Tile exists
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::DIRT->getType()) {
|
||||
allDirt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allDirt) {
|
||||
m_pAllTexture->Draw(m_Position);
|
||||
return;
|
||||
}
|
||||
if(*m_GroundTileType == Tiles::AIR) {
|
||||
this->DrawSide(TileDirection::TopLeft);
|
||||
this->DrawSide(TileDirection::TopRight);
|
||||
this->DrawSide(TileDirection::BottomLeft);
|
||||
this->DrawSide(TileDirection::BottomRight);
|
||||
|
||||
this->DrawSide(TileDirection::TopMiddle);
|
||||
this->DrawSide(TileDirection::BottomMiddle);
|
||||
this->DrawSide(TileDirection::MiddleLeft);
|
||||
this->DrawSide(TileDirection::MiddleRight);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
case GroundTileTypes::Dirt:
|
||||
case GroundTileTypes::Hard:
|
||||
case GroundTileTypes::Stone:
|
||||
case GroundTileTypes::Iron:
|
||||
m_pTexture->Draw(m_Position);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (*m_GroundTileType != Tiles::AIR) {
|
||||
m_pTexture->Draw(m_Position);
|
||||
if (m_Hightlight) {
|
||||
@@ -40,35 +85,9 @@ void WorldTile::Draw() {
|
||||
}
|
||||
}
|
||||
|
||||
//check if it's all around dirt
|
||||
bool allDirt = true;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
if(tile != nullptr) { //Tile exists
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::DIRT->getType()) {
|
||||
allDirt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(allDirt) {
|
||||
m_pAllTexture->Draw(m_Position);
|
||||
return;
|
||||
}
|
||||
|
||||
if(*m_GroundTileType == Tiles::AIR) {
|
||||
this->DrawSide(TileDirection::TopLeft);
|
||||
this->DrawSide(TileDirection::TopRight);
|
||||
this->DrawSide(TileDirection::BottomLeft);
|
||||
this->DrawSide(TileDirection::BottomRight);
|
||||
|
||||
this->DrawSide(TileDirection::TopMiddle);
|
||||
this->DrawSide(TileDirection::BottomMiddle);
|
||||
this->DrawSide(TileDirection::MiddleLeft);
|
||||
this->DrawSide(TileDirection::MiddleRight);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WorldTile::Update(const Camera* camera) {
|
||||
|
||||
@@ -18,7 +18,7 @@ enum class GroundTileTypes
|
||||
class GroundTileType
|
||||
{
|
||||
public:
|
||||
GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
|
||||
GroundTileType(const std::string&& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
|
||||
}
|
||||
virtual ~GroundTileType() = default;
|
||||
bool operator==(const GroundTileType& rhs) const {
|
||||
@@ -53,7 +53,7 @@ private:
|
||||
class RandomGroundTile : public GroundTileType
|
||||
{
|
||||
public:
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
|
||||
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(std::move(filePath), type), m_maxRandom(maxRandom) {
|
||||
}
|
||||
|
||||
~RandomGroundTile() override = default;
|
||||
@@ -96,6 +96,8 @@ namespace Tiles
|
||||
static GroundTileType* HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
|
||||
static GroundTileType* HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
|
||||
static GroundTileType* HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
|
||||
|
||||
static GroundTileType* GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Dirt, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +127,7 @@ public:
|
||||
}
|
||||
void SetTileType(GroundTileType* type) {
|
||||
m_GroundTileType = type;
|
||||
m_pTexture = TextureManager::GetInstance()->GetTexture(type->getPath()); //Chage the texture when setting a new type
|
||||
}
|
||||
|
||||
Collision::TileCollisionRect GetCollisionRect();
|
||||
@@ -133,7 +136,6 @@ public:
|
||||
|
||||
private:
|
||||
void DrawSide(const TileDirection& direction);
|
||||
|
||||
|
||||
Vector2f m_Position;
|
||||
GroundTileType* m_GroundTileType;
|
||||
|
||||
Reference in New Issue
Block a user