mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 20:41:47 +01:00
Fix precompiled headers
Added edge detection (if it works :/)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "WorldTile.h"
|
||||
#include "pch.h"
|
||||
#include "WorldTile.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Camera.h"
|
||||
#include "colors.h"
|
||||
#include "../TextureManager.h"
|
||||
#include "utils.h"
|
||||
@@ -21,56 +23,78 @@ WorldTile::WorldTile(const Point2f& position, GroundTileType* groundTileType, Te
|
||||
WorldTile::~WorldTile() {
|
||||
delete m_pTexture;
|
||||
}
|
||||
void WorldTile::Draw() const {
|
||||
void WorldTile::Draw() {
|
||||
if (*m_GroundTileType != Tiles::AIR) {
|
||||
m_pTexture->Draw(m_Position);
|
||||
if (m_Hightlight) {
|
||||
utils::SetColor(Colors::GREEN);
|
||||
utils::FillRect(m_Position, 50, 50);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
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(), Point2f{50,50}});
|
||||
continue;
|
||||
}
|
||||
if(type != Tiles::AIR->getType()) {
|
||||
utils::SetColor(Colors::YELLOW);
|
||||
utils::FillRect(Rectf{tile->GetPosition(), Point2f{50,50}});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//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} });
|
||||
// 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(), Point2f{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) {
|
||||
Point2f CurrentIndex = m_pGridManager->GetIndexFromPosition(m_Position);
|
||||
m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
|
||||
Point2f mousePos = camera->TransformMouse(Point2f{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;
|
||||
}
|
||||
}
|
||||
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
|
||||
return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
|
||||
|
||||
Reference in New Issue
Block a user