diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 01f85e6..ccf6734 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -570,6 +570,10 @@ void Game::Update() { } item->removeMe = true; } + if (item->pickup && Intersect(*item, *(data->human))) { + item->removeMe = true; + globalData.player.item_inventory[item->name]++; + } } } auto& vp = data->gameRegion.placeables; diff --git a/src/saland/GameItems.cpp b/src/saland/GameItems.cpp index cf031d5..92311e6 100644 --- a/src/saland/GameItems.cpp +++ b/src/saland/GameItems.cpp @@ -30,6 +30,7 @@ const ItemDef& getItem(const std::string& itemName) { itemDef.isDestructible = true; itemDef.health = 100.0f; itemDef.itemid = itemName; + itemDef.pickup = false; if (itemName == "barrel") { itemDef.radius = 16.0f; itemDef.sprite = "item_barrel"; @@ -40,6 +41,7 @@ const ItemDef& getItem(const std::string& itemName) { itemDef.radius = 9.0f; itemDef.sprite = "item_food_potato"; itemDef.isStatic = false; + itemDef.pickup = true; } if (itemName == "tree_pine") { itemDef.radius = 20.0f; diff --git a/src/saland/GameItems.hpp b/src/saland/GameItems.hpp index 0e87c1d..a1d87cb 100644 --- a/src/saland/GameItems.hpp +++ b/src/saland/GameItems.hpp @@ -34,6 +34,7 @@ struct ItemDef { bool isStatic = true; bool isDestructible = true; float health = 10.0f; + bool pickup = false; }; const ItemDef& getItem(const std::string& itemName); diff --git a/src/saland/GameRegion.cpp b/src/saland/GameRegion.cpp index c27e4bb..21a35a5 100644 --- a/src/saland/GameRegion.cpp +++ b/src/saland/GameRegion.cpp @@ -95,6 +95,7 @@ void GameRegion::SpawnItem(const ItemDef& def, float destX, float destY) { barrel.get()->destructible = def.isDestructible; barrel.get()->health = def.health; barrel.get()->name = def.itemid; + barrel.get()->pickup = def.pickup; for (int i=(destX-def.radius)/32; i <= (destX+def.radius)/32+1; ++i) { for (int j=(destY-def.radius)/32; j <= (destY+def.radius)/32+1; ++j) { if (world.tile_protected(i, j)) { diff --git a/src/saland/model/placeables.hpp b/src/saland/model/placeables.hpp index c0d4948..744c89f 100644 --- a/src/saland/model/placeables.hpp +++ b/src/saland/model/placeables.hpp @@ -52,6 +52,7 @@ public: std::string id = "unknown"; std::string name = "Unknamed item"; double base_value = 1.0; + bool pickup = false; }; class Creature : public Placeable {