removing object from map after adding to inventory
This commit is contained in:
parent
eb0bae44aa
commit
1e3be66495
@ -121,12 +121,15 @@ 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) {
|
||||||
for (auto& ao : activeObjects) {
|
for (size_t i = 0; i < activeObjects.size(); ++i) {
|
||||||
if (ao.highlighted){
|
auto& ao = activeObjects[i];
|
||||||
AddItemToInventory(ao.name, ao.activeObjectTexturePtr);
|
if (ao.highlighted) {
|
||||||
PrintInventory();
|
AddItemToInventory(ao.name, ao.activeObjectTexturePtr);
|
||||||
}
|
activeObjects.erase(activeObjects.begin() + i);
|
||||||
|
// Можно выйти из цикла, если объект удален, чтобы избежать ошибок индексации.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// bx.Interpolate(animationCounter);
|
// bx.Interpolate(animationCounter);
|
||||||
// animationCounter += 2;
|
// animationCounter += 2;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,15 +32,6 @@ 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,9 +24,6 @@ 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();
|
||||||
|
|
||||||
|
|||||||
@ -94,6 +94,7 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
|||||||
// Draw highlighted objects UI
|
// Draw highlighted objects UI
|
||||||
for (const auto& ao : gameObjects.activeObjects) {
|
for (const auto& ao : gameObjects.activeObjects) {
|
||||||
if (ao.highlighted) {
|
if (ao.highlighted) {
|
||||||
|
if (ao.activeObjectScreenTexturePtr){
|
||||||
int screenX, screenY;
|
int screenX, screenY;
|
||||||
worldToScreenCoordinates(ao.objectPos, currentProjectionModelView,
|
worldToScreenCoordinates(ao.objectPos, currentProjectionModelView,
|
||||||
Environment::width, Environment::height, screenX, screenY);
|
Environment::width, Environment::height, screenX, screenY);
|
||||||
@ -102,6 +103,7 @@ void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
|||||||
glBindTexture(GL_TEXTURE_2D, ao.activeObjectScreenTexturePtr->getTexID());
|
glBindTexture(GL_TEXTURE_2D, ao.activeObjectScreenTexturePtr->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(ao.activeObjectScreenMeshMutable);
|
renderer.DrawVertexRenderStruct(ao.activeObjectScreenMeshMutable);
|
||||||
renderer.PopMatrix();
|
renderer.PopMatrix();
|
||||||
|
} else {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user