Add more digging logic

This commit is contained in:
Bram Verhulst
2024-03-20 17:10:36 +01:00
parent a165c0bc6f
commit ad847355b5
9 changed files with 134 additions and 46 deletions

29
Game/WorldGridManager.cpp Normal file
View File

@@ -0,0 +1,29 @@
#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;
}