Me and a team of junior developers are making a role playing game. We would like to make something similar to https://bunk.town/ I have only made a Tetris clone which doesn't require much knowledge about game architecture; however, this game will. Is an ECS architecture a good fit for this kind of game? If so how should i go about implementing it in python?

I know that one of the major drawbacks when making an ECS with python is the inability to utilize the cache. There is the advantage of being able to compose entities easily and archetypes may help iteration speeds.

I'm working with people relatively new to game programming. They lack experience and im not sure if i should make something like an ecs yet.

I tried putting something together but I'm partly unsatisfied with how it turned out. Its not finished, but i can loop over a specific group of components in an archetype. Id appreciate any guidance as Ive struggled with this in the past. Here is the source code.

class Component:

class Archetable:
    def __init__(self):
        self.entities = []
        self.type = set()

    def __iter__(self):
        for entity in self.entities:
            yield entity

    def over_components(self, *Components):
        for components in self.entities:
            entity = []
            for component in components:
                if type(component) not in Components:
                index = Components.index(type(component))
                entity.insert(index, component)

            yield entity

class Camera(Component):
    def __init__(self):
        self.id = 0

class Controller(Component):
    def __str__(self):
        return self.__class__.__name__

arche = Archetable()

for controller, in arche.over_components(Controller):
  • \$\begingroup\$ "There is the advantage of being able to compose entities easily" This is, IMHO, a very interesting advantage of using an ECS. "but I'm partly unsatisfied with how it turned out." Why? What kind of improvement are you seeking? \$\endgroup\$
    – Vaillancourt
    Sep 18, 2021 at 3:33
  • \$\begingroup\$ @Vaillancourt I dont know how to make ids that remain valid after entities are deleted and added. I could just have references to a list of components instead of an id, but most ecs use ids as a means of retrieving and modifying entities. \$\endgroup\$ Sep 18, 2021 at 3:37
  • 2
    \$\begingroup\$ Try editing your question to ask about that specifically. \$\endgroup\$
    – DMGregory
    Sep 18, 2021 at 12:13
  • \$\begingroup\$ Thanks I'll edit soon. \$\endgroup\$ Sep 19, 2021 at 7:34


You must log in to answer this question.

Browse other questions tagged .