1
votes

after some fine-tuning on my game's GUI I am finally ready to begin with the gameplay. But that's a tall order. My game will be something like a 2D platformer with RPG elements like collecting armor, helmets, weapons etc. So with that in mind I begun thinking about a way to create my player. First, I thought a single Player class would do the job for me but since I want to equip the armor/helmet I've acquired, I quickly abandoned this concept.

Next I got another idea. I could have the player's Head, Arms and Legs to be different classes and each of them drawing its own texture, respectively. So I can swap between different armor/helmet sprites for each of the body parts. But that would seem pretty complex to implement... or not?

Could I have a code example on how you would do this? Which path you would take if you are in my stead? Single Player class or different body parts classes? If the latter, how would you hook them so that it all looks like a single sprite?

2
Welcome. "Could I have a code example on how you would do this?" - we're not here for this sadly. You might want to check out gamedev. - Micky
Usually you start with gameplay first as it's much more complex than the UI. ;-) - Felix K.
Well at least could you tell me which concept would be correct? I don't even know where to start from :/ - Johny P.
A body part is a body part, an armor is equipped on top of a body part. How about have a Player class, and each body part classes, Head, Arm, Leg and, each body part has a Equipment? Sure you can swap heads, but different characters have different heads and they also look different in different helmets - libertylocked

2 Answers

0
votes

Armor/helmet should be part of the character status as it could be Health points. If you get hit your HP goes down and if your character collides with a helmet item then you should flag that status into your player object and render your character accordingly.

0
votes

You may want to use the game component pattern (link is a very good read).

You probably want the player class still be the main base of the character, and have armor/clothing components that draw on top of the character.

The player class can then "have" the components and draw accordingly, add HP or other logic you like etc. A component could "break" and disappear etc.