Giter Site home page Giter Site logo

demiurge's Introduction

Demiurge Engine 0.4.7

Simple constructor for 2D games Guide for using.
Demiurge - it's Entity-Component-System (ECS) based constructor.

Entity and EntityManager

Based unit of all game objects. Every entity has a list of unique identifiers components. You can't create entity without EntityManager, because constructor (ctor) and destructor (dtor) - has private access modifier.
EntityManager - it's class, which can create, delete, etc. entity.

auto Wall = EntityManager::Create<EObject>("Wall0")); //quotes may be empty
addObEect(Wall->getId());
Wall->DoesSomeMethod();

This code created a new game object - wall with name "Wall0". Create - is a static method of class EntityManager, which created new object by class name, added to vector and returned him. If your class wants to be created in this method, you must registered your class like this:

EntityManager::Register<YouClass>();

When YouClass inherited from EObject or IEntity with ERegisterable< YouClass > Every entity has a unique identifier. Id has generated on constructor call.
You can destroy any object by id:

EntityManager::Destroy(Wall->getId());

This method released all components which linked with him.

Component and ComponentManager

Based thing for interaction entity with entity. Every component has a unique id and id of entity to which his attached. Like Entity objects, component may created only on ComponentManager:

Wall->body = ComponentManager::Create(Wall->getId(), "body")); //quotes may be empty
//or
ComponentManager::Create<CDrawable>(Wall->getId());

In Create-method ComponentManager find entity by id and attach id of component to him. If entity not found, returned nullptr.

Level-based system

Every entity may have drawable components. For draw you must call draw-method. This method definition in every level. Life-cycle every level:

  1. Register level in LevelManager
  2. Load level
    2.1 Init ImageDirectory
    2.2 Init camera
  3. Main loop (every frame)
    3.1 Handle event callbacks
    3.2 Draw

How you can create level? It's easy: create class and inherit from abstract class Level.

class LTest : public Level
{
public:
    LTest(const std::string &name);
    virtual ~LTest() {}
    virtual bool prepareLevel(sf::RenderWindow &window) override;
    virtual void draw(sf::RenderWindow &window) override;
    virtual void MouseCallbacks(sf::RenderWindow &window, sf::Event &event) override;
    virtual void KeyBoardCallbacks(sf::RenderWindow &window, sf::Event &event) override;
};

You can stay ctor empty, like this:

LTest::LTest(const std::string &name) : Level(name)
{
}

But you must know, in ctor of Level-class init base fields:

- Id - unique integer identifier. Generated automatically (Level::getNextId());
- Name - set from ctor parameter;
- ImageDirectory - empty by default. Path for folder with images;
- ImagesFromats - vector, which contained file formats when searched. By default added .png and .jpg formats;
- backgroundColor - color for background. By default is sf::Color::Black;
- UserInterface - wrapper for work with UI. Just init;

And register classes for EntityManager and ComponentManager:

EntityManager::Register<EObject>();
ComponentManager::Register<CDrawable>();
ComponentManager::Register<CTransform>();

If you want register you class, ctor of you level-class - best idea.
prepareLevel - method for prepared you components and objects in level

Registered level

auto ltest = std::make_shared<LTest>("test-level");
levelManager->registerLevel(ltest);

Load level

CurrentLevel = levelManager->loadLevel("test-level");

Init ImageDirectory

CurrentLevel->ImageDirectory = this->ImageDirectory;

Init Camera

CurrentLevel->setCamera(MainCamera);

Handle event callbacks

CurrentLevel->MouseCallbacks(window, event);
CurrentLevel->KeyBoardCallbacks(window, event);
CurrentLevel->HandleGUIEvent(event);

Draw level

CurrentLevel->draw(window);

demiurge's People

Contributors

ludwici avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.