Thursday, November 24, 2005


Texas Quest Tutorial Part 2: Design Part 1


Part 2: Design of Texas Quest Part 1

I am writing this document as part of the very infrequently updated Texas Quest tutorial series. I suppose I should put “series” in scare quotes there because at this point there is only one entry in the series until now. ;) If you can ignore that, then what I am trying to do here is describe the overall architecture of a side scroller game before getting into more details of the rendering, which was going to be next. The architecture is usually the really fun part anyways, as graphics are, to me at least, quite frustrating (see the previous blog entry, which I did actually figure out eventually).

I am going to assume the reader is familiar with my side scroller game Texas Quest or at the very least games like it such as Mario World, so I am not going to detail their features. Also this guide, while based on Texas Quest and my experience making that game, may of course be used for other side scrollers and maybe even other types of games. In fact that’s why I am writing it, so that someone else making a game will have a good head start. But realize that there are always many many ways to do things in programming, what I detail is one way, not necessarily the best or even quickest either.

I should also mention that Texas Quest is kinda my second side scrolling game. I did another one back in the Winter of 2001 and got pretty far with it until giving up. I developed a lot of the concepts for Texas Quest there, so no one should think I came up with this whole design on a first pass or anything.

Levels

Levels are perhaps the easiest part of a game to design because it is really quite obvious what is needed from them. The reason for that is when you know everything required you can just put something together that does exactly what you need. The design flows from the requirements, especially with the case of levels since they are not too complex. So we start with levels for that reason and for another reason we will detail in a bit.

The level architecture goes as follows: A level has one or more level areas, one of which is the primary or starting area. Other than that a level doesn’t have anything else… except what I like to call a starting script. This is optional, and dependant on how you want to do scripting in your game. But this is the kinda thing that lets you play a little scene when the level starts. So it is neat and adds something special to a game that people expect nowadays. Oh, and when I say scripting I don’t mean a scripting language either, just a script in that it’s a series of predefined instructions. In Texas Quest I just had a few pre-built script classes (e.g. Level3StartScript, Level5StartScript, etc, etc).

Now for level areas. These objects are the maps or areas that you visit and explore in a game. The reason we separate out the maps from the level is that we want a level to have many relatively independent areas to explore, such as in Mario Brothers when you go down a tube you are no just taken to a different part of the level, but a whole new area with its own map. That’s what we are modeling here. A level area has the following components:

I call all active game objects (e.g. not tiles) Characters. So a level area has to maintain a list of Characters and where they start at. Characters can be enemies or items, or neutral things like blocks or really anything else you want, and we will discuss them in much more detail later. What I want to make clear now is that you need a list of them in your level areas that at a minimum includes what the character types, starting locations, and starting information (e.g. for a Question Mark Box character, what it contains). I will detail the way I did this later. Entry points are one end of the links between level areas. They are the exiting end, and the entering end is characters such as pipes or doors. There should also be some way of telling which entry point is the starting one for this area if this is the primary level area for the level. I just use the first entry point in an array but something more elegant could be done as well.

So… next are tiles. Let me say the way I did this in Texas Quest is wrong. I didn’t use a Tile class (actually a Tile struct would be more appropriate anyways if you are using C#). I used three matrixes of tiles. Each matrix is of integers. The integers are indexes into one of three different pseudo-arrays of tiles images. The matrixes are used to draw the map. So one matrix is for the foreground, another for what I call the mainground, and the final is for the background. There is another matrix containing movement information. Its cells are of an enumeration type with three possible values: Freely, StopsAll, JumpThrough, meaning respectively, this tile can always be moved through, this tile can never be moved through, and finally this tile can be moved through when traveling horizontally, or moving up (e.g. jumping).

What you should do is have a Tile class (again struct if you are using C# like I did). It should have an integral type (probably byte or ushort depending on how many tile types you have… byte if you have 256 or less, ushort otherwise (unless you have more than 65 thousand, which is very unlikely I think)) for the background, mainground, and foreground (and other layers if you want them). Each of these should index the same tile image array. Do not use three different tile image arrays like I did in Texas Quest. That’s silly and is bad design ;) Then you should have the same enumeration type I had in Texas Quest, with those three possible values effecting movement through the tile (Freely, StopsAll, JumpThrough). This will make things more clean.

Interlude

Now that you have gotten your level design down, now comes the first hurdle I like to cross: getting a map editor working. This has been a really great way for me to go about games, because I get the first and main round of graphics work done without getting into Character animations or anything, and I can make sure the level architecture works and looks good. I highly recommend doing this before getting into the core Engine part of the game. That may seem more appealing and rewarding, and it probably is, but getting this core work done will help you in the long run.

Characters

OK, now for characters. We are going to cover what attributes make up a character here, without getting into event handling for character interaction toooooo much. But we will touch on some of the basics for it as we detail what makes up a character. As I stated above, characters are all active objects in the game. Pretty much every game object aside from tiles is a character. You (as in me in Texas Quest, or Mario in Super Mario World), enemies, blocks that might break, blocks that interact with the user in any way, coins, other items, and even special effects (like the sparkles that appear after you collect a coin). I am going to list the attributes of characters in three sets: type based, instance based, and a small set describing how a character is added to the map in the level editor.

All characters have a class, such as Tutrle, and that has some attributes with are pretty much constants, such as maximum speed. These are type based character attributes. Characters also have some attributes like location, which changes. Those are instance based character attributes. Pretty simple really. What I did in Texas Quest is create an abstract class called Character that has both sets of attributes defined but not implemented (since they are abstract). That means ever Character subclass has to implement these attributes, and the difference between the two is that the type attributes can be gotten but not set so they should be more like constants. In a previous game I wrote I created a class called CharacterType and a class called Character. The CharacterType class had the type attributes, and the Character class had the instance attributes (plus a reference to the CharacterType class). Then I was even so bold as to make a small scripting language that defined the character types via a rule script file. Such that all the important stuff about the characters was dynamic and built at runtime instead of in the code. It sounds great. But it was toooooooooooo much work. And I got bored with it and let it die eventually. It is muuuuuch easier to build your Character classes at compile-time than at run-time, especially when you get to event handling. So just take my advice here, and if you are working on your first game, do not be too ambitious!

OK, so back on track here are character attributes:

Character Type Attributes

Character Instance Attributes

Character Level Editor Attributes

Wow that’s quite huge huh? I think they are all pretty straight forward and its pretty obvious why they were needed. How I implemented my character classes was to have this base abstract Character class whose attributes I just listed, and then have a ton of concrete subclasses like Turtle, Coin, and Aaron (the main character ;) ). There are some classes between the two (StandardCharacter, Enemy, Item) that are also abstract but provide some common functionality for their subclasses. The line between type and instance attributes is blurred a bit because of this, since the concrete subclasses do not have to return constants from the type attributes. But they for the most part do. Almost all type attributes return constants in all concrete character classes. Instance attributes depend on the character state, so naturally should not.

In addition to these attributes, the Character class also has several abstract methods that I am going to detail here. I want this to be complete so that’s why I am putting these all here, but a large number of the methods relate to event handling and will really be examined better later.

Character Methods

Now like I was saying about the characters and the level editor, the way I did the level architecture, specifically level areas, has each level area containing a list of characters. What I do is add an actual honest to goodness entire character to this list. That entire character is saved with the level. Most games probably use a character-stub for this, and as I said above you could probably get away with just putting a (type, location) into the list for your characters. Until you wanted to do things like set the item in a Question Box. Or set the number of coins in a Coin Bag. Or set the number of hit points of a Turtle. Or a million other things. I found it was just easier to put the whole character into the map so that all attributes can be modified. Then when the map is serialized and deserialzied the character comes with it (in .NET you have to set every character class with the SerializableAttribute before you serialize).

However this leads to the need for the Duplicate method. Once we have loaded a map with its level area’s and characters, we need to create an active set of characters running in the game. But if we use the same characters that came with the map, then when the player die’s and has to restart the level the map has to be reloaded again. To get around that silliness we can just clone every character from the map that should be in the running game when it is started, then if the character die’s or the level otherwise restarts we just trash the running character set and create it again, without having to reload the map.

Interlude 2

That’s quite a lot to digest so before I get any further I am going to take a break. If you have any questions, post them! Ill write the next part of the design soon (soon my time = a month or so probably, sorry :P)


Comments:
Hey Aaron,
Great addition to your tutorial. Is there a way for me to reach you (to chat about game development)?

My email is Isaac.Squires.removethis.@gmail.com.

Thanks,
-Isaac
 
Yep :)
 
This post has been removed by a blog administrator.
 
Very nice! Great tutorial, clear style. I like the hands-on approach you give.
 
Ive just started in c# with the ultimate aim of writing a 2D platformer. Ive found your tutorials extremley informative and well written, hope I dont have to wait to long for the next one! ;)
 
Hi! I like what you are doing. Maybe we could exchange tips on Wellness. You can have a quick look at http://www.wellnessmaster.com so we can exchange ideas.
 
Dear Blogers

Great fallbrook kitchen remodeling advice can be founf at http://fallbrookremodeling.com/Fallbrook-Kitchen-Remodeling.html . We are starting a home improvement site for home remodeling experts and home owners.
 
Hello, I found your blog from the ZMan site. I am working actually on my own version of Zelda II, the Adventure of Link, using the same tools as you did for Texas Quest !!

I started my game based on another tutorial but wasn't able to figure out how to manage game coordinates and the viewport and this kind of thing.

So, I found your game, really, really, good !!! and your tutorial really helpfull.

Alas, it seems like you have passed to something else...

I was also interested by that isometric game if you want to write on it and provide the source code !!

This was to congratulate you, let you know that the work you provided is still used and useful.

I hope everything is ok for you overthere and that love is still in the air...

If you wish, we could discuss a bit more by email...

Cheers from Paris, France !!
Claude
cvernier@hotmail.com
 
companies marketing mineral makeups and also get the best bargains in mineral makeup you can imagine,
find aout how to consolidate your students loans or just how to lower your actual rates.,
looking for breast enlargements? in Rochester,
homeopathy for eczema learn about it.,
Allergies, information about lipitor,
save big with great bargains in mineral makeup,

change edition interviewing motivational people preparing second
,

interviewing motivational people preparing second time
,

interviewing people motivational preparing for a second time
,

black mold exposure
,

black mold exposure symptoms
,

black mold symptoms of exposure
,

free job interview questions
,

free job interview answers
,

interview answers to get a job
,

lookfor hair styles for fine thin hair
,

search hair styles for fine thin hair
,

hair styles for fine thin hair
,

beach resort in the philippines
,

great beach resort in the philippines
,

luxury beach resort in the philippines
,
iron garden gates, here,
iron garden gates,
wrought iron garden gates
, here
,
wrought iron garden gates
,
You: The Owner's Manual: An Insider's Guide to the Body That Will Make You Healthier and Younger
,
answer from more much,
eat eating mindless more than think we we why
,
la times classified,
new york times classified


texturizer,
texturizers here,
black hair texturizer,
find aout how care curly hair,
find about how to care curly hair,
care curly hair,
lipitor rash,
lipitor reactions,
new house ventura california,
the house new houston tx,
new house washington dc,
new house washington dc,
new house ventura california,
the house new houston tx,
the house new houston tx, that you ar looking for,
new house ventura california, you need to buy,
new house washington dc,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

hair surgery transplant
,

air filter allergy
,

refurbished dell laptop computers
,

chocolate esophagus heartburn study
,

chocolate esophagus heartburn study
be informed,

digestion healing healthy heartburn natural preventing way
,

digestion healing healthy heartburn natural preventing way
,
sew skirts, 16simple styles you can make!,
sew what skirts 16 simple styles you


Allergies, lipitor rash,
alcohol rash,
lipitor and alcohol,
lipitor alcohol,

natural remedies to aid healing of esophagus
,

chicory heartburn
,

effectiveness of zocor vs. lipitor
,

chocolate esophagus
,
southwestern wrought iron yard gate,
exterior iron gates,
oriental wrought iron gates,
powder coated iron garden fencing,
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?