From 1229e61702743a91e85f0ce97c3296277761c2d8 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 19:42:03 +0600 Subject: [PATCH 1/8] scaling inventory obj --- GameObjectManager.cpp | 35 +++++++++++++++++++++++++++++++++-- GameObjectManager.h | 2 ++ QuestScripts.cpp | 6 +----- RenderSystem.cpp | 5 +++-- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 81e5914..9dfd612 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -7,8 +7,8 @@ namespace ZL { -const float GameObjectManager::INVENTORY_ICON_SIZE = 64.0f; -const float GameObjectManager::INVENTORY_MARGIN = 10.0f; +const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f; +const float GameObjectManager::INVENTORY_MARGIN = 20.0f; void GameObjectManager::initialize() { @@ -511,4 +511,35 @@ void GameObjectManager::worldToScreenCoordinates(Vector3f objectPos, screenY = (int)((1.0f + ndcY) * 0.5f * screenHeight); } +void GameObjectManager::addRectangle(int x, int y, int width, int height, int r, int g, int b, int borderWidth, int borderR, int borderG, int borderB) { + // Преобразование RGB в диапазон [0,1] для OpenGL + float rf = r / 255.0f; + float gf = g / 255.0f; + float bf = b / 255.0f; + float borderRf = borderR / 255.0f; + float borderGf = borderG / 255.0f; + float borderBf = borderB / 255.0f; + + // Отрисовка заполненного прямоугольника + glColor3f(rf, gf, bf); + glBegin(GL_QUADS); + glVertex2f(x, y); + glVertex2f(x + width, y); + glVertex2f(x + width, y + height); + glVertex2f(x, y + height); + glEnd(); + + // Отрисовка рамки + if (borderWidth > 0) { + glColor3f(borderRf, borderGf, borderBf); + glLineWidth(borderWidth); + glBegin(GL_LINE_LOOP); + glVertex2f(x, y); + glVertex2f(x + width, y); + glVertex2f(x + width, y + height); + glVertex2f(x, y + height); + glEnd(); + } +} + } // namespace ZL diff --git a/GameObjectManager.h b/GameObjectManager.h index cae553e..7c5eb0f 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -56,6 +56,8 @@ public: static const float INVENTORY_MARGIN; ActiveObjectManager aoMgr; int objects_in_inventory; + void addRectangle(int x, int y, int width, int height, int r, int g, int b, int borderWidth, int borderR, int borderG, int borderB); + private: //int animationCounter = 0; diff --git a/QuestScripts.cpp b/QuestScripts.cpp index 7f9a009..474cd6d 100644 --- a/QuestScripts.cpp +++ b/QuestScripts.cpp @@ -9,16 +9,12 @@ namespace ZL std::function createRoom1Logic() { return [](GameObjectManager& gom, size_t ms) -// Simple test logic { - if (GetItemByName("book")) { - std::cout << "[Room 1] Игрок поднял книгу!\n"; - gom.switch_room(1); - } }; } + std::function createRoom2Logic() { return [](GameObjectManager& gom, size_t ms) diff --git a/RenderSystem.cpp b/RenderSystem.cpp index d53e6eb..abe1ead 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -237,11 +237,12 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) { if (item.isSelected) { float xPos = Environment::width - gameObjects.INVENTORY_MARGIN - - gameObjects.INVENTORY_ICON_SIZE+25; + - gameObjects.INVENTORY_ICON_SIZE; float yPos = gameObjects.INVENTORY_MARGIN - + i * (gameObjects.INVENTORY_ICON_SIZE+25 + + i * (gameObjects.INVENTORY_ICON_SIZE + gameObjects.INVENTORY_MARGIN); renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); + renderer.ScaleMatrix(Vector3f{1.5f, 1.5f, 1.0f}); glBindTexture(GL_TEXTURE_2D, item.texture->getTexID()); } else { From ebf292d993ffdec84f79ae36b98b0d45cb263032 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 21:55:27 +0600 Subject: [PATCH 2/8] started first level logic --- GameObjectManager.cpp | 21 ++++++++++++++++++++- GameObjectManager.h | 6 +++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 1c8879a..68dbf3a 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -11,7 +11,7 @@ const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f; const float GameObjectManager::INVENTORY_MARGIN = 20.0f; void GameObjectManager::initialize() { - + bearName = ""; current_room_index = 0; objects_in_inventory = 0; @@ -159,6 +159,25 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (InventoryItem* item = GetItemSelected(true)) { + if (InventoryItem* item = GetItemSelected(true)) { + if (current_room_index==1) { + if (bearName.length() < 3) { + if (item->name == "cube_T"){ + bearName += "T"; + selectedCubes.push_back(*item); + std::cout << bearName << std::endl; + } + else if (item->name == "cube_O"){ + bearName += "O"; + selectedCubes.push_back(*item); + } + else if (item->name == "cube_M"){ + bearName += "M"; + selectedCubes.push_back(*item); + } + } + } + } } else { diff --git a/GameObjectManager.h b/GameObjectManager.h index 8d2de46..1d6ca25 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -6,6 +6,7 @@ #include #include "ActiveObject.h" #include "Room.h" +#include "Inventory.h" #ifdef __linux__ #include #endif @@ -52,7 +53,10 @@ public: std::vector activeObjects; std::vector rooms; - + std::vector selectedCubes; + + std::string bearName; + AudioPlayerAsync audioPlayerAsync; ZL::VertexDataStruct inventoryIconMesh; From ede7597acb15eb3fa7db057916b83f84feaf7528 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 22:28:52 +0600 Subject: [PATCH 3/8] finished cubes logic --- GameObjectManager.cpp | 7 +++---- GameObjectManager.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index b97dd73..348599c 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -157,9 +157,9 @@ void GameObjectManager::initialize() { roomTexturePtr = rooms[current_room_index].roomTexture; - AddItemToInventory("book1", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); + AddItemToInventory("cube_T", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); objects_in_inventory++; - AddItemToInventory("book2", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); + AddItemToInventory("cube_O", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); objects_in_inventory++; @@ -206,7 +206,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } else if (event.type == SDL_MOUSEBUTTONDOWN) { if (InventoryItem* item = GetItemSelected(true)) { - if (InventoryItem* item = GetItemSelected(true)) { + std::cout << item->name << std::endl; if (current_room_index==1) { if (bearName.length() < 3) { if (item->name == "cube_T"){ @@ -224,7 +224,6 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } } } - } } else { diff --git a/GameObjectManager.h b/GameObjectManager.h index 921cc24..79d5c30 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -13,6 +13,7 @@ #include "OpenGlExtensions.h" #include +#include #include "BoundaryBox.h" // Добавляем новый include From 4f2741765b5b7e163590b23fdd20abce0895d18e Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 22:30:13 +0600 Subject: [PATCH 4/8] finished cubes logic --- GameObjectManager.cpp | 13 ++++++++++--- QuestScripts.cpp | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 348599c..8ca5c09 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -161,6 +161,8 @@ void GameObjectManager::initialize() { objects_in_inventory++; AddItemToInventory("cube_O", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); objects_in_inventory++; + AddItemToInventory("cube_M", std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); + objects_in_inventory++; //SDL_ShowCursor(SDL_DISABLE); @@ -207,12 +209,13 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { else if (event.type == SDL_MOUSEBUTTONDOWN) { if (InventoryItem* item = GetItemSelected(true)) { std::cout << item->name << std::endl; - if (current_room_index==1) { - if (bearName.length() < 3) { + + if (current_room_index==0) { + + if (bearName.length() <= 3) { if (item->name == "cube_T"){ bearName += "T"; selectedCubes.push_back(*item); - std::cout << bearName << std::endl; } else if (item->name == "cube_O"){ bearName += "O"; @@ -224,6 +227,10 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } } } + else if (bearName.length() >= 3 && !(bearName.compare("TOM") == 0)) { + bearName = ""; + selectedCubes.clear(); + } } else { diff --git a/QuestScripts.cpp b/QuestScripts.cpp index 474cd6d..6866738 100644 --- a/QuestScripts.cpp +++ b/QuestScripts.cpp @@ -10,7 +10,10 @@ namespace ZL { return [](GameObjectManager& gom, size_t ms) { - + if (gom.bearName.compare("TOM") == 0) { + std::cout << gom.bearName << std::endl; + gom.switch_room(1); + } }; } From c39eac424138bc36db87b341ab248da36a89721b Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 22:43:07 +0600 Subject: [PATCH 5/8] adding cubes in inventory map ifuncorrect name --- GameObjectManager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 8ca5c09..0f96622 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -10,6 +10,9 @@ namespace ZL { const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f; const float GameObjectManager::INVENTORY_MARGIN = 20.0f; +const float GameObjectManager::SELECTED_CUBE_ICON_SIZE = 44.0f; +const float GameObjectManager::SELECTED_CUBE_MARGIN = 20.0f; + void GameObjectManager::initializeLoadingScreen() { loadingScreenTexturePtr = std::make_shared(CreateTextureDataFromBmp24("./loading.bmp")); @@ -216,19 +219,25 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { if (item->name == "cube_T"){ bearName += "T"; selectedCubes.push_back(*item); + gInventoryMap.erase(item->name); } else if (item->name == "cube_O"){ bearName += "O"; selectedCubes.push_back(*item); + gInventoryMap.erase(item->name); } else if (item->name == "cube_M"){ bearName += "M"; selectedCubes.push_back(*item); + gInventoryMap.erase(item->name); } } } else if (bearName.length() >= 3 && !(bearName.compare("TOM") == 0)) { bearName = ""; + for (const auto& cube : selectedCubes) { + gInventoryMap[cube.name] = cube; + } selectedCubes.clear(); } From e8e4dc9b28c8b43af22cfff27526e64dc105ed53 Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 23:19:15 +0600 Subject: [PATCH 6/8] draw cubes --- GameObjectManager.cpp | 6 +++--- GameObjectManager.h | 4 +++- QuestScripts.cpp | 2 +- RenderSystem.cpp | 23 +++++++++++++++++++++++ RenderSystem.h | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 0f96622..d7b60a7 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -8,10 +8,10 @@ namespace ZL { const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f; -const float GameObjectManager::INVENTORY_MARGIN = 20.0f; +const float GameObjectManager::INVENTORY_MARGIN = 44.0f; -const float GameObjectManager::SELECTED_CUBE_ICON_SIZE = 44.0f; -const float GameObjectManager::SELECTED_CUBE_MARGIN = 20.0f; +const float GameObjectManager::SELECTED_CUBE_ICON_SIZE = 244.0f; +const float GameObjectManager::SELECTED_CUBE_MARGIN = 50.0f; void GameObjectManager::initializeLoadingScreen() { diff --git a/GameObjectManager.h b/GameObjectManager.h index 79d5c30..a07c9ef 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -66,6 +66,8 @@ public: static const float INVENTORY_ICON_SIZE; static const float INVENTORY_MARGIN; + static const float SELECTED_CUBE_ICON_SIZE; + static const float SELECTED_CUBE_MARGIN; ActiveObjectManager aoMgr; int objects_in_inventory; void addRectangle(int x, int y, int width, int height, int r, int g, int b, int borderWidth, int borderR, int borderG, int borderB); @@ -80,12 +82,12 @@ public: std::list> loadingFunctions; std::thread loadingThread; bool sideThreadLoadingCompleted = false; + int current_room_index; private: //int animationCounter = 0; int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши int lastMouseY = 0; - int current_room_index; bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const; void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод Matrix4f projectionModelView, diff --git a/QuestScripts.cpp b/QuestScripts.cpp index 6866738..665a3ed 100644 --- a/QuestScripts.cpp +++ b/QuestScripts.cpp @@ -11,7 +11,7 @@ namespace ZL return [](GameObjectManager& gom, size_t ms) { if (gom.bearName.compare("TOM") == 0) { - std::cout << gom.bearName << std::endl; + gInventoryMap.clear(); gom.switch_room(1); } }; diff --git a/RenderSystem.cpp b/RenderSystem.cpp index a283d8f..1d51aa6 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -263,6 +263,29 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) { i++; } + // Отрисовка кубиков + if (gameObjects.current_room_index == 0){ + for (const auto& cube : gameObjects.selectedCubes) { + renderer.PushMatrix(); + + // Смещаем по оси x: начиная с левой стороны и двигаясь вправо + float xPos = gameObjects.SELECTED_CUBE_MARGIN + + i * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN); + // Оставляем y константным + float yPos = Environment::height - gameObjects.SELECTED_CUBE_MARGIN - (gameObjects.SELECTED_CUBE_ICON_SIZE * 3.0f); + + renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); + renderer.ScaleMatrix(Vector3f{2.8f, 2.8f, 1.0f}); + glBindTexture(GL_TEXTURE_2D, cube.texture->getTexID()); + + renderer.DrawVertexRenderStruct(gameObjects.inventoryIconMeshMutable); + + renderer.PopMatrix(); + i++; + } +} + + renderer.PopMatrix(); renderer.PopProjectionMatrix(); diff --git a/RenderSystem.h b/RenderSystem.h index 979cf07..86fd9bf 100644 --- a/RenderSystem.h +++ b/RenderSystem.h @@ -9,6 +9,7 @@ namespace ZL { class RenderSystem { public: RenderSystem() = default; + Renderer renderer; void initialize(); void drawScene(GameObjectManager& gameObjects); Renderer& getRenderer() { return renderer; } @@ -26,7 +27,6 @@ private: void drawLoadingScreen(const GameObjectManager& gameObjects); - Renderer renderer; ShaderManager shaderManager; Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI int lastMouseX = 0; From 526efb217ef893e86fdfcb989f23c1a039cf741e Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Sun, 2 Mar 2025 23:32:39 +0600 Subject: [PATCH 7/8] cubes positioning --- RenderSystem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RenderSystem.cpp b/RenderSystem.cpp index 1d51aa6..83ebada 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -270,9 +270,9 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) { // Смещаем по оси x: начиная с левой стороны и двигаясь вправо float xPos = gameObjects.SELECTED_CUBE_MARGIN - + i * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN); + + i * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN) + 50.0f; // Оставляем y константным - float yPos = Environment::height - gameObjects.SELECTED_CUBE_MARGIN - (gameObjects.SELECTED_CUBE_ICON_SIZE * 3.0f); + float yPos = 500.0f; renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); renderer.ScaleMatrix(Vector3f{2.8f, 2.8f, 1.0f}); From 5ebc68043efc83e31e46fb37eaa1d1f5d097695d Mon Sep 17 00:00:00 2001 From: maka70vv <25.makarovv@gmail.com> Date: Mon, 3 Mar 2025 00:00:26 +0600 Subject: [PATCH 8/8] finished level 1 without timer --- GameObjectManager.cpp | 19 ++++++++++++++----- QuestScripts.cpp | 4 ++++ RenderSystem.cpp | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 54aa3a6..570b41c 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -222,7 +222,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { bearName += "M"; selectedCubes.push_back(*item); gInventoryMap.erase(item->name); - } + } } else if (bearName.length() >= 3 && !(bearName.compare("TOM") == 0)) { @@ -232,7 +232,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } selectedCubes.clear(); } - + } } else { const auto highlightedObjects = aoMgr.findByHighlighted(true); @@ -249,7 +249,9 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { } // bx.Interpolate(animationCounter); // animationCounter += 2; + } } + else if (event.type == SDL_MOUSEWHEEL) { static const float zoomstep = 1.0f; if (event.wheel.y > 0) { @@ -327,10 +329,17 @@ void GameObjectManager::handleEvent(const SDL_Event& event) { break; case SDLK_1: case SDLK_2: - { - int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2; + case SDLK_3: + case SDLK_4: + case SDLK_5: + case SDLK_6: + case SDLK_7: + case SDLK_8: + case SDLK_9: + { + UnselectAllItems(); - if (InventoryItem* item = GetItemByHotkey(hot_key)) { + if (InventoryItem* item = GetItemByHotkey(event.key.keysym.sym - SDLK_1 + 1)) { item->isSelected = true; } } diff --git a/QuestScripts.cpp b/QuestScripts.cpp index 665a3ed..f67a23a 100644 --- a/QuestScripts.cpp +++ b/QuestScripts.cpp @@ -2,6 +2,9 @@ #include "GameObjectManager.h" #include "Inventory.h" #include +#include +#include + namespace ZL { @@ -12,6 +15,7 @@ namespace ZL { if (gom.bearName.compare("TOM") == 0) { gInventoryMap.clear(); +// std::this_thread::sleep_for(std::chrono::seconds(1)); gom.switch_room(1); } }; diff --git a/RenderSystem.cpp b/RenderSystem.cpp index d046d14..2136935 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -269,7 +269,7 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) { // Смещаем по оси x: начиная с левой стороны и двигаясь вправо float xPos = gameObjects.SELECTED_CUBE_MARGIN - + i * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN) + 50.0f; + + i * (gameObjects.SELECTED_CUBE_ICON_SIZE + gameObjects.SELECTED_CUBE_MARGIN) + 300.0f; // Оставляем y константным float yPos = 500.0f;