Constructors
Posted: Tue Jul 13, 2010 5:06 pm
Hey, I was just wondering if there is an easier way to do something like this:
So what I want to do is have player classes (classes that the player can choose such as in a RPG. E.g. Archer, Warrior, etc.) and have the information for those player classes automatically be assigned to the player like take for example I create a class and call it Assault or Rifleman. This "Rifleman" has default weapons and attributes that are different from other classes.
Rifleman
Default Primary -> Standard Assault Rifle
Default Secondary -> Standard Handgun
Health = 100
Speed = 2.5 ; Where as an explosive specialist class would be slower or faster.
Take for example, to figure out what the player's current weapon or loadout is, I'd just call this in main.cpp:
At first, before I introduced Loadouts into the game, I was just calling a SetWeapon() function in player.pPrimary.SetWeapon(StandardAssaultRifle) to set the weapon which could be changed when a gun is picked up. Now, I'd like to create a function which inside assigns the player's weapon based off the current Loadout. So, whatever the assault's default primary weapon is, that becomes the player's current primary. Or if the player changes classes, it automatically does it.
I'd like to know of easier ways of doing this. Like should I create derived classes of the Loadout Class and then assign the information in each or just have the instance of the Loadout Class and then assign all the information in a constructor?
So what I want to do is have player classes (classes that the player can choose such as in a RPG. E.g. Archer, Warrior, etc.) and have the information for those player classes automatically be assigned to the player like take for example I create a class and call it Assault or Rifleman. This "Rifleman" has default weapons and attributes that are different from other classes.
Rifleman
Default Primary -> Standard Assault Rifle
Default Secondary -> Standard Handgun
Health = 100
Speed = 2.5 ; Where as an explosive specialist class would be slower or faster.
Take for example, to figure out what the player's current weapon or loadout is, I'd just call this in main.cpp:
Code: Select all
Loadout Assault(); // () anything in side the parenthesis are for the constructor which is apart of what I need help on.
player.pLoadout.SetLoadout(Assault);
I'd like to know of easier ways of doing this. Like should I create derived classes of the Loadout Class and then assign the information in each or just have the instance of the Loadout Class and then assign all the information in a constructor?