mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 20:41:47 +01:00
Added inheritance for the screen system
basic edge detection for tile rendering
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
#include "WorldTile.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "colors.h"
|
||||
#include "../TextureManager.h"
|
||||
#include "utils.h"
|
||||
#include "WorldGridManager.h"
|
||||
|
||||
|
||||
WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager) : m_Position { position }, m_GroundTileType { groundTileType } {
|
||||
WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, 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_pBottomLeftTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomRight.png");
|
||||
m_pBottomRightTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/bottomLeft.png");
|
||||
m_pTopLeftTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/topRight.png");
|
||||
m_pTopRightTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/topLeft.png");
|
||||
}
|
||||
WorldTile::~WorldTile() {
|
||||
delete m_pTexture;
|
||||
@@ -20,7 +28,49 @@ void WorldTile::Draw() const {
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::FillRect(m_Position, 50, 50);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//Tile is air, So check 8 tiles around
|
||||
// Check the 4 tiles diagonally
|
||||
Point2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
|
||||
WorldTile* pTopLeft = m_pGridManager->GetTileAtIndex(CurrentIndex.x - 1, CurrentIndex.y - 1);
|
||||
WorldTile* pTopRight = m_pGridManager->GetTileAtIndex(CurrentIndex.x + 1, CurrentIndex.y - 1);
|
||||
WorldTile* pBottomLeft = m_pGridManager->GetTileAtIndex(CurrentIndex.x - 1, CurrentIndex.y + 1);
|
||||
WorldTile* pBottomRight = m_pGridManager->GetTileAtIndex(CurrentIndex.x + 1, CurrentIndex.y + 1);
|
||||
|
||||
|
||||
GroundTileType* pTopLeftType = pTopLeft != nullptr ? pTopLeft->GetTileType() : Tiles::AIR;
|
||||
GroundTileType* pTopRightType = pTopRight != nullptr ? pTopRight->GetTileType() : Tiles::AIR;
|
||||
GroundTileType* pBottomLeftType = pBottomLeft != nullptr ? pBottomLeft->GetTileType() : Tiles::AIR;
|
||||
GroundTileType* pBottomRightType = pBottomRight != nullptr ? pBottomRight->GetTileType() : Tiles::AIR;
|
||||
|
||||
if(pBottomLeftType == Tiles::AIR && pBottomRightType == Tiles::AIR && pTopLeftType == Tiles::AIR && pTopRightType == Tiles::AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(pTopLeftType != Tiles::AIR) {
|
||||
m_pTopLeftTexture->Draw(m_Position);
|
||||
}
|
||||
if(pTopRightType != Tiles::AIR) {
|
||||
m_pTopRightTexture->Draw(m_Position);
|
||||
}
|
||||
if(pBottomLeftType != Tiles::AIR) {
|
||||
m_pBottomLeftTexture->Draw(m_Position);
|
||||
}
|
||||
if(pBottomRightType != Tiles::AIR) {
|
||||
m_pBottomRightTexture->Draw(m_Position);
|
||||
}
|
||||
|
||||
// if(m_Hightlight) {
|
||||
// //Draw a rect over the diagonal tiles
|
||||
// utils::SetColor(Colors::GREEN);
|
||||
// utils::FillRect(m_Position, 50, 50);
|
||||
// utils::FillRect(Rectf{ pTopLeft->GetPosition(), Point2f{ 50, 50} });
|
||||
// utils::FillRect(Rectf{ pTopRight->GetPosition(), Point2f{ 50, 50} });
|
||||
// utils::FillRect(Rectf{ pBottomLeft->GetPosition(), Point2f{ 50, 50} });
|
||||
// utils::FillRect(Rectf{ pBottomRight->GetPosition(), Point2f{ 50, 50} });
|
||||
// }
|
||||
}
|
||||
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
||||
return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
|
||||
|
||||
Reference in New Issue
Block a user