diff --git a/assets/enemies.json b/assets/enemies.json index 2633ab4..96f7eee 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -2,36 +2,42 @@ "PLAYER_TILE": { "foreground": [255, 200, 125], "background": [30, 20, 75], - "hp": 100, - "damage": 10, - "display":"\ua66b" + "components": [ + {"type": "Tile", "config": {"chr": "\ua66b"}}, + {"type": "Combat", "config": {"hp": 200, "damage": 15}} + ] }, "SNAKE": { "foreground": [90, 172, 74], "background": [30, 20, 75], - "hp": 15, - "damage": 5, - "display":"\u06b1" + "components": [ + {"type": "Tile", "config": {"chr": "\u06b1"}}, + {"type": "Combat", "config": {"hp": 20, "damage": 15}} + ] }, "GOBLIN": { "foreground": [50, 200, 125], "background": [30, 20, 75], - "hp": 75, - "damage": 30, - "display":"\u06bf" + "components": [ + {"type": "LightSource", "config": {"strength": 70, "radius": 1.8}}, + {"type": "Tile", "config": {"chr": "\u06bf"}}, + {"type": "Combat", "config": {"hp": 50, "damage": 35}} + ] }, "UNICORN": { "foreground": [25, 200, 125], "background": [30, 20, 75], - "hp": 50, - "damage": 20, - "display":"\u17a5" + "components": [ + {"type": "Tile", "config": {"chr": "\u17a5"}}, + {"type": "Combat", "config": {"hp": 2000, "damage": 5}} + ] }, "RAT": { "foreground": [75, 200, 125], "background": [30, 20, 75], - "hp": 5, - "damage": 1, - "display":"\u08ac" + "components": [ + {"type": "Tile", "config": {"chr": "\u08ac"}}, + {"type": "Combat", "config": {"hp": 10, "damage": 5}} + ] } } diff --git a/assets/items.json b/assets/items.json index f8b675f..8de5bc5 100644 --- a/assets/items.json +++ b/assets/items.json @@ -5,8 +5,12 @@ "foreground": [24, 205, 189], "background": [230, 20, 120], "description": "A torch that barely lights the way. You wonder if it'd be better to not see the person who murders you.", - "type": "LIGHT", - "display": "\u0f08" + "inventory_count": 1, + "components": [ + {"type": "LightSource", "config": {"strength": 70, "radius": 2.0}}, + {"type": "Tile", "config": {"chr": "\u0f08"}}, + {"type": "Weapon", "config": {"damage": 35}} + ] }, "SWORD_RUSTY": { "id": "SWORD_RUSTY", @@ -14,8 +18,24 @@ "foreground": [24, 205, 189], "background": [24, 205, 189], "description": "A sword left to rot in a deep hole where it acquired a patina of dirt and tetanus. You aren't sure if it's more deadly for you to hold it or for the people you stab with it.", - "type": "WEAPON", - "display":"\u1e37" + "inventory_count": 1, + "components": [ + {"type": "Weapon", "config": {"damage": 15}}, + {"type": "Tile", "config": {"chr": "\u1e37"}} + ] + }, + "SWORD_LIGHT_AND_FLAME": { + "id": "SWORD_LIGHT_AND_FLAME", + "name": "Sword of Light and Flame", + "foreground": [24, 205, 189], + "background": [24, 205, 189], + "description": "A sword so powerful, a great man from the Land of The Rising Sun thrust it into the ocean of Nerf to chill its effects.", + "inventory_count": 1, + "components": [ + {"type": "LightSource", "config": {"strength": 70, "radius": 1.8}}, + {"type": "Tile", "config": {"chr": "\u0236"}}, + {"type": "Weapon", "config": {"damage": 30}} + ] }, "CHEST_SMALL": { "id": "CHEST_SMALL", @@ -23,8 +43,11 @@ "foreground": [24, 205, 189], "background": [24, 205, 189], "description": "A small chest of gold. You wonder who would leave something like this around.", - "type": "LOOT", - "display":"\uaaea" + "components": [ + {"type": "Tile", "config": {"chr": "\uaaea"}}, + {"type": "Loot", "config": {"amount": 10}} + ], + "inventory_count": 1 }, "WALL_TORCH": { "id": "WALL_TORCH", @@ -32,7 +55,11 @@ "foreground": [24, 205, 189], "background": [24, 205, 189], "description": "A torch on a wall you can't pick up.", - "type": "FIXED_LIGHT", + "inventory_count": 0, + "components": [ + {"type": "Tile", "config": {"chr": "\u06bf"}}, + {"type": "LightSource", "config": {"strength": 60, "radius": 1.8}} + ], "display": "☀" } } diff --git a/dbc.cpp b/dbc.cpp index c25d32a..515a644 100644 --- a/dbc.cpp +++ b/dbc.cpp @@ -1,4 +1,5 @@ #include "dbc.hpp" +#include void dbc::log(const string &message) { fmt::print("{}\n", message); diff --git a/status.txt b/status.txt index da160f1..bcfad12 100644 --- a/status.txt +++ b/status.txt @@ -1,6 +1,5 @@ TODAY'S GOAL: -* I don't handle death at all. It crashes when I die. * https://pkl-lang.org/ * Check out https://github.com/stephenberry/glaze * Things are still in walls because I +1 the x,y if they're colliding. diff --git a/systems.cpp b/systems.cpp index 803d2c8..d9afc5a 100644 --- a/systems.cpp +++ b/systems.cpp @@ -148,12 +148,16 @@ void System::collision(DinkyECS::World &world, Player &player) { world.set(player.entity, new_light); inventory.light = new_light; world.remove(entity); - } else if(world.has(entity)) { + } + + if(world.has(entity)) { inventory.add(item); auto &weapon = world.get(entity); player_combat.damage = weapon.damage; world.remove(entity); - } else if(world.has(entity)) { + } + + if(world.has(entity)) { auto &loot = world.get(entity); inventory.gold += loot.amount; world.remove(entity); diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 85eb40e..d6a0bc8 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -168,30 +168,43 @@ void WorldBuilder::generate_map() { } } +void configure_components(DinkyECS::World &world, DinkyECS::Entity entity, json& entity_data) { + for(auto &comp : entity_data["components"]) { + json& config = comp["config"]; + + if(comp["type"] == "Weapon") { + world.set(entity, {config["damage"]}); + } else if(comp["type"] == "LightSource") { + world.set(entity, {config["strength"], config["radius"]}); + } else if(comp["type"] == "Loot") { + world.set(entity, {config["amount"]}); + } else if(comp["type"] == "Tile") { + world.set(entity, {config["chr"]}); + } else if(comp["type"] == "EnemyConfig") { + world.set(entity, {config["hearing_distance"]}); + } else if(comp["type"] == "Combat") { + world.set(entity, {config["hp"], config["damage"]}); + } else { + dbc::sentinel(format("ITEM COMPONENT TYPE MISSING: {}", + std::string(comp["type"]))); + } + } +} + DinkyECS::Entity place_item(DinkyECS::World &world, Map &game_map, std::string name, int in_room) { auto &config = world.get_the(); auto item = world.entity(); auto pos = game_map.place_entity(in_room); json item_data = config.items[name]; - world.set(item, {pos.x+1, pos.y+1}); - world.set(item, {item_data["display"]}); - - if(item_data["type"] == "WEAPON") { - world.set(item, {1, item_data}); - world.set(item, {20}); - } else if(item_data["type"] == "LIGHT") { - world.set(item, {1, item_data}); - world.set(item, {70,2.0f}); - } else if(item_data["type"] == "LOOT") { - world.set(item, {1, item_data}); - world.set(item, {100}); - } else if(item_data["type"] == "FIXED_LIGHT") { - world.set(item, {90,3.0f}); - } else { - dbc::sentinel(format("ITEM MISSING TYPE: {}", name)); + + if(item_data["inventory_count"] > 0) { + world.set(item, {item_data["inventory_count"], item_data}); } + if(item_data.contains("components")) { + configure_components(world, item, item_data); + } return item; } @@ -202,8 +215,10 @@ DinkyECS::Entity place_combatant(DinkyECS::World &world, Map &game_map, std::str auto enemy_data = config.enemies[name]; world.set(enemy, {game_map.place_entity(in_room)}); world.set(enemy, {0,0}); - world.set(enemy, {enemy_data["display"]}); - world.set(enemy, {enemy_data["hp"], enemy_data["damage"]}); + + if(enemy_data.contains("components")) { + configure_components(world, enemy, enemy_data); + } return enemy; }