Entities factory

Factory to create entities

class Factory {
    public:
        Factory(ECS::Registry &registry);
        ~Factory();
        entity_t createButton(float x, float y, const std::shared_ptr<sf::Texture> &texture, const sf::Vector2f &scale, std::function<void()> callback);
        entity_t createScreen(float x, float y, const std::shared_ptr<sf::Texture> &texture, const sf::Vector2f &scale = {1.0, 1.0});
        entity_t createPlayer(float x, float y, const std::shared_ptr<sf::Texture> &texture);
        entity_t createParallax(float x, float y, const std::shared_ptr<sf::Texture> &texture, float scrollSpeed, const sf::Vector2f &scale, float ratio = 1.0f);
        entity_t createMissile(float x, float y, const std::shared_ptr<sf::Texture> &texture);
        entity_t createEnnemi(float x, float y, const std::shared_ptr<sf::Texture> &texture);
        entity_t createEnnemi4frames(float x, float y, const std::shared_ptr<sf::Texture> &texture, float scale);
        entity_t createBlackband(sf::IntRect rect, const std::shared_ptr<sf::Texture> &texture);

        entity_t createScoreCoche(float x, float y, const std::shared_ptr<sf::Texture> &texture, float scale);

        entity_t createMusic(const std::string &musicPath, float volume = 100.0f, bool loop = false);
        entity_t createStrobe(const std::shared_ptr<sf::Texture> &texture, float x, float y);

        entity_t createText(const std::string &text, const std::shared_ptr<sf::Font> &font, const float &x = 0, const float &y = 0, const size_t &size = 20, const sf::Color &color = sf::Color::White, const sf::Text::Style &style = sf::Text::Style::Regular);
        entity_t createLoadingBar(float x, float y, const std::shared_ptr<sf::Texture> &texture, const std::shared_ptr<sf::Texture> &textureRect, float scale);
        entity_t createSound(const std::string &soundPath, float volume = 100.0f, bool play = false);
        entity_t createBonus(const std::shared_ptr<sf::Texture> &texture, float x, float y, float scale);
        entity_t createMissileAnnimated(float x, float y, const std::shared_ptr<sf::Texture> &texture, float scale);
        entity_t createBomb(const std::shared_ptr<sf::Texture> &texture, float x, float y, float scale);
        entity_t createPod(const std::shared_ptr<sf::Texture> &texture, float scale);
        entity_t createExplosion(const std::shared_ptr<sf::Texture> &texture, float x, float y, float scale);
        entity_t createLaser(const std::shared_ptr<sf::Texture> &texture, float x, float y, float scale);
    private:
        ECS::Registry &_registry;
};

Entities factory is a class where you have to add a method to init an entity that you want in your game.

Firstly, we can see a constructor method where we have to register each component that we want to use for our entities.

Constructor method:

You have to add the component that you want to use (if still not registered).

Method example:

You will use this method to create a player and use it like this ->

To resume, in this method you will add all the components that you want on your entity.

Last updated