Hi there! My name is Mike Parson and I'm a professional game programmer. I have coded several commercial titles, and I am currently working as lead programmer for a 3D MMORPG.
This site was built with beginners in mind. Just like you, I wanted to learn how to program games, but I have discovered that game coding is hard. Many wannabes are enthusiastic, but then they find out that they'll need to learn a lot of math, complex programming languages, and so on. Truth be told, it's much easier to write the code for a complex database application in comparison with a simple RPG, which needs code for the inventory, player, enemies, non-playing characters, etc.
So, most beginners look forward to learning game programming, but then get discouraged and quit. Believe it or not, it happened to me as well! However, I loved games so much that I chose to return to programming, and now I'm a proficient C++ game coder. I like this programming language because it is very powerful and fast. It's also used by some of the best game engines in the world, such as Unreal and Unity.
We are going to use a subset of the C language for these tutorials, though. My goal is to get you up and running by making use of as few lines of code as possible. So, Google acknex.h and download a copy on your hard drive; we will include it in our projects, and thus get access to lots of gaming-related functions that will greatly simplify our projects.
These things being said, we are ready to start our first RPG tutorial. And to keep things simple, I will discuss each block of code individually.
The two lines of code above include two different files in our project. The first one is acknex.h, and we've already discussed its role. The second file includes the code for player's movement. It's a bit too complex for what we know now, so we'll discuss it in the next tutorial.
Please note the pointy brackets and the quotes that are used to include those two files. We will use pointy brackets whenever we want to include an already existing resource in our projects, and quotes when we plan to incorporate our own coding resources.
var show_pointer = 1;
STRING* rpg1_wmb = "rpg1.wmb";
ENTITY* sky =
type = "skycube+6.tga";
flags2 = SKY | CUBE | SHOW;
The code above consists of three definition: a variable, a string and an entity. A variable is a place in your computer's memory that can be used to store a certain type of data. In our case, a var can store a number that ranges from -1,000,000 to 1,000,000. These values are more than enough for most games; you can use a "long" variable if you need to store larger numbers.
The string stores the name of the level; it's "rpg1.wmb" in our example, but it can have any other name.
Finally, we define a sky entity which will be used in our levels. The information is read from the skycube+6.tga file; the name tells the computer that our bitmap consists of six different images which are glued together. In a nutshell, the player will be placed inside a cube whose six faces are those six bitmaps that are read from skycube+6.tga.
d3d_fogcolor1.red = 255;
d3d_fogcolor1.green = 255;
d3d_fogcolor1.blue = 255;
video_mode = 8;
video_screen = 1;
media_loop("chase.mp3", NULL, 70);
Function main gets executed every time you run a C application; without it, your code wouldn't do anything, because it can't run. So, you will want to put all the code that needs to be executed at game start in this function.
The first three lines of code set up the color of the fog in our levels; we want to use fog because it looks cool, and it also helps us hide some of the things that must happen behind the scene, such as level-of-detail model changes, new level sections that are loaded as we approach certain areas, and so on.
The next two lines of code set up the video game resolution to 8 and ensure that the game runs in full screen mode. Our previously defined level is then loaded, the game waits for three frames to ensure that the entire level is now loaded in the RAM memory, and then the "chase.mp3" soundtrack is started and run in a loop.
my.ambient = 50;
This tutorial ends with an action definition. Actions are attached to objects (entities) in our levels; their code starts to run as soon as the level that contains those objects is loaded. In this case, the vegetation will use the accurate "polygon" collision detection flag, and its ambient light will be set to 50%.
I hope that you like this first role-playing game tutorial. As you can see, the basic elements of a simple RPG game don't look that scary.