Defining characters

Characters are a type of entity that is essential in a major part of games. Depending on the game type, they will be defined with more or less detail. For instance, in strategy-type games, characters are usually defined with a few stats, while in role-play games characters have a wide range of stats. In many games, apart from their stats or personal attributes, characters have an inventory attached to them. That is the case of Dagovar games, too. In the image below you can see the character's stats to the right and the inventory items to the left.

Games, as any other application, are made up of a great amount of data definitions (variables) where we store values that are used to control what the game has to do in any moment. There are different types of variables to be used, but what they all have in common is that they store numbers. These numbers have a meaning in the world of the game, and their values can be shown as they are - numbers - or can be assigned to a certain object or concept, that has to be shown as an image or a behaviour on the program.

A character is simply made up of certain kinds of numeric - or alphanumeric - variables that arranged together define it. And I say arranged, because they are included in user-defined types, a type of variable that allows to manage with ease large amounts of data. If you read further these chapters, you will see that nearly any type of entity will be defined with an user-defined type. The complexity of an application such as a game, will make necessary as well to nest certain user-defined types inside another user-defined types of higher hierarchy.


As you can see in the image, the character has a bunch of attributes, labelled in green color, starting by her name, Arcania, and some attributes with a current and maximum value. That is because our character will be able to increase these attributes when she earns experience points. There are two additional attributes on the top of the list, labelled in yellow. They are apart from the others because they are a particular type of attributes; they are just limits imposed to the character, so she cannot surpass a certain thresold of value (attributes and items have a cost in points that adds up until reaching a limit value for the character).

You can see as well an antibullet vest, labelled as ARMOR, on the central space between the attributes and the inventory; the antibullet vest is an atribute on itself, but it is represented as an image instead of a number, and it is an attribute that can be altered in a particular way during gameplay - the character can wear it or not, or pass it to another character -. The colors of the character's skin and hair are also attributes whose value is shown in a graphical manner, and these can be changed only while creating the character on the CharEdit application.

Well, as I said, each attribute is just a numeric - or alphanumeric - value, but in the game all these values will be used in many different ways. For instance, the alphanumeric data that form the name of a character is just used to make that character recognizable for the player, while the stats and the antibullet vest obviously influence many algorithms that work during the game.

Now to the left we can see a serie of items that are included on the inventory; these objects could be considered also as attributes, since they add something to its owner. But each of these objects is more than that; it is an entity on itself, with its own attributes. As I said before, an user-defined type can be nested inside another user-defined type that is higher in hierarchy. In this case, inventory items are 'inside' characters. Now I will show you the source code as it would be programmed in Visual Basic 6 to define these lovely creatures:

Public Type Character
sngPoints As Single
sngLoadPoints As Single
sngLoad As Single
strName As String * 12
bytModel As Byte
bytResistance As Byte
bytMaximumLoad As Byte
bytActionPoints As Byte
bytCuration As Byte
bytFirearms As Byte
bytGrenades As Byte
bytMelee As Byte
bytArmor As Byte
bytOrientation As Byte
Inv_Items(1 To 16) As Item
End Type

You can notice the fixed array of 16 variables of type Item; these form the inventory that a character can carry, which is limited to 16 objects. Let us see the definition of an item:

Public Type Item
bytId As Byte
intQuantity As Integer
End Type

It it very simple, right? Just two variables, that indicate which type of item (Id) and which quantity of that item (Cantidad). But an item is just an entity created from a definition. A definition is an user-defined type where the attributes of an entity are defined. Think of an entity as a cookie; the definition of a cookie would be the mold where cookies are molded. So both a pistol and a grenade are items, but belonging to different item definitions. Let us see the definition of an item definition:

Public Type Item_Def
bytId As Byte
sngWeight As Single
sngPoints As Single
strType As String
strComment As String
End Type

You can see in this definition some variables that will store the corresponding values for the attributes of a certain type of item. Note how the identificative variable (Id) is included also in an item definition. Well, it looks obvious that in the game much more attributes will be necessary, but in the CharEdit application, these are enough. For example, Weight and Points are related to the yellow-labelled attributes that I referred previously; they are needed to control how much points a character is using and how much weight of items a character is carrying, because those values have a limit set to them.

Let us see now some definitions of constants that the program will use:

Public Const NUM_ITEM_DEFS = 18
Public Const MAX_POINTS = 1000
Public Const MAX_RESISTANCE = 50
Public Const MAX_LOAD = 30
Public Const MAX_ACTION_POINTS = 10
Public Const MAX_CURATION = 10
Public Const MAX_FIREARMS = 100
Public Const MAX_GRENADES = 100
Public Const MAX_MELEE = 100
Public Const MIN_RESISTANE = 30
Public Const MIN_LOAD = 15
Public Const MIN_ACTION_POINTS = 5
Public Const MIN_CURATION = 0
Public Const MIN_FIREARMS = 50
Public Const MIN_GRENADES = 50
Public Const MIN_MELEE = 50

Probably you can relate most of these values with the ones shown on the image above; the first one, which is 18, could remain obscure, though. It indicates the number of item definitions that the program will use; that is, the number of different item types that we can use when playing the game. This number has to be defined, because we have to create an array of item definitions that has this same number of cells, to store on it the values of the attributes for each different item definition. This is done by a long procedure that loads all the values on the array when the program is initialized. I wrote the values directly on the source code, so the users cannot modify them, but they could instead be loaded from an external file, if I had wanted so. It would be easy to allow to add an indefinite number of definitions to a program by allowing the users to generate their own text and graphical files for the new objects, but in a game this wouldn't make any sense if we didn't put on our program some kind of restrictive code to block overpowered, cheating objects...

Finally, we have to declare the variables that will make use of our fascinating user-defined types:

Public Item_Defs(1 To NUM_ITEM_DEFS) As Item_Def
Public Character As Character

In these variables we will store all the attributes needed for the different items and the character, those lovely little entities... Since CharEdit is just a character editing application, I only declared one character. But with all the variables that I have shown so far, we can start to shape all the attributes of a character.

And this is the foundation of the CharEdit application and the seed from which the game can be born. I am not going to write here all the source code of the application, since that would be just sick. Remember that the complete game has around 20000 source code lines. I just wanted you to see how data is conceptualized and arranged to be used efficiently. The rest of the program is just the manipulation of this data; click here to change this or that other attribute, save all the variables to a file, load all the variables from a file, and so on... the limit is your own imagination, your skill or your patience...

In successive chapters I will enlighten your spirit with more subjects around the Dagovar project, that can be used as an inspiration to create other games.

About Dagovar

~ About Dagovar ~

Desert Vixens 2 maps

~ Desert Vixens 2 maps ~

Desert Vixens 3 maps

~ Desert Vixens 3 maps ~

Tile-based terrains

~ Tile-based terrains ~

Random maps

~ Random maps ~


~ Screenshots ~


~ Algorithms ~

API functions for games

~ API functions for games ~

Source code examples

~ Source code examples ~

Return To Index

Privacy Policy