diff --git a/assets/items.json b/assets/items.json index 19c0e15..a80a419 100644 --- a/assets/items.json +++ b/assets/items.json @@ -59,5 +59,17 @@ {"type": "Tile", "config": {"chr": "\u077e"}}, {"type": "LightSource", "config": {"strength": 60, "radius": 1.8}} ] + }, + "POTION_HEALING_SMALL": { + "id": "POTION_HEALING_SMALL", + "name": "Small Healing Potion", + "foreground": [24, 205, 189], + "background": [24, 205, 189], + "description": "A small healing potion.", + "inventory_count": 1, + "components": [ + {"type": "Tile", "config": {"chr": "\u03eb"}}, + {"type": "Curative", "config": {"hp": 20}} + ] } } diff --git a/components.hpp b/components.hpp index 514eaa2..77ebcac 100644 --- a/components.hpp +++ b/components.hpp @@ -53,6 +53,10 @@ namespace components { int damage = 0; }; + struct Curative { + int hp = 10; + }; + inline void configure(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) { for(auto &comp : entity_data["components"]) { json& config = comp["config"]; @@ -69,6 +73,8 @@ namespace components { world.set(entity, {config["hearing_distance"]}); } else if(comp["type"] == "Combat") { world.set(entity, {config["hp"], config["damage"]}); + } else if(comp["type"] == "Curative") { + world.set(entity, {config["hp"]}); } else if(comp["type"] == "Motion") { world.set(entity, {config["dx"], config["dy"], config["random"]}); } else { diff --git a/systems.cpp b/systems.cpp index 20acb57..a2a7d06 100644 --- a/systems.cpp +++ b/systems.cpp @@ -165,6 +165,12 @@ void System::collision(DinkyECS::World &world, Player &player) { world.remove(entity); } + if(world.has(entity)) { + auto& cure = world.get(entity); + player_combat.hp += cure.hp; + world.remove(entity); + } + collider.remove(item_pos.location); world.remove(entity); world.remove(entity);