0
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Personally, I would use a single Player class element, for simplicities sake. Here I would just have drawing code that accounts for the various upgrades that the player purchases.

For example, I would have some kind of UpgradeManager class that holds all the upgrades in a list, based on some List<Upgrade> where each upgrade has a Texture2D property. Then I would assign the upgrades in a List<Upgrade> as a property with the Player.

Hopefully this will get you on the right track.

\$\endgroup\$
3
  • \$\begingroup\$ Sounds alright, but how would you assign the different upgrades to the player? \$\endgroup\$
    – Johny P.
    Commented Mar 20, 2016 at 19:16
  • \$\begingroup\$ I imagine I would have something like an abstract Equipment class and have armor/leggings/helmets classes inherit from it, but how would I assign that to the player? \$\endgroup\$
    – Johny P.
    Commented Mar 20, 2016 at 19:53
  • \$\begingroup\$ Like I said, you could use a List<Equipment> for equipment assigned to the player, or you could have individual fields for each type of upgrade (armor, weapons, etc.) \$\endgroup\$ Commented Mar 20, 2016 at 20:30
0
\$\begingroup\$

I would do both. I would make separate arms, legs, body, and head classes and keep track of them all within a player class. This way, in your Game1 class and other classes, the player is treated as ine object, but within the class, the body parts are treated separately. Hope this helps!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .