diff --git a/assets/texture/block/dirt/back.png b/assets/texture/block/dirt/back.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/back.png differ diff --git a/assets/texture/block/dirt/base.png b/assets/texture/block/dirt/base.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/base.png differ diff --git a/assets/texture/block/dirt/front.png b/assets/texture/block/dirt/front.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/front.png differ diff --git a/assets/texture/block/dirt/left.png b/assets/texture/block/dirt/left.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/left.png differ diff --git a/assets/texture/block/dirt/right.png b/assets/texture/block/dirt/right.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/right.png differ diff --git a/assets/texture/block/dirt/top.png b/assets/texture/block/dirt/top.png new file mode 100644 index 0000000..1a49e76 Binary files /dev/null and b/assets/texture/block/dirt/top.png differ diff --git a/assets/texture/block/grass_block/back.png b/assets/texture/block/grass_block/back.png index 07df4d6..5411270 100644 Binary files a/assets/texture/block/grass_block/back.png and b/assets/texture/block/grass_block/back.png differ diff --git a/assets/texture/block/grass_block/base.png b/assets/texture/block/grass_block/base.png index 0ca459d..1a49e76 100644 Binary files a/assets/texture/block/grass_block/base.png and b/assets/texture/block/grass_block/base.png differ diff --git a/assets/texture/block/grass_block/front.png b/assets/texture/block/grass_block/front.png index 07df4d6..5411270 100644 Binary files a/assets/texture/block/grass_block/front.png and b/assets/texture/block/grass_block/front.png differ diff --git a/assets/texture/block/grass_block/left.png b/assets/texture/block/grass_block/left.png index 07df4d6..5411270 100644 Binary files a/assets/texture/block/grass_block/left.png and b/assets/texture/block/grass_block/left.png differ diff --git a/assets/texture/block/grass_block/right.png b/assets/texture/block/grass_block/right.png index 07df4d6..5411270 100644 Binary files a/assets/texture/block/grass_block/right.png and b/assets/texture/block/grass_block/right.png differ diff --git a/assets/texture/block/stone/back.png b/assets/texture/block/stone/back.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/back.png differ diff --git a/assets/texture/block/stone/base.png b/assets/texture/block/stone/base.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/base.png differ diff --git a/assets/texture/block/stone/front.png b/assets/texture/block/stone/front.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/front.png differ diff --git a/assets/texture/block/stone/left.png b/assets/texture/block/stone/left.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/left.png differ diff --git a/assets/texture/block/stone/right.png b/assets/texture/block/stone/right.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/right.png differ diff --git a/assets/texture/block/stone/top.png b/assets/texture/block/stone/top.png new file mode 100644 index 0000000..a69ad7a Binary files /dev/null and b/assets/texture/block/stone/top.png differ diff --git a/include/Cubed/config.hpp b/include/Cubed/config.hpp index caaeac2..bd1093c 100644 --- a/include/Cubed/config.hpp +++ b/include/Cubed/config.hpp @@ -1,6 +1,6 @@ #pragma once constexpr int WORLD_SIZE_Y = 256; -constexpr int MAX_BLOCK_NUM = 2; +constexpr int MAX_BLOCK_NUM = 4; constexpr int MAX_UI_NUM = 1; constexpr int CHUCK_SIZE = 16; diff --git a/src/gameplay/chunk.cpp b/src/gameplay/chunk.cpp index f41447b..ec8849f 100644 --- a/src/gameplay/chunk.cpp +++ b/src/gameplay/chunk.cpp @@ -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; } - } } diff --git a/src/map_table.cpp b/src/map_table.cpp index 9033855..66259aa 100644 --- a/src/map_table.cpp +++ b/src/map_table.cpp @@ -6,6 +6,13 @@ std::unordered_map MapTable::id_to_name_map; std::unordered_map MapTable::name_to_id_map; +constexpr std::array 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; + } + }