QB CULT MAGAZINE
Vol. 2 Iss. 3 - August 2001

RPG Development, Part 1

By Matt2Jones <matt2jones@yahoo.com>

Hello fellow coders of QB,
I am Matt2jones, a Qb programmer, probably the only one left, who is still OBSESSED with RPGs. I will hopefully be posting a series of articles in QBCM about RPG developement, and how to finish one. This first article will be more of an introduction than a tutorial, but the rest WILL be better.

First up, "What the fuck is an RPG?" Well, an RPG is a Role Playing Game (Believe it or not, it took me FOUR MONTHS to make that association!), this means the player TAKES ON THE ROLE of a character and lives in their universe (Am I sounding familiar? If I am, stop reading because you've heard this stuff allready.). USUALLY an event of great importants is taking place while the player controlls the character, but I stress the word "usually". Most RPGs tend to focus around the Plot and character developement more than fast action, and that suits most people fine (No "tricky" INKEY$ functions nessery, just reliable old INPUT A$!;).

An RPG also tends to have whats called a "Turn Based Battle system". Ie, you attack, the enemy attacks, you attack, the enemy attacks (you take turns). While some of the more... Profesional RPGs are slowly loosing this technique (FFIX for example), it is still my favorite method of combat.

Most Qb RPGs tend to be made with "Scrolling Tile Engines", a method I'll discuss in the next issue along with many others, and nice, colourful tiles. That is NOT nessesery. Infact, the first thing about making an RPG should be the Story, then the Graphics, then the Story, then the Engine, then the Story. Well, perhaps I exagerate a little;-), presentation and ease of use are also important factors, but to this RPGer, Stories come FIRST!

Now I've rambled on long enough (And I don't care if you still don't know what an RPG is, you can find definitions almost everywhere!), its time to get to the main part of this article...

How am I supposed to code this new-fangled RPGamabob? Well, this was probably the step in the ladder that stumped me the most. I was all set to have Waters of Europa the greatest thing since FFVII, but I didn't know where to start. Well, I'll tell you, because no-one told me: Story and Graphics.

Write the story anywhere, and draw the graphcis anywhere (preferably on the computer though, and no smartass, not ON the screen:P But make sure you have the basics done, that way once you get the Engine up and running, you won't have to wait weeks to get graphics to test it.

Well after you finish that stuff it's time to move onto the Engine . To help you I have, in the course of my long Qblife (2 years), devised 3 main ways:

Script Orientated BASIC Orientated (aka CheckStuff) CHAIN Orientated L And a subset of CHAIN Orientated... SUB Orientated!

Script Orientated is the most professional and is used for Epic, 1 Meg+ games. BASIC Orientated is the next step down, usually for smaller games (80k). CHAIN Orientated is the most unstructured peice of shit you are ever going to come across, and are probably the most fun to make. I've seen Epic CHAIN games (Elysian Field... NO, SCREW YOU, THAT GAME ROCKED!), and smaller ones which are too insignificant to mention (Okay, Hellpit 2&3). And SUB Orientated is a subset of CHAIN because it is mostly used in that type of game, but SUB games can also be RPGs in their own right (Hellpit/Demon Hunter/Fantassy Power Zone).

Now that was a lot of unhelpful blabber, so I'm going to explane how to make each one now.

Script Orientated:

In the main module you should have something like this:

DEFINT A-Z
DIM SHARED HP, MP, MHP, MMP, ST, DF, GOLD, X, Y, LOCATION, STORY
DIM MAP(63, 63, 3)
SETUP
TITLE
A=OPTIONS
IF A = 0 THEN
	INITNEWVARS
ELSE
	LOADOLDVARS A
END IF
GAME
SYSTEM

As you can see, this is pretty much a long list of Sub calls, and some dimensioning Variables.

HP and MP are obvious enough (Health Points and Magic Points), mHp just means Max Health Points, and mMP the same with Magic Points.

St is your strenght (How much damage you can inflict), Df your defense (How much of your enemies damage you ignore).

Gold is how much money you have (Duh).

X and Y are your coordinents on the map.

Location is what map you are on. 0 would be the world map, 1 the town and 2 the Cave or something.

Story is like what chapter of the game you are on. Everytime you have a meaningful cut-scene or something, increase Story by 1.

Map(63, 63, 3) means that there will be 4 maps of 64x64 tiles (for scrolling Tile engines).

Setup does things like set up the screen mode, load fonts and initiate mouse.

Title is just a LoadPalette call, bload a picture to the screen and wait for a keypress.

Options is a function which determins if you want to start a new game or load an old one. If you want to start a new game it returns 0, otherwise it returns the save number.

InitNewVars sets all the variables to their starting values.

LoadOldVars load a save.

Game is the actual engine.

I trust you could write those subs yourself (bar Game)?

Okay, now lets pretend you were writting a SCRIPT RPG. Your game sub would look like this:

DEFINT A-Z
SUB Game()
	DrawScreen	'Take a wild guess what this does
	DO: A$ = RIGHT$(INKEY$, 1)	'Loads the key that is pressed from the keyboard
into A$
		IF A$ = "H" THEN MOVEUP		'If the Uparrow is pressed, Call sub MoveUp
		IF A$ = "P" THEN MOVEDOWN	'The same but down arrow and MoveDown
		IF A$ = "K" THEN MOVELEFT	'Left arrow, Move Left
		IF A$ = "M" THEN MOVERIGHT	'I wonder...
		IF A$ = " " THEN STATS		'Display players Health and stuff.
		IF A$ = CHR$(27) THEN QUIT	'End the game
		IF A$ <> "" THEN INTERPRET: DRAWSCREEN	'Interpret the script and draw the
screen.
	LOOP
END SUB

Okay...
A summary of what the called subs do as follows:

DrawScreen-Draws the screen
MoveUp-Checks if the square above is empty, and if it is moves you to it.
MoveDown-Checks if the square below is empty, and if it is moves you to it.
MoveLeft-Checks if the square to the left is empty, and if it is moves you to it.
MoveRight-Checks if the square to the right is empty, and if it is moves you to it.
STATS-Clear the screen and show something like this:
Stats screenshot from Final Fantasy 3 for SNES.
Goddamnit! I could have explaned half this article with pictures! Why did I just think of it now?
QUIT-Asks they player if they want to quit and if they say yes, ends the program.
INTERPRET-The script part of the game, and guess what? I'm not going to explain scripts to you! Ha ha! You're going to have to download QBTM and read the tutorials there! Ha Ha!! You loose!! Ha Ha ha ha...ha....HA HA!

Now, if you were writting a BASIC orientated engine your Main Module would look exactly the same as above, and the subs, except for game, would do exactly the same things.

Game would look like this:

'-------------------
DEFINT A-Z
SUB Game()
	DrawScreen	'Take a wild guess what this does
	DO: A$ = RIGHT$(INKEY$, 1)	'Loads the key that is pressed from the keyboard into A$
		IF A$ = "H" THEN MOVEUP		'If the Uparrow is pressed, Call sub MoveUp
		IF A$ = "P" THEN MOVEDOWN	'The same but down arrow and MoveDown
		IF A$ = "K" THEN MOVELEFT	'Left arrow, Move Left
		IF A$ = "M" THEN MOVERIGHT	'I wonder...
		IF A$ = " " THEN STATS		'Display players Health and stuff.
		IF A$ = CHR$(27) THEN QUIT	'End the game
		IF A$ <> "" THEN CheckStuff: DRAWSCREEN	'Interpret the script and draw the screen.
	LOOP
END SUB
'-------------------

All the subs listed in that block do the same as they did in the one above, except for "CheckStuff". The CheckStuff sub should look like this:

'-------------------
DEFINT A-Z
SUB CheckStuff
	IF STORY = 0 AND X = 12 AND Y = 2 THEN CUT1: Story = 1
	IF STORY = 0 AND X = 13 AND Y = 6 THEN CUT2: Story = 1
	IF STORY = 1 AND X = 44 AND Y = 2 THEN CUT3: Story = 2
	IF STORY = 2 AND X = 3 AND Y = 16 THEN CUT4: Story = 3
	IF STORY = 3 AND X = 12 AND Y = 7 THEN WIN: System
END SUB
'-------------------

Cut1 to 4 are just anamations and talking between characters, while WIN is the complete game screen. You can write a Cut sub however you want, you could even use GOTO in it (Fawning, hot, sexy redhaired french-girl: OOOoooo-He's so brave:-)!

CHAIN Orientated

Now CHAIN Orientated games get their name because every part of the map (like shops, towns and dungeons) are ALL seporate files full of QB code, that are linked together by CHAIN commands. I said these are fun to make because you can have a group of 12 or so people and have each person make one part of the game, stick all the files in one folder and run it. It's soooo funny seeing the different graphics styles in one game. And the different ways the character looks. Try it.

Now the way these games are structured is quite different:

You have a folder containing files like these:
INIT.BAS
TITLE.BAS
LOADSAVE.BAS
NEWGAME.BAS
OPTIONS.BAS
VILL1.BAS
VILL2.BAS
WORLD.BAS
CASTLE.BAS
SHOP.BAS
FIGHT.BAS
INN.BAS
WIN.BAS
DIE.BAS
SAVE.BAS

Each of these files contains different aspect of the game.
INIT setup the screen mode, and commons all the variables, then CHAINs to TITLE.BAS.
TITLE bloads the title screen and wait for a key to be pressed, then CHAINs to OPTIONS.BAS.
OPTIONS gives the player a choice then either CHAINs to NEWGAME.BAS or LOADSAVE.BAS.
NEWGAME sets all variables to their default and CHAINs to VILL1.BAS
LOADSAVE load the variables from a file and CHAINs to the last file the player was in.
VILL1 has got the drawscreen, movement and cutscenes for the first village, when you leave the village it CHAINs to WORLD.BAS, when you enter a shop it writes "Vill1.bas" to the end of a datafile, and CHAINs to Shop.
When you leave the shop the "Vill1.bas" is read from the end of the Datafile, and Vill1.bas is chained to.

Do you get the picture of how these work? Do you see why my insane anarchistic mind finds them so funny? Do you? DO YOU?! Well I don't give a shit, because now I'm talking about SUB ORIENTATED GAMES!

SUB Orientated Games

These are for VERY simple, Town & Dungeon RPGs. The Main looks somewhat like this:

'-------------------
DEFINT A-Z
DIM SHARED HP, MP, MHP, MMP, ST, DF, GOLD, X, Y, LOCATION, STORY
DIM MAP(63, 63, 3)
SETUP
TITLE
A=OPTIONS
IF A = 0 THEN
	INITNEWVARS
ELSE
	LOADOLDVARS A
END IF
VILLAGE
SYSTEM
'-------------------

Look familiar? It should. As you can see, most RPGs have the same BASIC setup, it's whats inside the subs that make the difference. We could learn alot from the RPG, for example, many people look the same. Some are black, some are white, but everyone is different inside, and it's whats inside that makes the difference.

Basicly, the village sub holds movement code, has a drawscreen subroutine and calls the shops when they are needed. If you walk on a certain spot, it calls the Dungeon Sub. This sub is practicly the same as the Village sub, except it has random fights. When you walk on the exit from the Dungeon, EXIT SUB is called. Simple.


Well thats all for now. Next month (or two if QBCM goes Bimonthly) I will talk about the different engines for RPGs out there.

Be Excellent to each other...

This is the last surviving member of the <insert name of alien 1 ship here>, matt2jones, signing off...

email me at Matt2jones@yahoo.com.

Goto my webpage at http://members.nbci.com/matt2jones/

RPG tip of the Month: When writting an RPG, don't use any methods you have never tried before because they will slow procuction as you figure them out, and might even cause you to drop your project if you can't get it to work.