adding inventory
This commit is contained in:
parent
a4aea4163a
commit
eb0bae44aa
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
struct ActiveObject {
|
struct ActiveObject {
|
||||||
|
std::string name;
|
||||||
std::shared_ptr<ZL::Texture> activeObjectTexturePtr;
|
std::shared_ptr<ZL::Texture> activeObjectTexturePtr;
|
||||||
ZL::VertexDataStruct activeObjectMesh;
|
ZL::VertexDataStruct activeObjectMesh;
|
||||||
ZL::VertexRenderStruct activeObjectMeshMutable;
|
ZL::VertexRenderStruct activeObjectMeshMutable;
|
||||||
|
|||||||
@ -52,6 +52,7 @@ void GameObjectManager::initialize() {
|
|||||||
|
|
||||||
// Create active object
|
// Create active object
|
||||||
ActiveObject ao1;
|
ActiveObject ao1;
|
||||||
|
ao1.name = "book";
|
||||||
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
|
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
|
||||||
ao1.activeObjectMesh.Scale(4);
|
ao1.activeObjectMesh.Scale(4);
|
||||||
ao1.activeObjectMeshMutable.AssignFrom(ao1.activeObjectMesh);
|
ao1.activeObjectMeshMutable.AssignFrom(ao1.activeObjectMesh);
|
||||||
@ -91,13 +92,6 @@ void GameObjectManager::initialize() {
|
|||||||
inventoryIconMeshMutable.AssignFrom(inventoryIconMesh);
|
inventoryIconMeshMutable.AssignFrom(inventoryIconMesh);
|
||||||
inventoryIconMeshMutable.RefreshVBO();
|
inventoryIconMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
|
|
||||||
// Add test items to inventory
|
|
||||||
auto testRoomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
|
|
||||||
auto testConeTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
|
|
||||||
AddItemToInventory("RoomCeramics", testRoomTexture);
|
|
||||||
AddItemToInventory("Cone", testConeTexture);
|
|
||||||
|
|
||||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +121,14 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
switch_room(1);
|
switch_room(1);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||||
bx.Interpolate(animationCounter);
|
for (auto& ao : activeObjects) {
|
||||||
animationCounter += 2;
|
if (ao.highlighted){
|
||||||
|
AddItemToInventory(ao.name, ao.activeObjectTexturePtr);
|
||||||
|
PrintInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// bx.Interpolate(animationCounter);
|
||||||
|
// animationCounter += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (event.type == SDL_MOUSEWHEEL) {
|
else if (event.type == SDL_MOUSEWHEEL) {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace ZL
|
|||||||
gInventory.push_back({ name, tex });
|
gInventory.push_back({ name, tex });
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveItemFromInventory(const std::string& name)
|
void RemoveItemFromInventory(const std::string name)
|
||||||
{
|
{
|
||||||
gInventory.erase(
|
gInventory.erase(
|
||||||
std::remove_if(gInventory.begin(), gInventory.end(),
|
std::remove_if(gInventory.begin(), gInventory.end(),
|
||||||
@ -32,6 +32,15 @@ namespace ZL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HasObject(const std::string& name){
|
||||||
|
for (const auto& item : gInventory) {
|
||||||
|
if (item.name == name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<InventoryItem>& ReturnInventory()
|
const std::vector<InventoryItem>& ReturnInventory()
|
||||||
{
|
{
|
||||||
return gInventory;
|
return gInventory;
|
||||||
|
|||||||
@ -24,6 +24,9 @@ namespace ZL
|
|||||||
// Удалить предмет из инвентаря
|
// Удалить предмет из инвентаря
|
||||||
void RemoveItemFromInventory(const std::string& name);
|
void RemoveItemFromInventory(const std::string& name);
|
||||||
|
|
||||||
|
// todo check if object exists
|
||||||
|
bool HasObject(const std::string name);
|
||||||
|
|
||||||
// Вывести все предметы в инвентаре
|
// Вывести все предметы в инвентаре
|
||||||
void PrintInventory();
|
void PrintInventory();
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void drawWorld(const GameObjectManager& gameObjects);
|
void drawWorld(const GameObjectManager& gameObjects);
|
||||||
void drawUI(const GameObjectManager& gameObjects);
|
void drawUI(const GameObjectManager& gameObjects);
|
||||||
|
|
||||||
Renderer renderer;
|
Renderer renderer;
|
||||||
ShaderManager shaderManager;
|
ShaderManager shaderManager;
|
||||||
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
Matrix4f currentProjectionModelView; // Добавлено для хранения матрицы между drawWorld и drawUI
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user