Sign in to follow this  

Design Issue [2D Top Down RPG]

Recommended Posts

Hello Internet :),


I need some help for my design issue 😕

At the moment I´m developing a little 2D Top Down RPG (mechanics wise you could compare it to the Pokemon Mystery Dungeon series.)

The game as it is right know was made with the entity component system in mind therefore I have components which act as a data container, entities which represent actual gameobjects (they also have a list with their components) and systems which do the heavy lifting. Now I´m at the point where I need to implement the "turn based and AI" logic and I have no idea how to implement this properly within the ecs.

First I though something like an event queue and a state machine would be appropriate. For example it´s the player turn and he decides to move one cell to the left. The "turn system" checks the current state (player turn) and would poll the player action from the event qeue. After the player action was processed the "turn system" would change state to "enemy turn" and vica versa. Systems like movement or combat would then only look for the needed entities.

I mean its really a loose concept but you should get the idea.

What do you think about this approach especially with the entity component system in mind. Do you have other suggestions to takle the problem?


Thanks for your time :)!

Share this post

Link to post
Share on other sites

ECS is all about being data driven and decoupling logic. Whether the game is turn-based or real-time shouldn't matter too much. In your case you can have an AI system that is triggered only when the entity has its turn. It does its thing and changes the relevant components, which are then used by rendering system to display the action.

Event queues, state machines... are all concepts that can work with ECS. When you think about it ECS is a form of state machine itself (systems are transitions, components the states, entity is basically just a group of components, so a state). You can implement anything on top of that.

What helps me when designing these things is to think about what data represents the basic unit of functionality I want to achieve (i.e. define a component). How that data can change, when, and why (data flow, i.e. systems). What other data might be needed (coupling, i.e. other components a system might need to do its job). When you have a solid image of this, you can usually start with pretty solid design and iterate on it as you realize more things.
Also keep in mind you don't necessary have to run your systems every frame. You can have a system that is only triggered when the enemy executes its turn. In the end all that systems are is a data transformation, a state transition.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.