mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
feat: add dirt and stone
This commit is contained in:
@@ -216,7 +216,7 @@ void Chunk::init_chunk() {
|
||||
for (int x = 0; x < CHUCK_SIZE; x++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for (int z = 0; z < CHUCK_SIZE; z++) {
|
||||
m_blocks[get_index(x, y, z)] = 1;
|
||||
m_blocks[get_index(x, y, z)] = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,10 +233,15 @@ void Chunk::init_chunk() {
|
||||
0.125f * PerlinNoise::noise(world_x * 0.04f, world_z * 0.04f, 0.5f);
|
||||
int y_max = height * noise;
|
||||
|
||||
for (int y = 5; y < y_max; y++) {
|
||||
for (int y = 5; y < y_max - 5; y++) {
|
||||
m_blocks[get_index(x, y, z)] = 3;
|
||||
}
|
||||
for (int y = y_max - 5; y < y_max - 1; y++) {
|
||||
m_blocks[get_index(x, y, z)] = 2;
|
||||
}
|
||||
for (int y = y_max - 1; y < y_max; y++) {
|
||||
m_blocks[get_index(x, y, z)] = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
std::unordered_map<unsigned, std::string> MapTable::id_to_name_map;
|
||||
std::unordered_map<size_t, unsigned> MapTable::name_to_id_map;
|
||||
|
||||
constexpr std::array<std::string, MAX_BLOCK_NUM> BLOCK_REISTER{
|
||||
"air",
|
||||
"grass_block",
|
||||
"dirt",
|
||||
"stone"
|
||||
};
|
||||
|
||||
|
||||
const std::string& MapTable::get_name_from_id(unsigned id) {
|
||||
auto it = id_to_name_map.find(id);
|
||||
@@ -17,13 +24,16 @@ const unsigned MapTable::get_id_from_name(const std::string& name) {
|
||||
CUBED_ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist");
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void MapTable::init_map() {
|
||||
id_to_name_map.reserve(MAX_BLOCK_NUM);
|
||||
name_to_id_map.reserve(MAX_BLOCK_NUM);
|
||||
id_to_name_map[0] = "air";
|
||||
name_to_id_map[HASH::str("air")] = 0;
|
||||
id_to_name_map[1] = "grass_block";
|
||||
name_to_id_map[HASH::str("grass_block")] = 1;
|
||||
|
||||
for (int i = 0; i < MAX_BLOCK_NUM; i++) {
|
||||
id_to_name_map[i] = BLOCK_REISTER[i];
|
||||
name_to_id_map[HASH::str(BLOCK_REISTER[i])] = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user