diff --git a/assets/textures/tools/diamond_axe.png b/assets/textures/tools/diamond_axe.png new file mode 100644 index 0000000..7627f87 Binary files /dev/null and b/assets/textures/tools/diamond_axe.png differ diff --git a/assets/textures/tools/diamond_shovel.png b/assets/textures/tools/diamond_shovel.png new file mode 100644 index 0000000..e4a8992 Binary files /dev/null and b/assets/textures/tools/diamond_shovel.png differ diff --git a/assets/textures/tools/gold_axe.png b/assets/textures/tools/gold_axe.png new file mode 100644 index 0000000..0f47b60 Binary files /dev/null and b/assets/textures/tools/gold_axe.png differ diff --git a/assets/textures/tools/gold_shovel.png b/assets/textures/tools/gold_shovel.png new file mode 100644 index 0000000..150cbb9 Binary files /dev/null and b/assets/textures/tools/gold_shovel.png differ diff --git a/assets/textures/tools/iron_axe.png b/assets/textures/tools/iron_axe.png new file mode 100644 index 0000000..8bf133e Binary files /dev/null and b/assets/textures/tools/iron_axe.png differ diff --git a/assets/textures/tools/iron_shovel.png b/assets/textures/tools/iron_shovel.png new file mode 100644 index 0000000..079b236 Binary files /dev/null and b/assets/textures/tools/iron_shovel.png differ diff --git a/assets/textures/tools/stone_axe.png b/assets/textures/tools/stone_axe.png new file mode 100644 index 0000000..fb33584 Binary files /dev/null and b/assets/textures/tools/stone_axe.png differ diff --git a/assets/textures/tools/stone_shovel.png b/assets/textures/tools/stone_shovel.png new file mode 100644 index 0000000..8e1c0c2 Binary files /dev/null and b/assets/textures/tools/stone_shovel.png differ diff --git a/assets/textures/tools/wood_axe.png b/assets/textures/tools/wood_axe.png new file mode 100644 index 0000000..3a19203 Binary files /dev/null and b/assets/textures/tools/wood_axe.png differ diff --git a/assets/textures/tools/wood_shovel.png b/assets/textures/tools/wood_shovel.png new file mode 100644 index 0000000..b057911 Binary files /dev/null and b/assets/textures/tools/wood_shovel.png differ diff --git a/assets/textures/weapons/diamond_sword.png b/assets/textures/weapons/diamond_sword.png new file mode 100644 index 0000000..2a1552d Binary files /dev/null and b/assets/textures/weapons/diamond_sword.png differ diff --git a/assets/textures/weapons/gold_sword.png b/assets/textures/weapons/gold_sword.png new file mode 100644 index 0000000..0ddef04 Binary files /dev/null and b/assets/textures/weapons/gold_sword.png differ diff --git a/assets/textures/weapons/iron_sword.png b/assets/textures/weapons/iron_sword.png new file mode 100644 index 0000000..4d49c5a Binary files /dev/null and b/assets/textures/weapons/iron_sword.png differ diff --git a/assets/textures/weapons/stone_sword.png b/assets/textures/weapons/stone_sword.png new file mode 100644 index 0000000..5810dfd Binary files /dev/null and b/assets/textures/weapons/stone_sword.png differ diff --git a/assets/textures/weapons/wood_sword.png b/assets/textures/weapons/wood_sword.png new file mode 100644 index 0000000..c04dc0a Binary files /dev/null and b/assets/textures/weapons/wood_sword.png differ diff --git a/imgui.ini b/imgui.ini index 968af1b..6cf6939 100644 --- a/imgui.ini +++ b/imgui.ini @@ -7,11 +7,11 @@ Pos=38,36 Size=253,111 [Window][##MainMenu] -Pos=1030,513 +Pos=710,320 Size=499,350 [Window][##WorldSelect] -Pos=1030,438 +Pos=710,245 Size=500,500 [Window][Debug] @@ -23,7 +23,7 @@ Pos=587,46 Size=192,167 [Window][##PauseMenu] -Pos=1105,538 +Pos=785,345 Size=350,300 [Window][Chat] @@ -35,10 +35,10 @@ Pos=1030,438 Size=500,500 [Window][##Inventory] -Pos=1016,546 +Pos=696,353 Size=528,284 [Window][##CreativeInventory] -Pos=1016,564 -Size=528,248 +Pos=696,315 +Size=528,360 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b4166a..f8c4ccb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,6 +50,25 @@ embed_asset(embed_stone_pickaxe_png "${_TEX}/tools/stone_pickaxe.png") embed_asset(embed_gold_pickaxe_png "${_TEX}/tools/gold_pickaxe.png") embed_asset(embed_iron_pickaxe_png "${_TEX}/tools/iron_pickaxe.png") +embed_asset(embed_diamond_axe_png "${_TEX}/tools/diamond_axe.png") +embed_asset(embed_wood_axe_png "${_TEX}/tools/wood_axe.png") +embed_asset(embed_stone_axe_png "${_TEX}/tools/stone_axe.png") +embed_asset(embed_gold_axe_png "${_TEX}/tools/gold_axe.png") +embed_asset(embed_iron_axe_png "${_TEX}/tools/iron_axe.png") + +embed_asset(embed_diamond_shovel_png "${_TEX}/tools/diamond_shovel.png") +embed_asset(embed_wood_shovel_png "${_TEX}/tools/wood_shovel.png") +embed_asset(embed_stone_shovel_png "${_TEX}/tools/stone_shovel.png") +embed_asset(embed_gold_shovel_png "${_TEX}/tools/gold_shovel.png") +embed_asset(embed_iron_shovel_png "${_TEX}/tools/iron_shovel.png") + +# weapons +embed_asset(embed_diamond_sword_png "${_TEX}/weapons/diamond_sword.png") +embed_asset(embed_wood_sword_png "${_TEX}/weapons/wood_sword.png") +embed_asset(embed_stone_sword_png "${_TEX}/weapons/stone_sword.png") +embed_asset(embed_gold_sword_png "${_TEX}/weapons/gold_sword.png") +embed_asset(embed_iron_sword_png "${_TEX}/weapons/iron_sword.png") + # blocks embed_asset(embed_dirt_png "${_TEX}/dirt.png") diff --git a/src/core/main.cpp b/src/core/main.cpp index 5960472..b598b4e 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1,3 +1,4 @@ +#include #ifdef _WIN32 #define NOMINMAX #define WIN32_LEAN_AND_MEAN @@ -678,7 +679,9 @@ int main(int argc, char* argv[]) else { float hardness = getBlockHardness(player.breakingBlockId); - player.breakProgress += deltaTime / hardness; + uint8_t heldId = player.inventory.selectedItem().blockId; + float speedMult = getToolSpeedMultiplier(heldId, player.breakingBlockId); + player.breakProgress += (deltaTime / hardness) * speedMult; if (player.breakProgress >= 1.0f) { setBlockAtWorld(hit->blockPos.x, hit->blockPos.y, hit->blockPos.z, 0, *chunkManager); diff --git a/src/gameplay/Inventory.cpp b/src/gameplay/Inventory.cpp index 132eb4a..479c157 100644 --- a/src/gameplay/Inventory.cpp +++ b/src/gameplay/Inventory.cpp @@ -30,6 +30,21 @@ const std::vector& getCreativeItems() {TOOL_STONE_PICKAXE, "Stone Pickaxe"}, {TOOL_GOLD_PICKAXE, "Gold Pickaxe"}, {TOOL_IRON_PICKAXE, "Iron Pickaxe"}, + {TOOL_DIAMOND_AXE, "Diamond Axe"}, + {TOOL_WOOD_AXE, "Wood Axe"}, + {TOOL_STONE_AXE, "Stone Axe"}, + {TOOL_GOLD_AXE, "Gold Axe"}, + {TOOL_IRON_AXE, "Iron Axe"}, + {TOOL_DIAMOND_SHOVEL, "Diamond Shovel"}, + {TOOL_WOOD_SHOVEL, "Wood Shovel"}, + {TOOL_STONE_SHOVEL, "Stone Shovel"}, + {TOOL_GOLD_SHOVEL, "Gold Shovel"}, + {TOOL_IRON_SHOVEL, "Iron Shovel"}, + {TOOL_DIAMOND_SWORD, "Diamond Sword"}, + {TOOL_WOOD_SWORD, "Wood Sword"}, + {TOOL_STONE_SWORD, "Stone Sword"}, + {TOOL_GOLD_SWORD, "Gold Sword"}, + {TOOL_IRON_SWORD, "Iron Sword"}, }; return items; } diff --git a/src/rendering/ToolModelGenerator.cpp b/src/rendering/ToolModelGenerator.cpp index 0d2f708..a41a56b 100644 --- a/src/rendering/ToolModelGenerator.cpp +++ b/src/rendering/ToolModelGenerator.cpp @@ -188,6 +188,24 @@ void loadToolModels() {TOOL_STONE_PICKAXE, embed_stone_pickaxe_png_data, embed_stone_pickaxe_png_size}, {TOOL_GOLD_PICKAXE, embed_gold_pickaxe_png_data, embed_gold_pickaxe_png_size}, {TOOL_IRON_PICKAXE, embed_iron_pickaxe_png_data, embed_iron_pickaxe_png_size}, + + {TOOL_DIAMOND_AXE, embed_diamond_axe_png_data, embed_diamond_axe_png_size}, + {TOOL_WOOD_AXE, embed_wood_axe_png_data, embed_wood_axe_png_size}, + {TOOL_STONE_AXE, embed_stone_axe_png_data, embed_stone_axe_png_size}, + {TOOL_GOLD_AXE, embed_gold_axe_png_data, embed_gold_axe_png_size}, + {TOOL_IRON_AXE, embed_iron_axe_png_data, embed_iron_axe_png_size}, + + {TOOL_DIAMOND_SHOVEL, embed_diamond_shovel_png_data, embed_diamond_shovel_png_size}, + {TOOL_WOOD_SHOVEL, embed_wood_shovel_png_data, embed_wood_shovel_png_size}, + {TOOL_STONE_SHOVEL, embed_stone_shovel_png_data, embed_stone_shovel_png_size}, + {TOOL_GOLD_SHOVEL, embed_gold_shovel_png_data, embed_gold_shovel_png_size}, + {TOOL_IRON_SHOVEL, embed_iron_shovel_png_data, embed_iron_shovel_png_size}, + + {TOOL_DIAMOND_SWORD, embed_diamond_sword_png_data, embed_diamond_sword_png_size}, + {TOOL_WOOD_SWORD, embed_wood_sword_png_data, embed_wood_sword_png_size}, + {TOOL_STONE_SWORD, embed_stone_sword_png_data, embed_stone_sword_png_size}, + {TOOL_GOLD_SWORD, embed_gold_sword_png_data, embed_gold_sword_png_size}, + {TOOL_IRON_SWORD, embed_iron_sword_png_data, embed_iron_sword_png_size}, }; for (const auto &tool : tools) diff --git a/src/rendering/ToolModelGenerator.h b/src/rendering/ToolModelGenerator.h index 8b215c1..800fdb9 100644 --- a/src/rendering/ToolModelGenerator.h +++ b/src/rendering/ToolModelGenerator.h @@ -28,6 +28,27 @@ constexpr uint8_t TOOL_STONE_PICKAXE = 130; constexpr uint8_t TOOL_GOLD_PICKAXE = 131; constexpr uint8_t TOOL_IRON_PICKAXE = 132; +// axes +constexpr uint8_t TOOL_DIAMOND_AXE = 133; +constexpr uint8_t TOOL_WOOD_AXE = 134; +constexpr uint8_t TOOL_STONE_AXE = 135; +constexpr uint8_t TOOL_GOLD_AXE = 136; +constexpr uint8_t TOOL_IRON_AXE = 137; + +// shovels +constexpr uint8_t TOOL_DIAMOND_SHOVEL = 138; +constexpr uint8_t TOOL_WOOD_SHOVEL = 139; +constexpr uint8_t TOOL_STONE_SHOVEL = 140; +constexpr uint8_t TOOL_GOLD_SHOVEL = 141; +constexpr uint8_t TOOL_IRON_SHOVEL = 142; + +// swords +constexpr uint8_t TOOL_DIAMOND_SWORD = 143; +constexpr uint8_t TOOL_WOOD_SWORD = 144; +constexpr uint8_t TOOL_STONE_SWORD = 145; +constexpr uint8_t TOOL_GOLD_SWORD = 146; +constexpr uint8_t TOOL_IRON_SWORD = 147; + inline bool isToolItem(uint8_t id) { return id >= TOOL_ID_START; } class ToolModelGenerator { diff --git a/src/utils/BlockTypes.cpp b/src/utils/BlockTypes.cpp index 044c71b..1cad325 100644 --- a/src/utils/BlockTypes.cpp +++ b/src/utils/BlockTypes.cpp @@ -1,4 +1,5 @@ #include "BlockTypes.h" +#include "../rendering/ToolModelGenerator.h" std::array g_blockTypes; std::array g_defaultBlockTypes; @@ -210,3 +211,63 @@ float getBlockHardness(uint8_t blockId) default: return 1.0f; } } + +ToolType getBlockPreferredTool(uint8_t blockId) +{ + switch (blockId) + { + case 3: //stone + case 22: //cobblestone + return ToolType::Pickaxe; + case 4: //log + case 5: //planks + return ToolType::Axe; + case 1: //dirt + case 2: //grass + case 6: //sand + case 21: //snow + return ToolType::Shovel; + default: + return ToolType::None; + } +} + +float getToolSpeedMultiplier(uint8_t toolItemId, uint8_t blockId) +{ + ToolType preferred = getBlockPreferredTool(blockId); + if (preferred == ToolType::None) + return 1.0f; + + if (preferred == ToolType::Pickaxe) { + switch (toolItemId) + { + case TOOL_WOOD_PICKAXE: return 1.0f; + case TOOL_STONE_PICKAXE: return 1.5f; + case TOOL_IRON_PICKAXE: return 1.9f; + case TOOL_GOLD_PICKAXE: return 2.2f; + case TOOL_DIAMOND_PICKAXE: return 3.0f; + default: return 0.3f; + } + } else if (preferred == ToolType::Axe) { + switch (toolItemId) + { + case TOOL_WOOD_AXE: return 1.0f; + case TOOL_STONE_AXE: return 1.5f; + case TOOL_IRON_AXE: return 1.9f; + case TOOL_GOLD_AXE: return 2.2f; + case TOOL_DIAMOND_AXE: return 3.0f; + default: return 0.3f; + } + } else if (preferred == ToolType::Shovel) { + switch (toolItemId) + { + case TOOL_WOOD_SHOVEL: return 1.0f; + case TOOL_STONE_SHOVEL: return 1.5f; + case TOOL_IRON_SHOVEL: return 1.9f; + case TOOL_GOLD_SHOVEL: return 2.2f; + case TOOL_DIAMOND_SHOVEL: return 3.0f; + default: return 0.3f; + } + } + return 0.3f; +} diff --git a/src/utils/BlockTypes.h b/src/utils/BlockTypes.h index aaa54cd..16622fa 100644 --- a/src/utils/BlockTypes.h +++ b/src/utils/BlockTypes.h @@ -26,6 +26,9 @@ enum BlockTex : int }; float getBlockHardness(uint8_t blockId); +enum class ToolType { None, Pickaxe, Axe, Shovel, Sword }; +ToolType getBlockPreferredTool(uint8_t blockId); +float getToolSpeedMultiplier(uint8_t toolItemId, uint8_t blockId); struct BlockType {