~leinnan/raylibGame unlisted

129565961ee6c48c177dcb847a3d7f1bcbb22dea — Leinnan 1 year, 3 months ago 78f7658
Objects are taking damage
4 files changed, 22 insertions(+), 1 deletions(-)

M data/test.json
M src/systems/DamageSystem.cpp
M src/utils/JsonParser.cpp
M src/utils/JsonParser.hpp
M data/test.json => data/test.json +3 -0
@@ 97,6 97,9 @@
            "type": "Transform"
        },
        {
            "type": "Destroyable"
        },
        {
            "collisions": [
                {
                    "offsetX": 0.0,

M src/systems/DamageSystem.cpp => src/systems/DamageSystem.cpp +3 -0
@@ 8,6 8,7 @@
#include "components/Transform.hpp"

#include "raylib.h"
#include <iostream>

namespace Systems {
void DamageSystem::Update(entt::registry<> &registry, const float delta) {


@@ 74,6 75,8 @@ void DamageSystem::Update(entt::registry<> &registry, const float delta) {
            }

            destroyable.currentLife -= damageTaken;
            if(damageTaken > 0)
                std::cout << "Damage points! Even " << damageTaken << " of them, there is only " << destroyable.currentLife << " left!\n";
        });
}
} // namespace Systems

M src/utils/JsonParser.cpp => src/utils/JsonParser.cpp +12 -1
@@ 44,10 44,14 @@ void Components::to_json(json &j, const Components::Velocity &t) { j = json{{"ty

void Components::from_json(const json &j, Components::Velocity &t) {}

void Components::to_json(json &j, const Components::Fighter &t) { j = json{{"type", "Velocity"}}; }
void Components::to_json(json &j, const Components::Fighter &t) { j = json{{"type", "Fighter"}}; }

void Components::from_json(const json &j, Components::Fighter &t) {}

void Components::to_json(json &j, const Components::Destroyable &t) { j = json{{"type", "Destroyable"}}; }

void Components::from_json(const json &j, Components::Destroyable &t) {}

void Components::to_json(json &j, const Components::Actor &t) {
    j = json{{"type", "Actor"}, {"name", t.name}, {"speed", t.speed}};
}


@@ 207,6 211,11 @@ void Components::parseToFile(entt::registry<> &registry, const char *filename) {
            Components::to_json(component, registry.get<Components::Fighter>(entity));
            entityObject.push_back(component);
        }
        if(registry.has<Components::Destroyable>(entity)) {
            json component;
            Components::to_json(component, registry.get<Components::Destroyable>(entity));
            entityObject.push_back(component);
        }
        jsonReader.push_back(entityObject);
    });



@@ 261,6 270,8 @@ void Components::readFromFile(entt::registry<> &registry, const char *filename) 
                registry.assign<Components::WorldScreenText>(entity, component.get<Components::WorldScreenText>());
            } else if(type.compare("Fighter") == 0) {
                registry.assign<Components::Fighter>(entity, component.get<Components::Fighter>());
            } else if(type.compare("Destroyable") == 0) {
                registry.assign<Components::Destroyable>(entity, component.get<Components::Destroyable>());
            }
        }
    }

M src/utils/JsonParser.hpp => src/utils/JsonParser.hpp +4 -0
@@ 6,6 6,7 @@
#include "components/Collisions.hpp"
#include "components/CylinderRenderer.hpp"
#include "components/DestroyAfterTime.hpp"
#include "components/Destroyable.hpp"
#include "components/Fighter.hpp"
#include "components/MeshRenderer.hpp"
#include "components/Missile.hpp"


@@ 63,6 64,9 @@ void from_json(const json &j, Components::WorldScreenText &t);
void to_json(json &j, const Components::Fighter &t);
void from_json(const json &j, Components::Fighter &t);

void to_json(json &j, const Components::Destroyable &t);
void from_json(const json &j, Components::Destroyable &t);

void parseToFile(entt::registry<> &registry, const char *filename);
void readFromFile(entt::registry<> &registry, const char *filename);
}; // namespace Components