~leinnan/raylibGame unlisted

f774e62c4c9fa3e158c5db7b6b618f86e4a9a91d — Leinnan 1 year, 3 months ago 708edb9
Create RectangleVeil
M data/test.json => data/test.json +5 -0
@@ 1,6 1,11 @@
[
    [
        {
            "type": "RectangleVeil"
        }
    ],
    [
        {
            "idToSpawn": "player",
            "type": "SpawnPoint"
        },

A src/components/RectangleVeil.hpp => src/components/RectangleVeil.hpp +20 -0
@@ 0,0 1,20 @@
#ifndef RECTANGLE_VEIL_HPP
#define RECTANGLE_VEIL_HPP
#include "raylib.h"

namespace Components {

struct RectangleVeil final {
    int rectanglesInX = 20;
    float frameDelay = 0.1f;
    float rectAnimDuration = 0.3f;
    float elapsed = 0.0f;
    
    int getRectangleSize() const { return (GetScreenWidth() / rectanglesInX); }
    int getRectangleInY() const { return (GetScreenHeight() / getRectangleSize() + 1); }
    float getAnimationDuration() const { return frameDelay * (getRectangleInY() - 1) + rectAnimDuration; };
};
} // namespace Components
  // Components

#endif

M src/systems/RenderSystem.cpp => src/systems/RenderSystem.cpp +16 -0
@@ 7,6 7,7 @@
#include "components/DamageBox.hpp"
#include "components/MeshRenderer.hpp"
#include "components/PlayerInput.hpp"
#include "components/RectangleVeil.hpp"
#include "components/Transform.hpp"
#include "components/WorldScreenText.hpp"
#include <cmath>


@@ 61,6 62,21 @@ void RenderSystem::Update(entt::registry<> &registry, Camera &camera) {
                     screenText.fontSize, GOLD);
        });
    DrawText("Debug build", 10, 10, 10, CLITERAL{230, 102, 1, 255});
    registry.view<Components::RectangleVeil>().each(
        [&](const auto, Components::RectangleVeil &rectVeil) {
            rectVeil.elapsed += GetFrameTime();// TODO- move outside render system to UI system
            for(int i = 0; i < rectVeil.rectanglesInX;++i)
            {
                for(int j = 0;j < rectVeil.getRectangleInY();++j)
                {
                    const float startFrame = rectVeil.frameDelay * j;
                    const float endFrame = startFrame + rectVeil.rectAnimDuration;
                    const float sizeModifier = rectVeil.elapsed < startFrame ? 1.0f : (rectVeil.elapsed > endFrame ? 0.0f : 1.0f - ((rectVeil.elapsed - startFrame) / rectVeil.rectAnimDuration));
                    const float offset = (rectVeil.getRectangleSize() / 2.0f * (1.0f - sizeModifier));
                    DrawRectangle(i * rectVeil.getRectangleSize() + offset, j * rectVeil.getRectangleSize() + offset,rectVeil.getRectangleSize() * sizeModifier, rectVeil.getRectangleSize() * sizeModifier, BLACK);
                }
            }
        });
    EndDrawing();
}


M src/utils/JsonParser.cpp => src/utils/JsonParser.cpp +23 -0
@@ 245,6 245,11 @@ void Components::parseToFile(entt::registry<> &registry, const char *filename) {
            Components::to_json(component, registry.get<Components::SpawnPoint>(entity));
            entityObject.push_back(component);
        }
        if(registry.has<Components::RectangleVeil>(entity)) {
            json component;
            Components::to_json(component, registry.get<Components::RectangleVeil>(entity));
            entityObject.push_back(component);
        }
        jsonReader.push_back(entityObject);
    });



@@ 307,6 312,8 @@ uint32_t Components::createEntityFromJson(entt::registry<> &registry, json &obje
            registry.assign<Components::Destroyable>(entity, component.get<Components::Destroyable>());
        } else if(type.compare("SpawnPoint") == 0) {
            registry.assign<Components::SpawnPoint>(entity, component.get<Components::SpawnPoint>());
        } else if(type.compare("RectangleVeil") == 0) {
            registry.assign<Components::RectangleVeil>(entity, component.get<Components::RectangleVeil>());
        }
    }
    return entity;


@@ 315,3 322,19 @@ uint32_t Components::createEntityFromJson(entt::registry<> &registry, json &obje
uint32_t Components::createEntityFromJson(entt::registry<> &registry, const std::string &s) {
    return createEntityFromJson(registry, json::parse(s));
}

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

void Components::from_json(const nlohmann::json &j, Components::RectangleVeil &t)
{
    t.elapsed = 0.0f;
    if(j.find("frameDelay") != j.end())
        t.frameDelay = j.at("frameDelay").get<float>();
    if(j.find("rectanglesInX") != j.end())
        t.rectanglesInX = j.at("rectanglesInX").get<int>();
    if(j.find("rectAnimDuration") != j.end())
        t.rectAnimDuration = j.at("rectAnimDuration").get<float>();
}

M src/utils/JsonParser.hpp => src/utils/JsonParser.hpp +4 -0
@@ 12,6 12,7 @@
#include "components/Missile.hpp"
#include "components/Patrol.hpp"
#include "components/PlayerInput.hpp"
#include "components/RectangleVeil.hpp"
#include "components/RotatingObject.hpp"
#include "components/SpawnPoint.hpp"
#include "components/Transform.hpp"


@@ 71,6 72,9 @@ void from_json(const json &j, Components::Destroyable &t);
void to_json(json &j, const Components::SpawnPoint &t);
void from_json(const json &j, Components::SpawnPoint &t);

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

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