Minerva/8 Posted July 7, 2018 Share Posted July 7, 2018 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 :)! Quote Link to comment Share on other sites More sharing options...
Antriel Posted July 8, 2018 Share Posted July 8, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.