Who is this tutorial for?
After reading some books and language tutorials you decide that it's time to build something. Well that's great, but what are you going to build? What will it do? What do you need to build it? How long will it take to build? And the biggest question: How will it work?
In this tutorial we will go through step-by-step the development of a complete project that will be the foundation of many more projects to come. We will start with the idea, answering the questions above. After that we will go through the process of designing the program, thinking through all of the important details that all programmers must think about. Finally we will hammer out all of the necessary code to make it work.
Let's get started.
What will we build?
Ok, we want to build something fun and interesting, so we set out to build a simple 2D game. Question, what do most simple 2D games have in common?
That's pretty simple, which is good because after all, we've just read some books and are going to build something with our new-found knowledge. Since these are common properties of simple 2D games, we will build a reusable framework that we can develop many simple 2D games with.
Building and reusing a framework (as we are going to do) greatly simplifies the task of actually developing the game. You don't have to think about all of the tedium of mapping, graphics, and AI because it has been separated and encapsulated.
It is like building a box with buttons, knobs, and switches. We are going build a box that has all of the mechanisms inside that deal with the logic of handling maps, drawing map graphics, and finding paths. On the outside of that box we will have the hypothetical buttons, switches, and knobs to manipulate the maps, pathfinder, and graphics engine. Doing it that way makes it much simpler and easier to use. If we didn't do it, we would be tinkering around inside of it for every game that we build.
We will call it GameFX - The Game Development Framework.
What will it do?
The Game Development Framework (GameFX) is simply a set of libraries to be used as the foundation for any simple 2D tile-based game. It can be used to build games such as PacMan, Snake, Tetris, and even Chess.
Now that we have the basic idea of our project we need to identify its key components. To do this we must divide GameFX's functions up into categories. Then we break each category down into functional components that can be put together to perform the functions of that category. We know that GameFX will handle tile-based maps, graphics, and pathfinding, so we can divide GameFX into those three main categories.
Now we'll break each category down into smaller components to further simplify things. Ok, let's start with tile-mapping. The highest-level functioning unit of tile-mapping is of course the TileMap. What is the basic unit of a TileMap? A Tile. Can a Tile be broken down further? Not really, it would be counter productive to attempt it. What other components are needed in 2D mapping? A coordinate.
Good, we have broken down the first category (tile-mapping) into three functional components that can be put together to preform the functions of tile-mapping.
The next category (graphics) cannot be broken down. We simply have the GraphicsEngine. It works with all three components of tile-mapping to render a graphical representation of a TileMap.
The category of pathfinding is a bit more complex, however it can be broken down similarly as tile-mapping was broken down. First let's learn a little about how pathfinding works so we can figure out how to break it down.
The A* pathfinding algorithm generates and stores nodes that represent coordinates on a map, where each node knows the goal coordinate on the map, and can estimate the cost of movement to that coordinate. The algorithm generates nodes as it gravitates towards the goal coordinate, and links the nodes of the lowest cost (aka shortest path) together to form the path.
With this understanding, we can break down the pathfinding category into these three components. Understand that these all work together with the components that perform the functions of tile-mapping.
We will learn about the A* pathfinding algorithm in more detail after we construct the components of the first two categories.
What do we need to build it?
GameFX will be built using the C# programming language on the .NET 2.0 platform. We are going to use the C# programming language because it provides a good balance between power and simplicity, which is important in educational scenarios such as this. The .NET 2.0 framework is a commonly installed platform that much of today's software is built against. Version 2.0 of the .NET framework comes preinstalled on Vista and later systems and is shipped as an update on earlier systems.
To develop software on the .NET 2.0 platform, at a minimum you will need to download the freely available .NET 2.0 SDK. However, I highly recommend that you choose to use an Integrated Development Environment (IDE). An IDE will greatly simplify the development of larger applications by providing you with a convenient graphical user interface that will enable you organize and deal with your work in a more efficient manner.
If you are looking for a quality IDE that is free, Visual C# 2005 Express Edition (or later version) will fit the bill.
How long will it take to build?
Well that depends on many factors, such as your skill-level, concern for quality, determination, and how well you document your code. For a project of this magnitude, you may spend about a week or two working depending on how many hours a day you set aside for your project.
It shouldn't take that long for us to work through this tutorial though, because I have already designed and built it. We will be walking through the entire process of the development of GameFX from idea to finished product, going through all of the thought process you would normally go through on your own if you were to take on this project by yourself.
In part two of this tutorial, we will start the design and development of the functional components of the TileMap, starting with the smallest fundamental components and then building on top of them.