Public Group

# Gameplay programming

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

## Recommended Posts

Hello, I have taken a C++ class and like it and also like games. I want to make a video game of a character like ultima online, but wanted a kick in the right direction. I want to make him have skills and such. I am confused about data structures to use for creating a character object in my game, but here is my idea. Can someone tell me if I am on the right foot here? Also any link to a tutorial to read or book for me to study on this aspect of gameplay programming would be great! i love reading programming. Im only 13 almost and will take C++ classes and advanced math at my private school :) I will make my characters created in my game as a struct. psuedocodish. Im sure its probably really bad and wrong heh :/ struct Player_Obj { int Obj_ID; Char strName; char Profession; struct Stats; list* Prof_abilities /* spells or special moves associated with his Profession.*/ list* skills; /*make a linked list of skills so i can add some later or remove some i dont like*/ list* Equipment; //keep track of his equipment inventory int Money; }; struct Stats { int Strength; int Dexterity; int Wisdom; int Intelligence; int Charisma; }; I was going to store all his data in a mySQL database and build the character from it.

##### Share on other sites
Fistly, I'd recomend std::list or std::vector, not your own custom one. It will just be more complete and you could spend more time making the game.

Next, you might want to consider using an enum for skills(I'm assuming that these are kinda like feats were you just have a skill, you don't level it up in D&D? I've never played Ultima Online.) If you use powers of two for the numeric values of the skills you can have multiple skills in one variable. Example:

//declare the enum typeenum Skills { skillA = 1, skillB = 2, skillC = 4}//declare the variableSkills playerSkills;//set the skills available, in this case A and C.playerSkills = skillA|skillC;

Enumerated types might also works well for professions.

Good luck!

##### Share on other sites
Ezbez gives his views one the subject, and while I won't agree with him (mostly because of these nasty enums), the system he presents is simple enough to be implemented (it only requires you to understand bitwise arithmetic and operators - as well as enums, of course).

He also tells you that you should prefer the standard lists, vectors and strings instead of your own ones: it can't be more true. Unless you are The C++ Guru, the one you'll write will not be as good as the existing one. Of course, noone forbid you to write these container classes in order to learn how they work.

Now, my point :)

From an OO design point of view, you should avoid enumerations (enums in C++ are still not typesafe, and they hardly represent something) and use classes and inheritance. For example, your character profession is not an enum, it's a class (Profession) from which you'll inherit to create all the profession you want (Detective, Soldier, Student (I'm in Cthulhu right now)). The profession abilities are now defined as sub-objects of your profession classes.

Skills are correctly represented by a list (or a vector), but this list should be encapsulated in another object (SkillSet, for example).

Everything I told your is about implementation details. If I'd wanted to give you a kick in the right direction, I'd say that you should not do anything right now, for at least two reasons:

1) you are going to take a C++ class. The system you want to implement is very complex, so I beleive you should learn more about the language before doing anything else - it will be easier and less frustrating.

2) my own personnal mantra is "design first, then code". While you learn C++, you can try to design your game: what the involved (C++) objects will be , how they will interact, and so on. Of course, this is very hard: it is a full time job, ni fact. Moreover, 13 may be a bit young to handle such abstract things (hey, you're good at math ?). Nevertheless, don't be affraid of doing mistakes - on ne fait pas d'omelette sans casser des oeufs.

Last but not least: if you want some help, don't be afraid to ask question on gamedev.net :)

HTH,

##### Share on other sites
That's very cool. I "have a friend" that used to work on Ultima Online a long time ago. He *suggested* that it works the following way:

It used arrays and #defines:

Something like:

#define SKILL_BLACKSMITHING 30
.
.
#define SKILL_MAX 49

then

int base_skill[SKILL_MAX];

:D

##### Share on other sites
Ahh okay so thank you all very much for the input. So a struct is not the way to go. rather, use a class for the inheritence? I was initially leaning for the struct because I can just feed the values for an existing character from a dataset into the values. So maybe I should look more like this?

#include <list> // list class library
using namespace std;

class Player_Obj {
public:
Player_Obj()
~Player_Obj()

Update_DB() {} //update the DB with char info periodically

private:
int Obj_ID
char Char_Name;
char Prof_Name;
list Stats;
list Prof_Abilities;
list Skills;
list Equipment;
int Money;
};

##### Share on other sites
Quote:
 Original post by Anonymous PosterThat's very cool. I "have a friend" that used to work on Ultima Online a long time ago. He *suggested* that it works the following way:It used arrays and #defines:Something like:#define SKILL_BLACKSMITHING 30..#define SKILL_MAX 49thenint base_skill[SKILL_MAX];:D

That's the C way of doing it (can I assume that ultima online was written in C ?).

Quote:
 matt_stevens_2006Ahh okay so thank you all very much for the input. So a struct is not the way to go. rather, use a class for the inheritence? I was initially leaning for the struct because I can just feed the values for an existing character from a dataset into the values. So maybe I should look more like this?

You are welcome. In C++, structs are used to create a collection of value that has no associated behavior or as helper to communicate with a thrid party component. When they are carefully crafted structs are useful for bulk read (ie read from a medium (network, file, ...) without any interpretation of the data. For example, you'll probably use a struct to read the header of a bitmap file.

When you can associate some complex behavior with a struct then it's better to create a class and to encapsulate your structure data.

You can also mix the two solutions - C++ allow you to create classes/structures in another class:

class Player{private:  struct PlayerInfo  {    // some stuff here  };  // other members, such as the skills or the equipementpublic:  Player();  bool UpdateDB();  // and so on};

BTW, from a conceptual point of view, there is no difference between a structure and a class. In C++, the only difference lies in the access control feature: by default, class members are private while they are public in a struct.

HTH,

##### Share on other sites
After reading Emmanual's post, I'd probably have to agree with him on pretty much every point. That is the *better* way that you'd be taught about in a software engineering course. However, for a beginner enums may (or may not) be easier to implement. Basically, its your choice.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013753
×