Added water vs sand interaction.

This commit is contained in:
2024-12-31 10:05:56 -06:00
parent 14960eec4f
commit 24fa29408a
6 changed files with 47 additions and 5 deletions

View File

@@ -237,7 +237,9 @@ namespace CaveGame::Client {
Vector2 relative_tile_coords = Vector2(x, y);
Vector2 tile_coords = relative_tile_coords;
if (t_id == TileID::AIR) // Air
if (t_id == TileID::AIR || t_id == TileID::VOID) // Air
continue;
t_data = Core::GetByNumeric(t_id);

View File

@@ -24,8 +24,7 @@ namespace CaveGame::Core
static constexpr int ChunkSize = 256;
public:
/// The default constructor does not initialize any members.
Chunk() {}
Chunk() = default;
~Chunk()
{
@@ -35,6 +34,7 @@ namespace CaveGame::Core
/// @param cell_coords Specifies the chunk-cell this chunk will occupy.
explicit Chunk(const Vector2 &cell_coords);
explicit Chunk(const Vector2 &cell_coords, const std::filesystem::path &file) : Chunk(cell_coords)
{
std::ifstream inp;

View File

@@ -148,7 +148,7 @@ namespace CaveGame::Core
LED,
TORCH_BASE,
TORCH_EMBER,
TORCH_EMBER = 256,
VOID = 65535,
};

View File

@@ -173,6 +173,12 @@ namespace CaveGame::Core
return;
}
if (world->GetTile(x-1, y) == TileID::AIR && world->GetTile(x+1, y) == TileID::AIR) {
//world->SetTile(x-1, y, numeric_id);
world->SetTile(x, y, TileID::AIR);
return;
}
if (world->GetTile(x-1, y) == TileID::AIR) {
world->SetTile(x-1, y, numeric_id);
world->SetTile(x, y, TileID::AIR);
@@ -250,7 +256,7 @@ namespace CaveGame::Core
return;
}
if (world->GetTile(x+1, y+2) == TileID::AIR) {
if (world->GetTile(x+1, y+2) == TileID::AIR) {AIR
world->SetTile(x+1, y+2, numeric_id);
world->SetTile(x, y, TileID::AIR);
return;
@@ -261,6 +267,25 @@ namespace CaveGame::Core
world->SetTile(x, y, TileID::AIR);
return;
}
if (world->GetTile(x, y+1) == TileID::WATER) {
world->SetTile(x, y+1, numeric_id);
world->SetTile(x, y, TileID::WATER);
return;
}
if (world->GetTile(x+1, y+1) == TileID::WATER) {
world->SetTile(x+1, y+1, numeric_id);
world->SetTile(x, y, TileID::WATER);
return;
}
if (world->GetTile(x-1, y+1) == TileID::WATER) {
world->SetTile(x-1, y+1, numeric_id);
world->SetTile(x, y, TileID::WATER);
return;
}
}
};

View File

@@ -16,7 +16,14 @@ namespace CaveGame::Core
touched = true;
if (trigger_tile_updates)
{
SetTileUpdateFlag(x, y);
//SetTileUpdateFlag(x-1, y);
//SetTileUpdateFlag(x+1, y);
//SetTileUpdateFlag(x, y-1);
//SetTileUpdateFlag(x, y+1);
}
}
}

View File

@@ -73,8 +73,16 @@ namespace CaveGame::Core
const Vector2 coords = Vector2(chunkX, chunkY);
if (HasChunkAtCell(coords))
{
loaded_chunks.at(coords).SetTile(tileX, tileY, t);
SetTileUpdateFlag(x, y-1, true);
SetTileUpdateFlag(x, y+1, true);
SetTileUpdateFlag(x-1, y, true);
SetTileUpdateFlag(x+1, y, true);
}
}
Chunk World::GetChunkAtCell(const Vector2 &cell) {