Version 2.0!
Features
Tutorials
Files
Glossary
Projects
Contact
Links
Message Board
Extras
LuckyCam
Old News
Sign Guestbook
View Guestbook
VB Horoscope
VB Photo Album
Vote for this Site
Nexus News
.

VB RPG Tutorial

By Jim (Machaira) Perry

 Note: Any use of the source code in this tutorial for non-educational purposes is prohibited without the express consent of the author.

 

Contents

 

Introduction

VB + Games = ?

What Is An RPG?

What Is An RPG To A Programmer?

The First Steps

Class/Code Descriptions

 

 

Introduction

 

With the amount of people I’ve seen on VB message boards saying they want to do or are doing RPGs, I figured it was time to share some information on my work with RPGs. The goal of this tutorial is to produce a playable RPG/action game in the style of DiabloII or UO. This tutorial assumes you are familiar with VB and concepts such as classes.

 

VB + Games = ?

 

As little as 2 years ago if someone had told me you could write a quality PC game using VB, I probably would have laughed. Sure, VB had some graphics cabilities, but they were notoriously slow. Also, how would you handle things like sound, multiplay, peripherals such as joysticks & gamepads, and fullscreen capability. I’d seen small, simple games running in a window – things like Tetris or even PacMan clones, but doing a game like Diablo in VB?! Get serious! Well, with the ability to use DirectX in VB, many VB programmers dream are a reality. High quality graphics, sound, network and Internet play, even movies are now possible. In this tutorial I’ll show you how to do some of these things. Along the way we’ll create a simple RPG. VB’s object oriented capabilities make dealing with the many items and data that an RPG needs fairly simple. While this won’t be a Diablo level type RPG (and yes, I know Diablo isn’t a true RPG. But it has many similarities, so for the sake of argument we’ll pretend).

 

What Is An RPG?

 

RPG is an acronym for Role-Playing Game. The player assumes the role of the character, controlling every aspect of the character. A character in a role-playing game is usually based on stats and skills. Stats are such things as strength, dexterity, intelligence, etc. These stats are represented by a number, which indicates how developed that stat is. The higher a character’s strength, the more he can lift. The higher his intelligence, the easier he can learn things such as spells or languages. Skills are such things as using a sword, firing a gun, walking a tightrope, etc. There are different ways these skills are represented in an RPG. They are usually also based on some numeric value that indicates how well the character can perform that skill. A Computer Role-Playing Game (CRPG, but call RPG from this point on) sometimes hides some or all of these numbers, but most allow you to see at least the stats and determine how the character develops by changing them. An RPG is usually an isometric 2D style game. It uses sprites for graphics representing the character(s) and creatures. Sprites may also be used for things like trees, rivers, buildings, and items such as weapons, armor, treasure, etc. RPGs are also now moving into the 3D realm now that powerful graphics cards are commonplace.

 

What Is An RPG To A Programmer?

 

Let’s run down some of the things that come to a programmer’s mind when he thinks of an RPG:

 

  • The character(s)
  • Creatures
  • Armor
  • Weapons
  • Items such as treasure, scrolls, potions, etc.

 

Other things to consider are:

 

  • The map
  • Tiles
  • Skills
  • Spells
  • Stats
  • Scripts (advanced)

 

The programmer thinks of these things in terms of objects. Some of them are represented on the screen by graphics, but all are chunks of memory that the programmer manipulates as the game progresses.

 

The First Steps

 

The first steps I took when designing the RPG I’m working on were (roughly):

 

  • Decide on the graphics engine type – I opted for 2D isometric. It’s a common style that, for me, looks the best with a minimum of work. Other types could be: 2D – top down, square/rectangular or hex tiles and 3D – first person or isometric.
  • Decide on the RPG system that is used. This tutorial will use the following stats:
    • Strength – determines how strong the character is. This will affect the damage a character does in melee combat, how much the character can carry, and to some degree the amount of hit points a character has.
    • Dexterity – determines how coordinated the character is. This will be used in combat and other skills
    • Constitution – determines how quickly the character recovers from disease, injury, etc. This will also affect the amount of hit points a character has.
    • Intelligence – determines how quickly the character can learn. This stat is mainly used by spell casters.
    • HP – the amount of damage a character can take before dying.
    • Mana – determines how much magic the character can use before becoming exhausted.
  • Develop the tools for creating the game. This could include a map editor as a minimum. Other tools might be a script compiler, character creator, or anything else that might make creating the game a little easier on a designer, level designer or yourself.
  • Identify the code objects that will be used. This is an ongoing process (at least for me). The objects used for this tutorial will be:
    • Character – this will cover player and non-player characters. Non-player characters include creatures for the purpose of this tutorial.
    • Skill – skills allow a character to do things like swing a sword, cast a spell, notice things out of the ordinary, etc.
    • Spell – fairly self-explanatory.
    • Item – this will be a base class from which armor, weapons, and other items such as potions and scrolls are derived.
    • Map – this class holds the data necessary to display the world the character will dwell in. One of the members of this class will be an array of:
    • Tile – holds the data for determining the properties of an individual tile.
  • There will also be several UDTs. These could be classes (and are in my game), but for this tutorial UDTs suffice:
    • Stat
    • Room – this will be used for the one advanced feature – triggers.

 

 

Class/Code Descriptions

 

Now that we have some classes identified, we need to flesh them out a bit. Feel free to add whatever other properties you like as we go along. Let’s start with the Character object:

 

Character Class

This is probably the most involved class, as far as the number of members and methods. Not all are needed and more could be added. Most of the members are fairly self-explanatory and the ones that aren’t are commented. The Character class interacts with every other class to some extent, either by having them as members or by needing information from them in order to keep itself updated with the world in which it dwells. I’d like to touch on some of these members:

 

  • The Stat member can be changed to any number system you’d like. Some popular ones are: 1-100 (used here), 1-10, 1-6. Your system can also determine whether or not these values can change as the character gains levels. Most systems do increase the values but I personally feel this is unrealistic. Whatever works for you, however, is best.
  • The Level & Experience members will require some tweaking during testing more than likely. You want to have the player feel they are making progress quickly during the first couple of levels. As the character advances, however, it should be harder to increase the level without a corresponding increase in the strength of the creatures that must be fought. This may be a difficult balance to find.
  • The Age member can be strictly for building the character’s persona or could be used to modify the character’s stats and/or skills due to aging. No CRPGs that I know of do this. It would require keeping detailed track of time that may not be worth it. But for a MMORGP it would be more realistic.
  • Mana – your way of dealing with mana will be dependant on your magic system. Most RPGs simply base the value of this member on a stat. This tutorial does this. There are many ways of doing this. Most message boards that have an RPG forum discuss this at one time or another. Magic systems are a topic of much debate.
  • Skillpoints – your skill system (if you use one) is another area that could be done many ways. The way I’ve implemented it is as follows: every level a character gets a number of skill points. This number is determined by stats. Every skill costs a number of points. Every skill is available to every class, but the amount required to gain a level in that skill could be huge. Every time a player invests the required amount of points the character increases that skill’s level by 1. Every skill level represents a percentage that is added to the chance to use that skill. For example, if a warrior has a skill level of 5 with a longsword, he receives a +25 (or some other value. +5/level is used here.) to a roll when attacking a creature. I’ll go over combat more fully a little later on.

 

Skill Class

This class is fairly straightforward. It actually could have been a UDT, but I made it a class in case of expansion. There are several modifiers that can be used to add to or take away from a character’s chance to perform a skill. These can be used to make classes or races better at some skills than other (ex. An elf would be better at woods-based skills – tracking, stalking, hiding, etc.)

 

Spell Class

This class looks fairly simple considering the difficulty in developing a good magic system. The only thing that’s probably not obvious is the SkillPointsAllocated member. When investing skill points to learn a spell, a roll is made to see if the character succeeded. If he didn’t those points carry over until the spell is learned. If a player keeps putting points into a difficult spell, he’s guaranteed to learn it eventually.

 

Armor Class

My system for handling armor is a little different than most I’ve seen. I believe it’s a little more realistic. Each piece of armor has a Defense member that reduces the amount of damage done to a character. The armor also has an HP member that determines how much damage the piece can take before becoming ineffective. The more damage it takes, the more the Defense is reduced. The armor can be repaired to restore both Defense and HP. The Armor class also has a member that is a collection of Spell objects. This allows magical armor to be created. There are also members for offensive and defensives bonuses. These are arrays of a UDT that is defined in the constants module. The bonuses can be either positive or negative and are added together and used to modify the base

 

Weapon Class

Weapons operate similar to armor with regards to effectiveness. A weapon that has been damaged won’t do as much damage. Each attack has a chance of damaging the weapon

 

The 3 Epic… members allow for a system where a quest is done to find a weapon that is the object of the quest. The EpicItem member determines if the weapon is part of a quest, the EpicItemPiece member allows for a weapon that has been broken into several parts, and the EpicNum member allows for multiple quests to run at the same time.

 

Map Class

The Map class simply gives some information about the current map the players are adventuring in. The most important member is the collection of Tile objects. Access to all tile data is through this class.

 

Tile Class

This class holds information that describes an individual tile. This includes the bitmap that is used for the texture, the type of tile (normal, lava, hindrance which reduces movement, impassible, wall, door, etc), and the contents of that tile. This class also uses the advanced part of this tutorial. The Action member is an instance of the Action class that determines what, if anything, happens when a character steps on or presses the tile. The action is not limited to the tile. The Action class has members that can be used to produce an action on any tile in the map.

 

Action Class

This class is used to determine actions that the level designer wants to occur on the map. The actions that can be triggered are limited only by the ingenuity of the programmer. The actions that I’ve incorporated are:

  • Trap (Single) – affects just the character that triggered the trap
  • Trap (Multi) – affects the entire party
  • Teleport – teleports the character/party to another place on the map
  • Heal
  • Level Change – teleports the character/party to another map
  • Spawn Monster
  • Spawn Item
  • Lock – locks a door
  • Unlock – unlocks a door
  • Message – displays a message to the character/party
  • Player Start – the position the character/party starts when a map is loaded

 

We’ll go into more detail when we implement this class

 

Sprite Class

This class is used to store and draw all graphics for characters, items, or any non-tile graphic. We’ll go over this class further and expand it when we cover the graphics engine.

 

Constants

I’ve defined a number of constants, UDTs, and enums that will be used in conjunction with the classes. I believe they’re fairly self-explanatory.

 

Conclusion

 

Hopefully this will be of some use to those who are just starting out with VB game programming and want to do an RPG. It is a huge amount of work, as you’ll see when the tutorials continue. Please e-mail me any comments on this, any ideas you’d like to see incorporated, etc. Till then – keep coding!