Jump to content
  • Advertisement
Sign in to follow this  
Miguel Chang

Simple RPG Programming

This topic is 4252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to get into the basics of RPG programming and before I get into 2D I want to just try out a very simple console RPG in C++. Warriors stats would be: HP = 200 Attack = 10 Wizard stats would be: HP = 150 Magic Attack = 20 Ranger Stats would be HP = 175 Ranged Attack = 15 The output should be like this: Choose your class: 1)Warrior 2)Wizard 3)Ranger Then after the player chooses and select a class the stats would correspond to that class and the program would move on to the battle part. Enemies stats would be: Enemy HP = 30 Attack = 10 I dont even want to implement leveling with xp yet since I don't usually program RPG games I wanted to know how I should make each class as a function that returns a value or some other way? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You can either hardcode those stats as constants and when the player selects a class you can assign the constants to the values in your class.Like :
PlayerClass noobPlayer;

char c = getChoice();
if(c=='1'){
noobPlayer.setHP(WARRIORHP);
}
else if(c=='2'){
noobPlayer.setHP(MAGEHP);
}
else if(c=='3'){
noobPlayer.setHP(ROGUEHP);
}



Another way would be to put all those constants into an external txt file for example then read them in.This way you can change and test different values without compiling your code.

Share this post


Link to post
Share on other sites
Thank goodness, someone who starts at a good pace :).

Something I would like to point out design wise first. Everyone should have the same stats (because they will use the same set of formulae). What I mean by this is, all creatures and players should have both MAGIC ATK, ATK, and RANGED ATK for example, though some may be zerod out. This simplifies things greatly.

How you could do this then, is have a class representing a creature. Each creature could have functions representing various "moves", or an attack function which does a move based on a parameter. You could then subclass this for each type of creature, setting the default stat values in the constructor. If your a fan of extensability, you could store move commands in a vector or list, and have a function which outputs them to the console as a selection.

Your attack function should take in a pointer or referance to an instance of the creature class representing the opponent your fighting. That function should run a formulae based on each opponents stats, and make the adjustments accordingly. The return value could be a boolean perhaps, representing the outcome of the battle? Anyways , there are so many ways you could go about doing this. But that should be a starting point

Richard

Share this post


Link to post
Share on other sites
Hello,

If you want to do this the OOP way then you could use the following classes for example:


This would be a base class which you could use to derive other classes from.

class BaseClass
{
public:
typedef enum DamageType
{
Melee, // example
Ranged,
Magic
}

public:
BaseClass(int HP, int Damage, DamageType Type)
: _HP(HP), _Damage(Damage), _Type(Type)
{
}

~BaseClass()
{
}

void virtual TakeDamage(signed int Damage, DamageType Type)
{
// Do some damage calculations based up Damage Type
// Negative Damage value could heal this individual
}

bool virtual IsDead()
{
return _HP <= 0 ? false : true;
}

protected:
int _HP;
int _Damage; // or _Attack whatever var-name suites you
DamageType Type;
};



Now we implement the class specific classes you sampled.

class Warrior : public BaseClass
{
public:
Warrior()
: BaseClass(200, 10, Melee)
{
}

~Warrior()
{
}

void TakeDamage(int Damage, DamageType Type) // Do some rock, paper, scissor thing
{
switch(Type)
{
case Melee:
{
_HP -= 1.0f * Damage;
}
case Ranged:
{
_HP -= 0.5f * Damage;
}
case Magic:
{
_HP -= 2.0f * Damage;
}
}
}
}



class Ranger: public BaseClass
{
public:
Ranger()
: BaseClass(175, 15, Ranged)
{
}

~Ranger()
{
}

void TakeDamage(int Damage, DamageType Type) // Do some rock, paper, scissor thing
{
switch(Type)
{
case Melee:
{
_HP -= 2.0f * Damage;
}
case Ranged:
{
_HP -= 1.0f * Damage;
}
case Magic:
{
_HP -= 1.5 * Damage;
}
}
}
}



class Wizard: public BaseClass
{
public:
Wizard()
: BaseClass(150, 20, Magic)
{
}

~Wizard()
{
}

void TakeDamage(int Damage, DamageType Type) // Do some rock, paper, scissor thing
{
switch(Type)
{
case Melee:
{
_HP -= 1.5f * Damage;
}
case Ranged:
{
_HP -= 2.0f * Damage;
}
case Magic:
{
_HP -= 1.0f * Damage;
}
}
}
}



In your console you could use the TakeDamage(...) method.

Hope this helps.

Regards,

Xeile

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!