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\$
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\$
  • \$\begingroup\$ Sounds alright, but how would you assign the different upgrades to the player? \$\endgroup\$ – Johny P. Mar 20 '16 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. Mar 20 '16 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\$ – Ramsay Smith Mar 20 '16 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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.