Git Product home page Git Product logo

compynent's Introduction

ComPyNent

Entity-Component-System (ECS) framework for Python 3+. It aims to be flexible, performant and easy to use and learn, with a specific emphasis on game development. There is currently an example of how to integrate it with the Panda3D game engine in the examples folder, although it can also be used in conjunction with other frameworks such as Pygame or Pyglet.

How to use

This is a one-file library: just add compynent.py to your project, and import it with import compynent.

Overview

For an explanation of how ECS works and what the motivation for it is, read this article. The implementation in ComPyNent uses the approach by which entities are simply integers that refer to a list of the components attached to them.

The main class is the EntityManager class. Normally, you only need to instantiate it once.

  • To create an entity, use the create_entity method of EntityManager. It optionally accepts inital components as parameters
  • Components are simply objects with data as its members
  • A system can be a function or method that is added via the add_system method of EntityManager, and it is called each time that the do_frame method of that instance of EntityManager is called. add_system has an order parameter, which is an integer that specifies the order that systems should be run in, with systems with lower order values being run first.

Example:

import compynent

ecs = compynent.EntityManager()

class MessageComponent:
    def __init__(self, message):
        self.message = message

entity = ecs.create_entity()
component = MessageComponent()
ecs.add_component(entity, component)

class MessageSystem():
    def update(self):
        for entity in ecs.get_entities():
            if entity.has_component(MessageComponent):
                print(ecs.get_component(entity, MessageComponent).message)
            
ecs.add_system(MessageSystem())

while True:
    ecs.do_frame()

Note: adding more than one component of the same type to a single entity will cause unexpected results.

Contributing

See CONTRIBUTING.md.

License

The Unlicense

compynent's People

Contributors

typewriter1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

compynent's Issues

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.