mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 14:41:49 +01:00
Fix precompiled headers
Added edge detection (if it works :/)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "WorldGridManager.h"
|
||||
#include "pch.h"
|
||||
#include "WorldGridManager.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -15,31 +16,27 @@ WorldGridManager::WorldGridManager() {
|
||||
WorldGridManager::~WorldGridManager() {
|
||||
|
||||
}
|
||||
std::vector<WorldTile*> WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
std::vector<WorldTile*> tiles;
|
||||
surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
surroundingTiles tiles;
|
||||
Point2f pos = world_tile->GetPosition();
|
||||
Point2f gridCoords = this->GetIndexFromPosition(pos);
|
||||
int x = gridCoords.x;
|
||||
//TODO: Stupid fix, fix this
|
||||
int y = gridCoords.y - 1;
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
return tiles;
|
||||
}
|
||||
for (int i { -1 }; i <= 1; ++i) {
|
||||
for (int j { -1 }; j <= 1; ++j) {
|
||||
if (i == 0 && j == 0) {
|
||||
continue;
|
||||
}
|
||||
if(x + i < 0 || x + i >= WORLD_WIDTH || y + j < 0 || y + j >= WORLD_HEIGHT) {
|
||||
continue;
|
||||
}
|
||||
WorldTile* tile = GetTileAtIndex(x + i, y + j);
|
||||
if (tile != nullptr) {
|
||||
tiles.push_back(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tiles.SetTile(TileDirection::TopLeft, this->GetTileAtIndex(x - 1, y - 1));
|
||||
tiles.SetTile(TileDirection::TopMiddle, this->GetTileAtIndex(x, y - 1));
|
||||
tiles.SetTile(TileDirection::TopRight, this->GetTileAtIndex(x + 1, y - 1));
|
||||
|
||||
tiles.SetTile(TileDirection::MiddleLeft, this->GetTileAtIndex(x - 1, y));
|
||||
tiles.SetTile(TileDirection::MiddleRight, this->GetTileAtIndex(x + 1, y));
|
||||
|
||||
tiles.SetTile(TileDirection::BottomLeft, this->GetTileAtIndex(x - 1, y + 1));
|
||||
tiles.SetTile(TileDirection::BottomMiddle, this->GetTileAtIndex(x, y + 1));
|
||||
tiles.SetTile(TileDirection::BottomRight, this->GetTileAtIndex(x + 1, y + 1));
|
||||
|
||||
return tiles;
|
||||
|
||||
}
|
||||
Point2f WorldGridManager::GetIndexFromPosition(Point2f position) {
|
||||
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
|
||||
Reference in New Issue
Block a user