Games / How To Create A Computer Game

Editing

Game Iterator

edit SideBar

How To Create A Computer Game

How to Create a Computer Game

This article will show you how to create a full blown computer game for PC. This is not an overview about what you could and should do, but an actual tutorial which guides you step by step to creating a game. And it won't advice you to use one of these obscure game creator tools, but direct you to the real tools, 3D software and programming languages also used by real, professional game developers. Despite all this, this article is for beginners.

1.  Getting all the tools

To create games, you need the tools, software which will simplify the work for you. You need some programming language to program your game, something to create graphics, some editor to create the world of your computer game, something to play back sound of your game, and something which displays the graphics. You can extend this list for example with scripting, physics or networking, but these are the basic components needed by every game. For our tutorial, we choose to use only free but high quality tools which are all downloadable for free.

1.1  Programming Language

Professional computer games are written in a language named C++, so we are using it here as well. C++ is very mighty and can be complicated, but don't fear, it we will keep the complex stuff away. A progamming language is really just like a natrual language like english or german: You just use it to communicate. In this case, we use it to talk to the computer. We do this by typing text such as

  printf("Hello World"); 

which will tell the computer to print the words 'Hello World' on the screen. This text written in this programming language needs to be translated into the real, native language of the computer, and this is done using a compiler. To simplify all this text typing and the usage of the compiler, there are tools which can help us, they are called an IDE, for Integrated Development Environment. So we only need to download an IDE for C++ with a compiler in it:

Go to Codeblocks.org and download the Code Blocks IDE. If you are using Windows, select Code::Blocks IDE, with MINGW compiler. After you have downloaded it, install it by double clicking the thing.

1.2  3D World and Level Editor

To design a game world and levels, we need a world or level editor. All cool games today are done in 3D, so we need a 3D editor. Even if we would prefer to create a 2D game only, 3D game tools can help: You only need to change the camera perspective (named orthogonal) and a 3D game looks like it is a 2D game.

The 3D editor we are using in this tutorial is named irrEdit. irrEdit is free and pretty extensible, so just what we need. Download it (use version 0.7.1 for this tutorial if possible), and unzip its archive to a place of your preference.

1.3  3D Engine

A 3D engine is a programming library which makes it easier to draw 3D worlds on the screen for programmers. Directly talking to the graphics adapter and telling it to draw single triangles is much too complicated, so we prefer to use a 3D engine to tell it to draw cool animated monsters and similar. In this tutorial, we a the popular free and open source 3D engine named Irrlicht. Just download the Irrlicht Engine SDK in a latest version (version 1.3.1 preferred for this tutorial), and unzip it in a path of your choice.
The irrEdit 3D Level editor you've downloaded before is the perfect editor for this engine too.

1.4  Audio library

Games without sounds a pretty boring, so we also need an audio library, to play back our sound effects and maybe even sound mp3 music, we need an audio library. Just like a 3D engine with graphics, it simplifies the output of sound for us.
In this tutorial, we are using irrKlang, a free audio library which is compatible with our previously selected tools, irrlicht and irredit. Go and download it (version 1.0.2 preferred for this tutorial), and unzip the archive somewhere on your harddisk.

2.  Creating your game and game world

2.1  Setting up a 3D scene

Once you have downloaded and installed all the tools as described in the previous section, the first thing you should do is to design your game world. To do this, start irrEdit, the editor you should have downloaded already. What you see there will look like this:


irrEdit, how it looks like when started

You can use this editor to design your game world freely. Just place some animated meshes, boxes, particle effects or whatever in the 3D world. If you don't have any animated 3D models, you can download them from the internet or create you own ones using various 3D modeling programs. But to play around and test this out, you can use some of the models wich come with irrEdit or the Irrlicht engine, simply select File -> Import -> Animated mesh:


import an animated mesh into irrEdit

The default directory which is selected already contains a useful animated file, try the file 'dwarf.x', for example. Or you could try the media directory in the Irrlicht Engine SDK. After you imported the file dwarf.x, the editor should look like this:


irrEdit after importing the animated mesh dwarf.x

You can move the dwarf freely by clicking and dragging the yellow, blue and red arrows. An animated dwarf and that bux is enough for now, you can design your 3D world later in detail. Just save your file now. Press File -> Save and name it 'game.irr'. The file will then be saved in the folder 'scenes' in your irrEdit installation.

2.2  Displaying the scene in your game

After you created a 3D game world or at least something which could grow into a game world, you now need to write the actual game: Code which displays the 3D scene and add some gameplay: Define what the game should do when you press a key and so on. To do this, you need to write some C++ code, so start up the CodeBlocks IDE.


CodeBlocks after starting up

You need a new folder where you can place all your game code in, so go into the directory where you unzipped the irrEdit editor, and create a new folder named 'mygame' in there:


Creating the directory where the game code will be placed in

In CodeBlocks, create a new project by selecting File -> New Project and select the 'Console Application' there. Then, press 'Create'. CodeBlocks will ask you where to save the project. Select the directory you created before and some name, probably 'console' or 'mygame', just like you wish. You will have an empty console project then, and after you navigate to the main.cpp file in the Management browser on the left, it will look like this:


CodeBlocks after creating the new project and selecting the main.cpp file

The window in the right part shows some code. Simply erase it and replace it with the following code:

#include <irrlicht.h>
#include <iostream>
#include <direct.h>
using namespace irr;

IrrlichtDevice* Device = 0;

class EventReceiver : public IEventReceiver
{
public:
 virtual bool OnEvent(SEvent event)
 {
   // close app when user presses escape

   if(event.KeyInput.Key == KEY_ESCAPE)
   Device->closeDevice();

   return false;
 }
};

int main()
{
 chdir(".."); // change to the main irredit directory

 Device = createDevice(video::EDT_OPENGL, 
                       core::dimension2d<s32>(640, 480));

 EventReceiver receiver;
 Device->setEventReceiver(&receiver);

 Device->setWindowCaption(L"A Game");

 scene::ISceneManager* smgr = Device->getSceneManager();

 smgr->loadScene("scenes/game.irr");
 smgr->addCameraSceneNodeFPS(); // create fps camera

 Device->getCursorControl()->setVisible(false); 

 while(Device->run())
   if (Device->isWindowActive())
   {
     Device->getVideoDriver()->beginScene(true, 
                 true, video::SColor(0,200,200,200));

     smgr->drawAll();
     Device->getVideoDriver()->endScene();
   }

 Device->drop();

 return 0;
}

This code loads and displays the created game.irr file, as you can read in the line

 loadScene("scenes/game.irr");

We only would need to let the compiler translate it into machine code so we could run it, but we first need to adjust some few settings before this:

In CodeBlocks, use Build -> Compiler Settings -> Linker, to add the lib\Win32-gcc\libIrrlicht.a file which is located where you extracted the Irrlicht Engine SDK:


add the libIrrlicht.a to CodeBlocks.

And additionally, you need to add the include files in the same dialog on the 'Directories' tab:


add the include directory to CodeBlocks.

That's all. Now only press Build -> Run or hit Ctrl-F10 and the compiler will build your code and try to run the application. Unfortunately, it needs a file named Irrlicht.dll to be able to start the game, so just copy the Irrlicht.DLL file from the place where you extracted the Irrlicht Engine SDK from the folder bin/Win32-gcc to the folder where your game is, the 'mygame' folder in this example.
Then, as result, you will see your 'game' in action, showing the 3D scene you created in irrEdit:


your game in action

Congratulations, your game application is running. You just finished the first step to create your own game. In the second part of this tutorial, you will see how to refine the code to make it more interactive and how to add sound to it.

Read on Tutorial Part 2

Or add a comment: Comments on article 'How to create a Computer Game'


Related pages

Recent Changes (All) | Edit SideBar Page last modified on November 08, 2007, at 12:44 PM Edit Page | Page History
Powered by PmWiki