Wednesday, April 18, 2018

entity system - Superclassing RPG Game Entities



I am in the design process of an RPG game and I have no experience at all in game dev. This question is about how I should approach entity management using OOP classes.


My train of thought is as followed:




  • Have Entity interface with basic update() function

  • "Mortal" class and "NPC" class implement Entity

  • "Hero" and "Monster" class inherit from "Mortal" class


In this case, Mortal class are all those entities that have statuses such as HP and MP. NPC are self explanatory.


I am sure my approach is naive so I would like to know the pros and cons and what would be a better way to approach this.



Answer



Your approach is fine, and was used widely by game developers of the past. You see with inheritance hierarchy you often find yourself in a situation there you want inherit from a multiple classes, but they don't usually mix well (including The diamond problem). Because of that, a component based architecture is being widely adopted. One variation of this approach is called Entity component system or ECS. This approach uses composition instead of inheritance to build up functionality of the entity (note that entity have a very special meaning in ECS). If you are interested in ECS here is some references for you to start: one, two, three.


As Sean Middleditch correctly noticed ECS is just one type of implementation, you are free to use other approaches.



As a side note, I really suggest you not concentrate much on architecture for your first attempts. It's really hard to make all right and nice in games. There are many other aspects which are important for a novice: handling game loop, input, graphics, sound, physics, collision detection, and the list goes on. You should try to make small game (like Tetris or Breakout) ignoring architecture nuances, to become comfortable with your tools, and see the whole picture.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...