diff --git a/Environment.cpp b/Environment.cpp index b7abe4f..6a26a80 100644 --- a/Environment.cpp +++ b/Environment.cpp @@ -42,4 +42,7 @@ bool Environment::exitGameLoop = false; bool Environment::gameIsLoading = true; +float Environment::monsterTimer = 0.0; +int Environment::monsterState = 1; + } // namespace ZL diff --git a/Environment.h b/Environment.h index 728900e..5e4176f 100644 --- a/Environment.h +++ b/Environment.h @@ -46,6 +46,9 @@ public: static bool gameIsLoading; + static float monsterTimer; + static int monsterState; + }; diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index 86e5184..5a6b25e 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -174,6 +174,15 @@ void GameObjectManager::initialize() { objects_in_inventory++; + monsterTexturePtr1 = std::make_shared(CreateTextureDataFromBmp32("./monster001.bmp32")); + monsterTexturePtr2 = std::make_shared(CreateTextureDataFromBmp32("./monster002.bmp32")); + + + monsterScreenMesh = CreateRect2D({ 0.f, 0.f }, { 300.f, 300.f }, 0.5); + monsterScreenMeshMutable.AssignFrom(monsterScreenMesh); + monsterScreenMeshMutable.RefreshVBO(); + + //SDL_ShowCursor(SDL_DISABLE); SDL_SetRelativeMouseMode(SDL_TRUE); @@ -555,6 +564,30 @@ void GameObjectManager::updateScene(size_t ms) { Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame); } } + + if (Environment::monsterState == 0) + { + Environment::monsterTimer += ms; + + if (Environment::monsterTimer > 500) + { + Environment::monsterTimer = 0; + Environment::monsterState = 1; + } + } + else + { + Environment::monsterTimer += ms; + + if (Environment::monsterTimer > 500) + { + Environment::monsterTimer = 0; + Environment::monsterState = 0; + } + } + + //float Environment::monsterTimer = 0.0; + //int Environment::monsterState = 1; } bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const { diff --git a/GameObjectManager.h b/GameObjectManager.h index fff98d7..55b414a 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -81,6 +81,12 @@ public: bool sideThreadLoadingCompleted = false; int current_room_index; + + std::shared_ptr monsterTexturePtr1; + std::shared_ptr monsterTexturePtr2; + ZL::VertexDataStruct monsterScreenMesh; + ZL::VertexRenderStruct monsterScreenMeshMutable; + private: //int animationCounter = 0; int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши diff --git a/RenderSystem.cpp b/RenderSystem.cpp index e4a4411..86b5c5e 100644 --- a/RenderSystem.cpp +++ b/RenderSystem.cpp @@ -121,6 +121,8 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) { //glBindTexture(GL_TEXTURE_2D, gameObjects.coneTexturePtr->getTexID()); //renderer.DrawVertexRenderStruct(gameObjects.coneMeshMutable); + //drawMonster(gameObjects); + //glClear(GL_DEPTH_BUFFER_BIT); drawViola(gameObjects); @@ -175,6 +177,13 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) { glBindTexture(GL_TEXTURE_2D, gameObjects.rooms[gameObjects.current_room_index].roomTexture->getTexID()); renderer.DrawVertexRenderStruct(gameObjects.rooms[gameObjects.current_room_index].textMeshMutable); + if (gameObjects.current_room_index == 1) + { + drawMonster(gameObjects); + } + drawViola(gameObjects); + + Matrix4f latestProjectionModelView = renderer.GetProjectionModelViewMatrix(); // Проверяем пересечение с мышью после расчета всех матриц @@ -326,6 +335,55 @@ void RenderSystem::drawLoadingScreen(const GameObjectManager& gameObjects) } +void RenderSystem::drawMonster(const GameObjectManager& gameObjects) +{ + renderer.shaderManager.PushShader("default"); + + static const std::string vPositionName = "vPosition"; + static const std::string vTexCoordName = "vTexCoord"; + renderer.EnableVertexAttribArray(vPositionName); + renderer.EnableVertexAttribArray(vTexCoordName); + + renderer.PushProjectionMatrix(static_cast(Environment::width), + static_cast(Environment::height), -10, 10); + renderer.PushMatrix(); + renderer.LoadIdentity(); + + + std::cout << "Found activeObjectScreenTexturePtr" << std::endl; + int screenX, screenY; + + Vector3f objectPosPlusShift = Vector3f{ -300, 50, -70 }; + worldToScreenCoordinates(objectPosPlusShift, currentProjectionModelView, + Environment::width, Environment::height, screenX, screenY); + renderer.PushMatrix(); + // Здесь можно использовать вычисленные screenX, screenY, + // но для теста оставляем фиксированное значение + renderer.TranslateMatrix(Vector3f{ screenX + 0.f, screenY + 0.f, 0.0f }); + + if (Environment::monsterState == 0) + { + glBindTexture(GL_TEXTURE_2D, gameObjects.monsterTexturePtr1->getTexID()); + } + else + { + glBindTexture(GL_TEXTURE_2D, gameObjects.monsterTexturePtr2->getTexID()); + } + renderer.DrawVertexRenderStruct(gameObjects.monsterScreenMeshMutable); + renderer.PopMatrix(); + + + renderer.PopMatrix(); + renderer.PopProjectionMatrix(); + + // Выключаем атрибуты, чтобы сохранить баланс + renderer.DisableVertexAttribArray(vPositionName); + renderer.DisableVertexAttribArray(vTexCoordName); + + // Снимаем шейдер, тем самым балансируя стек + renderer.shaderManager.PopShader(); +} + void RenderSystem::worldToScreenCoordinates(Vector3f objectPos, Matrix4f projectionModelView, int screenWidth, int screenHeight, diff --git a/RenderSystem.h b/RenderSystem.h index 86fd9bf..002ab8e 100644 --- a/RenderSystem.h +++ b/RenderSystem.h @@ -26,6 +26,7 @@ private: void drawViola(GameObjectManager& gameObjects); void drawLoadingScreen(const GameObjectManager& gameObjects); + void drawMonster(const GameObjectManager& gameObjects); ShaderManager shaderManager; Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI diff --git a/monster001.bmp32 b/monster001.bmp32 new file mode 100644 index 0000000..ec7ce4f Binary files /dev/null and b/monster001.bmp32 differ diff --git a/monster002.bmp32 b/monster002.bmp32 new file mode 100644 index 0000000..9c45d9f Binary files /dev/null and b/monster002.bmp32 differ