mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2026-02-04 09:29:20 +01:00
30 lines
838 B
C++
30 lines
838 B
C++
#include "WorldGridManager.h"
|
|
WorldGridManager::WorldGridManager() {
|
|
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
|
|
for(size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
|
|
m_worldTiles[x][y] = nullptr;
|
|
}
|
|
}
|
|
|
|
}
|
|
WorldGridManager::~WorldGridManager() {
|
|
|
|
}
|
|
WorldTile* WorldGridManager::GetTileAtIndex(const int x, const int y) const {
|
|
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
|
return nullptr;
|
|
}
|
|
return m_worldTiles[x][y];
|
|
}
|
|
WorldTile* WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
|
|
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
|
|
int y = int(-pos.y / TILE_HEIGHT);
|
|
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
|
|
return nullptr;
|
|
}
|
|
return m_worldTiles[x][y];
|
|
}
|
|
void WorldGridManager::SetTileAtIndex(const int x, const int y, WorldTile* tile) {
|
|
m_worldTiles[x][y] = tile;
|
|
}
|