Hello community,
I want to start with programming a 2D RPG soon, and whilst planning the project, there occured some problems. One major problem is that I want a flexible architecture, so I can easily add new things later on. So I want to de-couple the different game parts/objects, for example there should not be any collision code inside the player class. Or another problem I am struggeling with is, how do I let the player interact with all kind of world objects like treasures, traps, NPC´s,... without having alol that code in the player class.
I read a very interesting post about that. There was a event system explained: For example if I the player wants to move he fires an event BeforeMove(Vector2 desiredPos) and the tile map and obstacles react to that event in their own class or so and if they collide with the player they set isPlayerAllowedToMove = false. So the player can´t move that frame. Or for example if I want to implement traps, I could create a event inside the trap class which fires an event, lets say DamagePlayer(int damage) and the player has a way to react to that(by loosing life). Is this a good approach, or do I couple things even more with that(I am not quit sure).
In my last projects I handled Collsion in a collisonManager which had references to the player, and the enemyManager and then I simply checked for collison. I also thought of lettin every object have an event OnCollison, but the problem with that is, that I wouldn´t know which objects collided, so I couldn´t interact differently.
So I hope someone can help me with my problem.
Have a nice day :D