added inventory testing buttons I to add items O to delete last items in inventory and p to get info about inventory
This commit is contained in:
parent
a8ab5015b9
commit
880caecd97
61
main.cpp
61
main.cpp
@ -112,6 +112,12 @@ namespace ZL
|
||||
|
||||
// Add AudioPlayer instance
|
||||
std::unique_ptr<AudioPlayer> audioPlayer;
|
||||
|
||||
// Добавляем структуры для иконок инвентаря
|
||||
VertexDataStruct inventoryIconMesh;
|
||||
VertexRenderStruct inventoryIconMeshMutable;
|
||||
const float INVENTORY_ICON_SIZE = 32.0f; // Размер иконки в пикселях
|
||||
const float INVENTORY_MARGIN = 10.0f; // Отступ от края экрана
|
||||
}
|
||||
|
||||
static SDL_Window* window = NULL;
|
||||
@ -213,6 +219,18 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
// Отрисовка иконок инвентаря
|
||||
const auto& inventory = ReturnInventory();
|
||||
for (size_t i = 0; i < inventory.size(); ++i) {
|
||||
renderer.PushMatrix();
|
||||
float xPos = Env::width - GameObjects::INVENTORY_MARGIN - GameObjects::INVENTORY_ICON_SIZE;
|
||||
float yPos = GameObjects::INVENTORY_MARGIN + i * (GameObjects::INVENTORY_ICON_SIZE + GameObjects::INVENTORY_MARGIN);
|
||||
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, inventory[i].texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(GameObjects::inventoryIconMeshMutable);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
@ -393,14 +411,14 @@ namespace ZL
|
||||
ZL::AddItemToInventory("RoomCeramics", roomTexturePtr);
|
||||
ZL::AddItemToInventory("Cone", coneTexturePtr);
|
||||
|
||||
std::cout << "Before removal:\n";
|
||||
// std::cout << "Before removal:\n";
|
||||
ZL::PrintInventory();
|
||||
|
||||
// Удаляем "Cone" из инвентаря
|
||||
ZL::RemoveItemFromInventory("Cone");
|
||||
// ZL::RemoveItemFromInventory("Cone");
|
||||
|
||||
std::cout << "\nAfter removal:\n";
|
||||
ZL::PrintInventory();
|
||||
// std::cout << "\nAfter removal:\n";
|
||||
// ZL::PrintInventory();
|
||||
|
||||
// Initialize audio player and start background music
|
||||
GameObjects::audioPlayer = std::make_unique<AudioPlayer>();
|
||||
@ -408,6 +426,15 @@ namespace ZL
|
||||
GameObjects::audioPlayer->playMusic("Symphony No.6 (1st movement).ogg");
|
||||
}
|
||||
|
||||
// Инициализация меша иконки инвентаря
|
||||
GameObjects::inventoryIconMesh = CreateRect2D(
|
||||
{0.0f, 0.0f},
|
||||
{GameObjects::INVENTORY_ICON_SIZE/2, GameObjects::INVENTORY_ICON_SIZE/2},
|
||||
0.5f
|
||||
);
|
||||
GameObjects::inventoryIconMeshMutable.AssignFrom(GameObjects::inventoryIconMesh);
|
||||
GameObjects::inventoryIconMeshMutable.RefreshVBO();
|
||||
|
||||
///
|
||||
}
|
||||
|
||||
@ -491,6 +518,32 @@ namespace ZL
|
||||
GameObjects::audioPlayer->playMusic("Symphony No.6 (1st movement).ogg");
|
||||
}
|
||||
break;
|
||||
// Добавляем тестовые клавиши
|
||||
case SDLK_i: // Добавить предмет по нажатию I
|
||||
{
|
||||
static int testItemCount = 0;
|
||||
auto testTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./book03.bmp"));
|
||||
AddItemToInventory("TestItem_" + std::to_string(testItemCount++), testTexture);
|
||||
std::cout << "Added test item to inventory\n";
|
||||
PrintInventory();
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_o: // Удалить последний предмет по нажатию O
|
||||
{
|
||||
auto inventory = ReturnInventory();
|
||||
if (!inventory.empty()) {
|
||||
RemoveItemFromInventory(inventory.back().name);
|
||||
std::cout << "Removed last item from inventory\n";
|
||||
PrintInventory();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDLK_p: // Вывести текущий инвентарь по нажатию P
|
||||
std::cout << "\nCurrent inventory contents:\n";
|
||||
PrintInventory();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user