Started to set things up so that the boss fight UI can load enemies and configs out of the components setup.

master
Zed A. Shaw 1 week ago
parent 033358749f
commit b3b8cbbeee
  1. 2
      assets/enemies.json
  2. 5
      boss_fight_ui.cpp
  3. 1
      boss_fight_ui.hpp
  4. 8
      components.cpp
  5. 13
      components.hpp

@ -78,7 +78,7 @@
{"_type": "EnemyConfig", "hearing_distance": 3},
{"_type": "Animation", "easing": 2, "ease_rate": 0.2, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0},
{"_type": "Sprite", "name": "rat_king"},
{"_type": "Sound", "attack": "Medium_Rat", "death": "Creature_Death_1"}
{"_type": "Sound", "attack": "Sword_Hit_2", "death": "Creature_Death_1"}
]
},
"SPIDER_GIANT_HAIRY": {

@ -32,6 +32,9 @@ namespace gui {
}
void BossFightUI::init() {
auto& config = $level.world->get_the<components::GameConfig>();
$sounds = components::get<components::Sound>(config.enemies["RAT_KING"]);
$status.world().set_the<Background>({$status.$parser});
for(auto& [name, cell] : $status.cells()) {
@ -65,7 +68,7 @@ namespace gui {
$boss_image.sprite->setScale({scale, scale});
if(scale > 1.0) {
if(!sound::playing("Sword_Hit_2")) sound::play("Sword_Hit_2");
if(!sound::playing($sounds.attack)) sound::play($sounds.attack);
$boss_image.sprite->setColor({255,255,255});
}

@ -21,6 +21,7 @@ namespace gui {
sf::Clock $clock;
int $boss_hp = 10;
bool $boss_hit = false;
components::Sound $sounds;
GameLevel $level;
guecs::UI $status;
guecs::UI $overlay;

@ -3,14 +3,6 @@
#include "easings.hpp"
namespace components {
ENROLL_COMPONENT(Position, location.x, location.y);
ENROLL_COMPONENT(EnemyConfig, hearing_distance);
ENROLL_COMPONENT(Motion, dx, dy, random);
ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead);
ENROLL_COMPONENT(Device, config, events);
ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate);
ENROLL_COMPONENT(Sound, attack, death);
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
for (auto &i : data) {
dbc::check(i.contains("_type") && i["_type"].is_string(), fmt::format("component has no _type: {}", data.dump()));

@ -116,14 +116,19 @@ namespace components {
template <typename T> struct NameOf;
// these need to be here if you're using components::convert outside of components.cpp
ENROLL_COMPONENT(Tile, display, foreground, background);
ENROLL_COMPONENT(Sprite, name);
ENROLL_COMPONENT(Curative, hp);
ENROLL_COMPONENT(LightSource, strength, radius);
ENROLL_COMPONENT(Weapon, damage);
ENROLL_COMPONENT(Loot, amount);
ENROLL_COMPONENT(Position, location.x, location.y);
ENROLL_COMPONENT(EnemyConfig, hearing_distance);
ENROLL_COMPONENT(Motion, dx, dy, random);
ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead);
ENROLL_COMPONENT(Device, config, events);
ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate);
ENROLL_COMPONENT(Sound, attack, death);
using ReflFuncSignature = std::function<void(DinkyECS::World& world, DinkyECS::Entity ent, nlohmann::json &j)>;
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
@ -140,9 +145,7 @@ namespace components {
template<typename COMPONENT> COMPONENT get(nlohmann::json &data) {
for (auto &i : data["components"]) {
if(i["_type"] == NameOf<COMPONENT>::name) {
COMPONENT result;
from_json(i, result);
return result;
return convert<COMPONENT>(i);
}
}

Loading…
Cancel
Save