benmoran56 / esper

An ECS (Entity Component System) for Python
MIT License
537 stars 67 forks source link

Testing esper #76

Closed bignuts closed 1 year ago

bignuts commented 1 year ago

Hi Ben,

really pleased to use this simple python module, it’s concise and do the job. It’s my first time trying ecs, so I wanted a quick suggestion on how to proceed, basically I’m trying to recreate for testing purpose Marvel Snap card game. At the moment I understand exactly what entity and component are, little confused on how I should use systems in game like this, does every card needs its own system? Since each card have unique ability mostly. Thanks in advance.

Daniele

benmoran56 commented 1 year ago

Hi Daniele, Thanks for your interest in esper. It's a bit hard to say as I haven't made this type of game, but it might help to think about one Processor (system) for each stage in the game. For a shooting game for instance:

InputProcessor
MovementProcessor
CollisionProcessor
WeaponProcessor
EffectProcessor
Etc.

Some of these processors will be fairly specific and deal with only one or two Component types, but other Processors might deal with multiple Components in one place for convenience. For example, the EffectProcessor could deal with multiple types of temporary visual effects. There could be multiple Processors for these effects, but you can also stick them together if it makes sense:

class EffectProcessor(esper.Processor):

    def process(self, dt):
        for ent, (rend, flash) in self.world.get_components(Renderable, Flash):
            ...

        for ent, (rend, blink) in self.world.get_components(Renderable, Blink):
            ...

Does that make sense?

bignuts commented 1 year ago

That’s a nice suggestion, I was not thinking about it. Still I think ecs is not well suited for a card game like this. Let me explain, 80% of the card have OnReveal effect (OnRevealComponent), that happen as soon as the card is revealed and OnGoing effect (OnGoingComponent) that persist through the game. But since every card has different effect, like adding power, discard a card, draw, add mana and so on, I can’t really use single OnRevealProcessor / OnGoingProcessor without using plenty of if statement.

benmoran56 commented 1 year ago

You could be right, if the individual game objects are all extremely unique. ECS isn't a good fit for every game type. It might be worth while to build a very simple example game (like an asteroids clone), just to get a feeling for it. It's then easier to understand what works well, and what doesn't. There are also lots of roguelikes out there that use ECS design, so that type of tutorial might be interesting as well.

With regards to your comment on if statements, that can become a mess. Sometimes, it makes more sense to add another Component as a way of "tagging" an Entity. I think it all depends on just how many if statements you end up with. For my CollisionProcessor, for instance, I only have about 4 types of objects. In that case, four if statements makes sense.

bignuts commented 1 year ago

Yeah I’ll probably build something simpler to test ecs out! Thank you for your time