Merge pull request #27 from mephi1984/pavel

Pavel
This commit is contained in:
Pavel Makarov 2025-03-03 00:01:27 +06:00 committed by GitHub
commit b51ef1f983
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 108 additions and 22 deletions

View File

@ -7,8 +7,11 @@
namespace ZL { namespace ZL {
const float GameObjectManager::INVENTORY_ICON_SIZE = 64.0f; const float GameObjectManager::INVENTORY_ICON_SIZE = 44.0f;
const float GameObjectManager::INVENTORY_MARGIN = 10.0f; const float GameObjectManager::INVENTORY_MARGIN = 44.0f;
const float GameObjectManager::SELECTED_CUBE_ICON_SIZE = 244.0f;
const float GameObjectManager::SELECTED_CUBE_MARGIN = 50.0f;
void GameObjectManager::initializeLoadingScreen() void GameObjectManager::initializeLoadingScreen()
{ {
@ -26,12 +29,15 @@ void GameObjectManager::initializeLoadingScreen()
void GameObjectManager::initialize() { void GameObjectManager::initialize() {
initializeLoadingScreen(); initializeLoadingScreen();
std::function<bool()> loadingFunction1 = [this]() std::function<bool()> loadingFunction1 = [this]()
{ {
current_room_index = 0; current_room_index = 0;
objects_in_inventory = 0; objects_in_inventory = 0;
bearName = "";
current_room_index = 0;
objects_in_inventory = 0;
//coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp")); //coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
@ -152,16 +158,18 @@ void GameObjectManager::initialize() {
//roomTexturePtr = rooms[current_room_index].roomTexture; //roomTexturePtr = rooms[current_room_index].roomTexture;
AddItemToInventory("book1", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); AddItemToInventory("cube_T", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
objects_in_inventory++; objects_in_inventory++;
AddItemToInventory("book2", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1); AddItemToInventory("cube_O", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
objects_in_inventory++;
AddItemToInventory("cube_M", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
objects_in_inventory++; objects_in_inventory++;
//SDL_ShowCursor(SDL_DISABLE); //SDL_ShowCursor(SDL_DISABLE);
SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE);
return true; return true;
}; };
@ -200,6 +208,40 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
} }
else if (event.type == SDL_MOUSEBUTTONDOWN) { else if (event.type == SDL_MOUSEBUTTONDOWN) {
const auto highlightedObjects = aoMgr.findByHighlighted(true); const auto highlightedObjects = aoMgr.findByHighlighted(true);
if (InventoryItem* item = GetItemSelected(true)) {
std::cout << item->name << std::endl;
if (current_room_index==0) {
if (bearName.length() <= 3) {
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();
}
}
}
else {
const auto highlightedObjects = aoMgr.findByHighlighted(true);
for (auto* ao : highlightedObjects) { for (auto* ao : highlightedObjects) {
if (!ao) { if (!ao) {
@ -213,7 +255,9 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
} }
// bx.Interpolate(animationCounter); // bx.Interpolate(animationCounter);
// animationCounter += 2; // animationCounter += 2;
}
} }
else if (event.type == SDL_MOUSEWHEEL) { else if (event.type == SDL_MOUSEWHEEL) {
static const float zoomstep = 1.0f; static const float zoomstep = 1.0f;
if (event.wheel.y > 0) { if (event.wheel.y > 0) {
@ -291,10 +335,17 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
break; break;
case SDLK_1: case SDLK_1:
case SDLK_2: case SDLK_2:
{ case SDLK_3:
int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2; case SDLK_4:
case SDLK_5:
case SDLK_6:
case SDLK_7:
case SDLK_8:
case SDLK_9:
{
UnselectAllItems(); UnselectAllItems();
if (InventoryItem* item = GetItemByHotkey(hot_key)) { if (InventoryItem* item = GetItemByHotkey(event.key.keysym.sym - SDLK_1 + 1)) {
item->isSelected = true; item->isSelected = true;
} }
} }
@ -423,7 +474,7 @@ void GameObjectManager::updateScene(size_t ms) {
newPosition.v[0] += directionVector.v[1] * ms; newPosition.v[0] += directionVector.v[1] * ms;
} }
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]}; Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
std::cout << "Player position: x=" << characterNewPos.v[0] std::cout << "Player position: x=" << characterNewPos.v[0]

View File

@ -4,14 +4,18 @@
#include "AudioPlayerAsync.h" #include "AudioPlayerAsync.h"
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <list>
#include "ActiveObject.h" #include "ActiveObject.h"
#include "Room.h" #include "Room.h"
#include "Inventory.h"
#ifdef __linux__ #ifdef __linux__
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif
#include "OpenGlExtensions.h" #include "OpenGlExtensions.h"
#include <thread> #include <thread>
#include <list>
#include "BoundaryBox.h" // Добавляем новый include
namespace ZL { namespace ZL {
@ -50,7 +54,10 @@ public:
std::vector<ZL::ActiveObject> activeObjects; std::vector<ZL::ActiveObject> activeObjects;
std::vector<ZL::Room> rooms; std::vector<ZL::Room> rooms;
std::vector<InventoryItem> selectedCubes;
std::string bearName;
AudioPlayerAsync audioPlayerAsync; AudioPlayerAsync audioPlayerAsync;
ZL::VertexDataStruct inventoryIconMesh; ZL::VertexDataStruct inventoryIconMesh;
@ -58,6 +65,8 @@ public:
static const float INVENTORY_ICON_SIZE; static const float INVENTORY_ICON_SIZE;
static const float INVENTORY_MARGIN; static const float INVENTORY_MARGIN;
static const float SELECTED_CUBE_ICON_SIZE;
static const float SELECTED_CUBE_MARGIN;
ActiveObjectManager aoMgr; ActiveObjectManager aoMgr;
int objects_in_inventory; int objects_in_inventory;
@ -73,11 +82,10 @@ public:
int current_room_index; int current_room_index;
private: private:
//int animationCounter = 0; //int animationCounter = 0;
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
int lastMouseY = 0; int lastMouseY = 0;
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const; bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод
Matrix4f projectionModelView, Matrix4f projectionModelView,

View File

@ -2,6 +2,9 @@
#include "GameObjectManager.h" #include "GameObjectManager.h"
#include "Inventory.h" #include "Inventory.h"
#include <iostream> #include <iostream>
#include <chrono>
#include <thread>
namespace ZL namespace ZL
{ {
@ -9,16 +12,16 @@ namespace ZL
std::function<void(GameObjectManager&, size_t)> createRoom1Logic() std::function<void(GameObjectManager&, size_t)> createRoom1Logic()
{ {
return [](GameObjectManager& gom, size_t ms) return [](GameObjectManager& gom, size_t ms)
// Simple test logic
{ {
if (GetItemByName("book")) { if (gom.bearName.compare("TOM") == 0) {
std::cout << "[Room 1] Игрок поднял книгу!\n"; gInventoryMap.clear();
// std::this_thread::sleep_for(std::chrono::seconds(1));
gom.switch_room(1); gom.switch_room(1);
} }
}; };
} }
std::function<void(GameObjectManager&, size_t)> createRoom2Logic() std::function<void(GameObjectManager&, size_t)> createRoom2Logic()
{ {
return [](GameObjectManager& gom, size_t ms) return [](GameObjectManager& gom, size_t ms)

View File

@ -235,11 +235,12 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
if (item.isSelected) { if (item.isSelected) {
float xPos = Environment::width float xPos = Environment::width
- gameObjects.INVENTORY_MARGIN - gameObjects.INVENTORY_MARGIN
- gameObjects.INVENTORY_ICON_SIZE+25; - gameObjects.INVENTORY_ICON_SIZE;
float yPos = gameObjects.INVENTORY_MARGIN float yPos = gameObjects.INVENTORY_MARGIN
+ i * (gameObjects.INVENTORY_ICON_SIZE+25 + i * (gameObjects.INVENTORY_ICON_SIZE
+ gameObjects.INVENTORY_MARGIN); + gameObjects.INVENTORY_MARGIN);
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f}); renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
renderer.ScaleMatrix(Vector3f{1.5f, 1.5f, 1.0f});
glBindTexture(GL_TEXTURE_2D, item.texture->getTexID()); glBindTexture(GL_TEXTURE_2D, item.texture->getTexID());
} }
else { else {
@ -261,6 +262,29 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
i++; 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) + 300.0f;
// Оставляем y константным
float yPos = 500.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.PopMatrix();
renderer.PopProjectionMatrix(); renderer.PopProjectionMatrix();

View File

@ -9,6 +9,7 @@ namespace ZL {
class RenderSystem { class RenderSystem {
public: public:
RenderSystem() = default; RenderSystem() = default;
Renderer renderer;
void initialize(); void initialize();
void drawScene(GameObjectManager& gameObjects); void drawScene(GameObjectManager& gameObjects);
Renderer& getRenderer() { return renderer; } Renderer& getRenderer() { return renderer; }
@ -26,7 +27,6 @@ private:
void drawLoadingScreen(const GameObjectManager& gameObjects); void drawLoadingScreen(const GameObjectManager& gameObjects);
Renderer renderer;
ShaderManager shaderManager; ShaderManager shaderManager;
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
int lastMouseX = 0; int lastMouseX = 0;