Galactic Arena - Your First CRPG

So you want to program your own CRPG from scratch and you have never programmed before in your life. No problem, as long as you have intelligence, persistence, and time you can make it happen.

One problem, that a lot of people face when the want to write a computer game, is there is an endless amount of stuff to learn... Direct X, C++, Open GL, and on and on. Well the best place to start if you have no prior experience is to write very simple yet fun programs that can serve as the building blocks for your future programs. The first CRPG I ever wrote was a text based adventure game on the TRS-80. It was simple but it gave me the desire to continue to explore the art of computer science. This is where we will start our adventure into the creation of CRPGs.

Ok you are going to need a compiler. This wondrous and frustrating item will be used to transform are mere mortal code into a Galactic Arena! I suggest Microsoft Visual C++ any edition standard, professional, learning (you can usually pick up the learning edition for under $50). Next install this bad boy and start it up.

Once that is done it is time to start your first game project. Follow the steps below to get your project ready.

Ok your project and files have been created. Lets add some code to your main file GalacticArena.cpp. We will add code to allow you to create a simple character and move into the Galactic Arena. Select the FileView tab and then select the + by GalacticArena files. Next select the + by Source Files, and finally double-click on the GalaticArena.cpp file. I told you this was a basic article for non-programmers, right?



// GalacticArena.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <conio.h>
#include <stdlib.h>
#include <time.h>

int Dice(int number,int sides)
{     
	int i,total;

	total=0;

	for (i=0; i<number; i++)
	{  
		total += rand()%sides + 1;  
	}

	return(total);
}

int main(int argc, char* argv[])
{
	int muscle, brains, toughness;
	char action;

	srand( (unsigned)time( NULL ) );

	muscle = Dice(2,5);
	brains = Dice(2,5);
	toughness = Dice(2,5) + muscle;

	printf("Welcome to Galactic Arena!\n");

	printf("Your Alter Ego\n");
	printf("Muscle:%d\n", muscle);
	printf("Brains:%d\n", brains);
	printf("Toughness:%d\n", toughness);
	getch();

	printf("You find yourself in the traing pit outside the GALACTIC ARENA!\n");
	printf("<1> Go inside\n");
	printf("<2> Train\n");
	action = getch();

	if (action == '1')
	{
		printf("You enter the GALACTIC ARENA.\n");
	}
	else
	{
		muscle++;
		printf("Your train for several hours and feel tired but much stronger.\n");
	}

	printf("The Arena is filled with cheering Citizens from across the Multiverse.\n");
	printf("You prepare for battle...\n");
	printf("A sliding door begins to open slowly...\n");

	getch();

	return 0;
}


Next type in the C code above or download the file here (right-click save target as). After you are done it is time to compile the code you can do this by either press F7 or selecting Build GalacticArena.exe from the Build menu. If you see any errors or warnings in the bottom window, check what you have typed in to see if it matches the code above, have patience. If you double click on an error it will take you to the line where the error occured. Now run the program by selecting Execute GalacticArena.exe from the Build menu. Your program should look something like this...



Not Diablo II or Baldur's Gate but you have to start somewhere. Here are some quick notes about what you have created:

Well that is it for this installment. Next month, if enough of you like this article, we will introduce the game loop and Galactic Arena combat. Oh if you want to run Galactic Arena without all of the above work you can get it here.

Glen Martin is the creator of Zenfar an alien science-fantasy CRPG.