mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 14:41:49 +01:00
Added inheritance for the screen system
basic edge detection for tile rendering
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
#include "WorldGridManager.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "WorldTile.h"
|
||||
|
||||
WorldGridManager::WorldGridManager() {
|
||||
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -9,10 +14,42 @@ WorldGridManager::WorldGridManager() {
|
||||
}
|
||||
WorldGridManager::~WorldGridManager() {
|
||||
|
||||
}
|
||||
std::vector<WorldTile*> WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
|
||||
std::vector<WorldTile*> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tiles;
|
||||
}
|
||||
Point2f WorldGridManager::GetIndexFromPosition(Point2f position) {
|
||||
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
||||
int y = int(-position.y / TILE_HEIGHT);
|
||||
return Point2f{ float(x), float(y) };
|
||||
}
|
||||
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
||||
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
||||
return nullptr;
|
||||
//TODO: see if this can be Math'ed out
|
||||
}
|
||||
return m_worldTiles[x][y];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user