Character class inheritance

I realize this might not be exactly a Monogame-exclusive quesion, but I’m no sure where else to go.

I’m trying to have the following:
-A “Character” class, from which I can inherit to create a few different characters
-Five characters inheriting from the Character class
-A way to spawn those five characters and assign each to a controller (four joysticks and the keyboard, that is).

How can I go about this? What should those classes look like?

I already have a character with texture, animations, behaviour, etc. But how do I inherit others, with different sprites and input, from it?

For handling multiple gamepads, you can just pass the index of the controller to the character and store that in a field in the Character class. You can make the fields/properties for the texture and animations in the Character class virtual and override them in inheriting classes, or just don’t use inheritance at all and pass the texture and animation (or even just the path to them, then load them in a LoadContent method) to the Character constructor like the gamepad index.

1 Like