Advertisement

a simple question(i think)

Started by October 25, 2000 01:06 PM
9 comments, last by Necromancer 24 years, 2 months ago
Well that hardly seems fair. You seem to make different functions for when the hero hits the vilain as opposed to the vilain hitting the hero. Maybe a bit of inheritence is in order:

[source]
struct Character
{
int hp;
int mp;
int str;
int intelligence; // int int; ? hehe
//whatever is common to both hero and vilain

int IsAttackedBy(Character* attacker)
{
// do damage calculation
return (damage_done);
}

};

sturct Hero : public Character
{
int experience;
int playtime;
char playername[20];
// Hero-specific stuff
};

struct Vilain : public Character
{
bool isBoss;
// vilain-specific stuff
};

main()
{
Hero player1;
Vilain Goblin;
// ...

player1->IsAttackedBy(&goblin);
//...

goblin->IsAttackedBy(&player1);
}

[source]

This way you only have to change the damage equations in one place in your game. This is using an RPG example, but is definately relevant in many cases where the game mechanics should work the same for all things in the game.

Am I answering a different question then was asked?
- Rick

This topic is closed to new replies.

Advertisement