Rework Tile detection system

This commit is contained in:
Bram Verhulst
2024-03-28 18:53:36 +01:00
parent d441222173
commit 3b9c96ea8d
15 changed files with 252 additions and 41 deletions

View File

@@ -23,8 +23,23 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
int actualX = x - WORLD_WIDTH / 2;
Point2f pos = Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT};
GroundTileType type = rand() % 2 == 0 ? Tiles::DIRT : Tiles::DIRT;
m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, Tiles::DIRT, TextureManager::GetInstance() });
GroundTileType* type = Tiles::AIR;
switch(utils::randRange(0,2)) {
case 0:
type = Tiles::DIRT;
break;
case 1:
type = Tiles::IRON;
break;
case 2:
//AIR
break;
default:
std::cout << "??" << std::endl;
}
m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, type, TextureManager::GetInstance() });
}
}
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
@@ -92,7 +107,7 @@ void WorldLevel::Draw() const {
//loop over worldtiles
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
if(m_gridManager.GetTileAtIndex(x,y)->GetTileType() == Tiles::DIRT) {
if(*m_gridManager.GetTileAtIndex(x,y)->GetTileType() != Tiles::AIR) {
Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().getCollisionRect();
utils::SetColor(Colors::GREEN);
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);