From 0e79288afcc2db5f5c0b420d593f4e5bee0fe75c Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 7 Nov 2024 02:06:22 -0500 Subject: [PATCH] More notes on the next things to do. --- components.hpp | 5 +++++ dinkyecs.hpp | 2 -- gui.cpp | 9 +++++++-- main.cpp | 1 + save.cpp | 2 ++ save.hpp | 3 ++- status.txt | 10 +++++++++- systems.cpp | 5 +++++ 8 files changed, 31 insertions(+), 6 deletions(-) diff --git a/components.hpp b/components.hpp index 25e90bf..fdd5b29 100644 --- a/components.hpp +++ b/components.hpp @@ -27,6 +27,11 @@ namespace components { DEFINE_SERIALIZABLE(Loot, amount); }; + struct Inventory { + int gold; + DEFINE_SERIALIZABLE(Inventory, gold); + }; + struct Tile { std::string chr; DEFINE_SERIALIZABLE(Tile, chr); diff --git a/dinkyecs.hpp b/dinkyecs.hpp index a79ceb4..9d1a7a9 100644 --- a/dinkyecs.hpp +++ b/dinkyecs.hpp @@ -124,6 +124,4 @@ namespace DinkyECS { return !queue.empty(); } }; - - } diff --git a/gui.cpp b/gui.cpp index 2d1c91a..69775e3 100644 --- a/gui.cpp +++ b/gui.cpp @@ -73,18 +73,21 @@ void GUI::create_renderer() { $document = Renderer([&, player]{ const auto& player_combat = $world.get(player.entity); + const auto& inventory = $world.get(player.entity); $status_text = player_combat.hp > 0 ? "NOT DEAD" : "DEAD!!!!!!"; std::vector log_list; for(auto msg : $log.messages) { log_list.push_back(text(msg)); } + auto log_box = vbox(log_list) | yflex_grow | border; return hbox({ hflow( vbox( - text(format("HP: {: >3}", player_combat.hp)) | border, + text(format("HP: {: >3} GOLD: {: >3}", + player_combat.hp, inventory.gold)) | border, text($status_text) | border, separator(), log_box @@ -126,7 +129,9 @@ void GUI::handle_world_events() { break; case eGUI::LOOT: { auto loot = $world.get(entity); - $log.log(format("You found {} gold.", loot.amount)); + auto inventory = $world.get(player.entity); + $log.log(format("You found {} gold. You have {} now.", + loot.amount, inventory.gold)); } break; default: diff --git a/main.cpp b/main.cpp index 19458d6..785c75d 100644 --- a/main.cpp +++ b/main.cpp @@ -27,6 +27,7 @@ void configure_world(DinkyECS::World &world, Map &game_map) { world.set(player.entity, {0, 0}); world.set(player.entity, {100, 10}); world.set(player.entity, {config.PLAYER_TILE}); + world.set(player.entity, {5}); auto enemy = world.entity(); world.set(enemy, {game_map.place_entity(1)}); diff --git a/save.cpp b/save.cpp index 2d2b06c..135db77 100644 --- a/save.cpp +++ b/save.cpp @@ -27,6 +27,7 @@ void save::to_file(fs::path path, DinkyECS::World &world, Map &map) { extract(world, save_data.combat); extract(world, save_data.motion); extract(world, save_data.tile); + extract(world, save_data.inventory); archive.save(save_data); std::string_view archive_view = archive.get_buffer(); @@ -68,6 +69,7 @@ void save::from_file(fs::path path, DinkyECS::World &world_out, Map &map_out) { inject(world_out, save_data.combat); inject(world_out, save_data.motion); inject(world_out, save_data.tile); + inject(world_out, save_data.inventory); map_out = Map(save_data.map.input_map, save_data.map.walls, save_data.map.limit); diff --git a/save.hpp b/save.hpp index 2b93b22..e73f3d6 100644 --- a/save.hpp +++ b/save.hpp @@ -33,8 +33,9 @@ namespace save { std::map motion; std::map combat; std::map tile; + std::map inventory; - DEFINE_SERIALIZABLE(SaveData, facts, map, position, motion, combat, tile); + DEFINE_SERIALIZABLE(SaveData, facts, map, position, motion, combat, tile, inventory); }; void to_file(fs::path path, DinkyECS::World &world, Map &map); diff --git a/status.txt b/status.txt index 548a90e..71bf0ab 100644 --- a/status.txt +++ b/status.txt @@ -3,10 +3,18 @@ NOTES: TODO: +* Event system could take additional data so that the events can be more coarse and simpler. +* Simplify the combat/collision system so that it's not a bunch of if-cases. +* Inventory needs to be better, but need some kinds of "weapons" or other loot to get and not just gold. +* Run the ansi_parser on the whole UI so I can use colors and other glyphs. +* Create a few more enemy types to fight. +* Devise a more complete map/world generator that can use the loot and enemies better. +* Maybe an LOS system, but the hearing version works pretty well so far. +* Probably a system for mapping collision types to sound effects, rather than having the GUI do it. + * Write a test that generates a ton of maps then confirms there's a path from one room to every other room? * Lua integration? * BUG: If map is < 90 zome out crashes. -* Simple loot system. * Bring back sounds, check out SoLoud. diff --git a/systems.cpp b/systems.cpp index 7239872..e787780 100644 --- a/systems.cpp +++ b/systems.cpp @@ -127,6 +127,11 @@ void System::combat(DinkyECS::World &world, Player &player) { } } else if(world.has(entity)) { world.send(eGUI::LOOT, entity); + auto &loot = world.get(entity); + auto &loot_pos = world.get(entity); + auto &inventory = world.get(player.entity); + inventory.gold += loot.amount; + collider.remove(loot_pos.location); } else { println("UNKNOWN COLLISION TYPE {}", entity); }