mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 20:41:47 +01:00
Add Building, Add Hard floors
This commit is contained in:
@@ -15,15 +15,16 @@ WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, T
|
||||
// m_pTexture = new Texture(dirtPath);
|
||||
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
|
||||
|
||||
m_pBottomLeftTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomLeft.png");
|
||||
m_pBottomRightTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomRight.png");
|
||||
m_pTopLeftTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/topLeft.png");
|
||||
m_pTopRightTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/topRight.png");
|
||||
m_SideTextures[TileDirection::TopLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topLeft.png");
|
||||
m_SideTextures[TileDirection::TopRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/topRight.png");
|
||||
m_SideTextures[TileDirection::BottomLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomLeft.png");
|
||||
m_SideTextures[TileDirection::BottomRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomRight.png");
|
||||
|
||||
m_pMiddleBottomTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleBottom.png");
|
||||
m_pMiddleTopTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleTop.png");
|
||||
m_pMiddleLeftTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleLeft.png");
|
||||
m_pMiddleRightTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleRight.png");
|
||||
m_SideTextures[TileDirection::TopMiddle] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleTop.png");
|
||||
m_SideTextures[TileDirection::BottomMiddle] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleBottom.png");
|
||||
m_SideTextures[TileDirection::MiddleLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleLeft.png");
|
||||
m_SideTextures[TileDirection::MiddleRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleRight.png");
|
||||
|
||||
|
||||
m_pAllTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/all.png");
|
||||
}
|
||||
@@ -42,9 +43,9 @@ void WorldTile::Draw() {
|
||||
//check if it's all around dirt
|
||||
bool allDirt = true;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
if(tile != nullptr) { //Tile exists
|
||||
GroundTileTypes type = tile->GetTileType()->getType();
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::DIRT->getType()) {
|
||||
allDirt = false;
|
||||
break;
|
||||
@@ -57,144 +58,35 @@ void WorldTile::Draw() {
|
||||
}
|
||||
|
||||
if(*m_GroundTileType == Tiles::AIR) {
|
||||
WorldTile* topLeft = m_SurroundingTiles.GetTile(TileDirection::TopLeft);
|
||||
if(topLeft != nullptr) {
|
||||
GroundTileTypes type = topLeft->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pTopLeftTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
this->DrawSide(TileDirection::TopLeft);
|
||||
this->DrawSide(TileDirection::TopRight);
|
||||
this->DrawSide(TileDirection::BottomLeft);
|
||||
this->DrawSide(TileDirection::BottomRight);
|
||||
|
||||
WorldTile* topRight = m_SurroundingTiles.GetTile(TileDirection::TopRight);
|
||||
if(topRight != nullptr) {
|
||||
GroundTileTypes type = topRight->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pTopRightTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* bottomLeft = m_SurroundingTiles.GetTile(TileDirection::BottomLeft);
|
||||
if(bottomLeft != nullptr) {
|
||||
GroundTileTypes type = bottomLeft->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pBottomLeftTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* bottomRight = m_SurroundingTiles.GetTile(TileDirection::BottomRight);
|
||||
if(bottomRight != nullptr) {
|
||||
GroundTileTypes type = bottomRight->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pBottomRightTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* middleTop = m_SurroundingTiles.GetTile(TileDirection::TopMiddle);
|
||||
if(middleTop != nullptr) {
|
||||
GroundTileTypes type = middleTop->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pMiddleTopTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* middleBottom = m_SurroundingTiles.GetTile(TileDirection::BottomMiddle);
|
||||
if(middleBottom != nullptr) {
|
||||
GroundTileTypes type = middleBottom->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pMiddleBottomTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* middleLeft = m_SurroundingTiles.GetTile(TileDirection::MiddleLeft);
|
||||
if(middleLeft != nullptr) {
|
||||
GroundTileTypes type = middleLeft->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pMiddleLeftTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* middleRight = m_SurroundingTiles.GetTile(TileDirection::MiddleRight);
|
||||
if(middleRight != nullptr) {
|
||||
GroundTileTypes type = middleRight->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pMiddleRightTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
|
||||
WorldTile* bottomMiddle = m_SurroundingTiles.GetTile(TileDirection::BottomMiddle);
|
||||
if(bottomMiddle != nullptr) {
|
||||
GroundTileTypes type = bottomMiddle->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_pMiddleBottomTexture->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
this->DrawSide(TileDirection::TopMiddle);
|
||||
this->DrawSide(TileDirection::BottomMiddle);
|
||||
this->DrawSide(TileDirection::MiddleLeft);
|
||||
this->DrawSide(TileDirection::MiddleRight);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// if(m_Hightlight) {
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
// if(tile != nullptr) { //Tile exists
|
||||
// //TODO: Wow Big mess
|
||||
// GroundTileTypes type = tile->GetTileType()->getType();
|
||||
// if(type == Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::BLACK);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// continue;
|
||||
// }
|
||||
// if(type != Tiles::AIR->getType()) {
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{tile->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//Tile is air, So check 8 tiles around
|
||||
// Check the 4 tiles diagonally
|
||||
|
||||
// m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
|
||||
//
|
||||
// //check if all tiles are air
|
||||
// bool allAir = true;
|
||||
// for (int i = 0; i < 8; i++) {
|
||||
// WorldTile* tile = m_SurroundingTiles.GetTile(static_cast<TileDirection>(i));
|
||||
// if(tile != nullptr) { //Tile exists
|
||||
// if(tile->GetTileType() != Tiles::AIR) {
|
||||
// allAir = false;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (allAir) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// WorldTile* topLeft = m_SurroundingTiles.GetTile(TileDirection::TopLeft); //TODO: ask if draw needs to be const
|
||||
// GroundTileType* topLeftType = topLeft != nullptr ? topLeft->GetTileType() : Tiles::AIR;
|
||||
// if(topLeftType != Tiles::AIR) {
|
||||
// m_pTopLeftTexture->Draw(m_Position);
|
||||
// utils::SetColor(Colors::YELLOW);
|
||||
// utils::FillRect(Rectf{topLeft->GetPosition(), Vector2f{50,50}});
|
||||
// }
|
||||
//
|
||||
// WorldTile* topRight = m_SurroundingTiles.GetTile(TileDirection::TopRight);
|
||||
// GroundTileType* topRightType = topRight != nullptr ? topRight->GetTileType() : Tiles::AIR;
|
||||
// if(topRightType != Tiles::AIR) {
|
||||
// m_pTopRightTexture->Draw(m_Position);
|
||||
// }
|
||||
//
|
||||
}
|
||||
void WorldTile::Update(Camera* camera) {
|
||||
Vector2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
|
||||
void WorldTile::Update(const Camera* camera) {
|
||||
m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
|
||||
Vector2f mousePos = camera->TransformMouse(Vector2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
m_Hightlight = utils::IsPointInRect(mousePos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
||||
if(CurrentIndex.x == 1 && CurrentIndex.y == 1) {
|
||||
// std::cout << "Hey" << std::endl;
|
||||
}
|
||||
const Vector2f mouse_pos = camera->TransformMouse(Vector2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
|
||||
m_Hightlight = utils::IsPointInRect(mouse_pos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
|
||||
}
|
||||
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
||||
return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
|
||||
}
|
||||
|
||||
void WorldTile::DrawSide(const TileDirection& direction) {
|
||||
const WorldTile* tile = m_SurroundingTiles.GetTile(direction);
|
||||
if(tile != nullptr) {
|
||||
const GroundTileTypes type = tile->GetTileType()->getType();
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
m_SideTextures[direction]->Draw(m_Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user