diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 52abad1..7c111da 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -2,7 +2,6 @@ #include "Environment.h" #include "ObjLoader.h" #include "Inventory.h" -#include "Room.h" #include "TextModel.h" // Add this include for LoadFromTextFile namespace ZL { @@ -12,6 +11,8 @@ const float GameObjectManager::INVENTORY_MARGIN = 10.0f; void GameObjectManager::initialize() { + current_room_index = 0; + std::cout << "Hello x1" << std::endl; coneTexturePtr = std::make_shared(CreateTextureDataFromBmp24("./conus.bmp")); @@ -61,19 +62,26 @@ void GameObjectManager::initialize() { ao1.activeObjectScreenMesh = CreateRect2D({ 0.f, 0.f }, { 64.f, 64.f }, 0.5); ao1.activeObjectScreenMeshMutable.AssignFrom(ao1.activeObjectScreenMesh); ao1.activeObjectScreenMeshMutable.RefreshVBO(); - activeObjects.push_back(ao1); - std::cout << "Hello x5" << std::endl; + Room room_1; + room_1.roomTexture = std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")); + room_1.objects.push_back(ao1); + room_1.sound_name = "file_example_OOG_5MG.ogg"; + rooms.push_back(room_1); + Room room_2; + room_2.roomTexture = std::make_shared(CreateTextureDataFromBmp24("./background.bmp")); + room_2.sound_name = "Symphony No.6 (1st movement).ogg"; + rooms.push_back(room_2); + + activeObjects = rooms[current_room_index].objects; // Initialize audio audioPlayer = std::make_unique(); if (audioPlayer) { - audioPlayer->playMusic("Symphony No.6 (1st movement).ogg"); + audioPlayer->playMusic(rooms[current_room_index].sound_name); } - std::cout << "Hello x6" << std::endl; - // Initialize inventory inventoryIconMesh = CreateRect2D( {0.0f, 0.0f}, @@ -83,8 +91,6 @@ void GameObjectManager::initialize() { inventoryIconMeshMutable.AssignFrom(inventoryIconMesh); inventoryIconMeshMutable.RefreshVBO(); - std::cout << "Hello x7" << std::endl; - // Add test items to inventory auto testRoomTexture = std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")); @@ -92,25 +98,37 @@ void GameObjectManager::initialize() { AddItemToInventory("RoomCeramics", testRoomTexture); AddItemToInventory("Cone", testConeTexture); - std::cout << "Hello x8" << std::endl; + roomTexturePtr = rooms[current_room_index].roomTexture; +} - roomTexturePtr = std::make_shared(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")); +void GameObjectManager::switch_room(int index){ + current_room_index = index; + roomTexturePtr = rooms[current_room_index].roomTexture; + + if (audioPlayer) { + audioPlayer->stop(); + audioPlayer->playMusic(rooms[current_room_index].sound_name); + } + + activeObjects = rooms[current_room_index].objects; + + std::cout << "Current music" << rooms[current_room_index].sound_name << std::endl; } + void GameObjectManager::handleEvent(const SDL_Event& event) { - if (event.type == SDL_MOUSEBUTTONDOWN) { +// debug room switching + if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) { + switch_room(1); + } + else if (event.type == SDL_MOUSEBUTTONDOWN) { bx.Interpolate(animationCounter); animationCounter += 2; } - else if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) { - //switchRoom(); - - - } else if (event.type == SDL_MOUSEWHEEL) { static const float zoomstep = 1.0f; if (event.wheel.y > 0) { diff --git a/GameObjectManager.h b/GameObjectManager.h index e14b50b..d569ca1 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -5,6 +5,8 @@ #include #include #include "ActiveObject.h" +#include "Room.h" +#include #include "OpenGlExtensions.h" namespace ZL { @@ -13,6 +15,8 @@ class GameObjectManager { public: void initialize(); + void switch_room(int index); + void handleEvent(const SDL_Event& event); void updateScene(size_t ms); void checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView); // Добавляем новый метод @@ -37,6 +41,7 @@ public: ZL::VertexRenderStruct coneMeshMutable; std::vector activeObjects; + std::vector rooms; std::unique_ptr audioPlayer; ZL::VertexDataStruct inventoryIconMesh; @@ -49,6 +54,7 @@ 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/Room.h b/Room.h index 6759539..e3db5b2 100644 --- a/Room.h +++ b/Room.h @@ -1,14 +1,14 @@ #pragma once -#include -#include -#include #include "TextureManager.h" -#include "Renderer.h" -#include "ObjLoader.h" -#include "Physics.h" +#include "Math.h" +#include #include "ActiveObject.h" namespace ZL { - +struct Room{ + std::shared_ptr roomTexture; + std::vector objects; + std::string sound_name; +}; } diff --git a/sounds/file_example_OOG_5MG.ogg b/sounds/file_example_OOG_5MG.ogg new file mode 100644 index 0000000..2a9b95d Binary files /dev/null and b/sounds/file_example_OOG_5MG.ogg differ