UFO game guide using the Welcome to the 2Dgame guide using the Orx Portable Game Engine

My aim for this tutorial is to take you through all the steps to build a UFO game from scratch.

The aim of our game is to allow the player to control a UFO by applying physical forces to move it around. The player must collect pickups to increase their score to win.

I should openly acknowledge that this series is cheekily inspired by the 2D UFO tutorial written for Unity.

It makes an excellent comparison of the approaches between Orx and Unity. It is also a perfect way to highlight one of the major parts that makes Orx unique among other game engines, its Data Driven Configuration System.

You'll get very familiar with this system very soon. It's at the very heart of just about every game written using Orx.

If you are very new to game development, don't worry. We'll take it nice and slow and try to explain everything in very simple terms. The only knowledge you will need is some simple C++.

I'd like say a huge thank you to FullyBugged for providing the graphics for this series of articles.

What are we making?

Visit the video below to see the look and gameplay of the final game:

Getting Orx

The latest up to date version of Orx can be cloned from github and set up with:

git clone https://github.com/orx/orx.git

Once cloning has completed, the setup script in the root of the files will start automatically for you. This script creates an $ORX environment variable for your system. The variable will point to the code subfolder where you cloned Orx.

Why? I'll get to the in a moment, but it'll make your life easier.

The setup script also creates several projects for various IDEs and operating system: Visual Studio, Codelite, Code::Blocks, and gmake. You can pick one of these projects to build the Orx library.

Building the Orx Library

While the Orx headers are provided, you need to compile the Orx library so that your own games can link to it. Because the setup script has already created a suitable a project for you (using premake), you can simply open one for your chosen OS/IDE and compile the Orx library yourself.

There are three configurations to compile: Debug, Profile and Release. You will need to compile all three.

For more details on compiling the Orx lbrary at: http://orx-project.org/wiki/en/tutorials/cloning_orx_from_github at the Orx learning wiki.

The $ORX Environment Variable

I promised I would explain what this is for. Once you have compiled all three orx library files, you will find them in the code/lib/dynamic folder:

orx.dll

orxd.dll

orxp.dll

Also, link libraries will be available in the same folder:

orx.lib

orxd.lib

orxp.lib

When it comes time to create our own game project, we would normally be forced to copy these library files and includes into every project.

A better way is to have our projects point to the libraries and includes located at the folder that the $ORX environment variable points to (for example: C:\Dev\orx\code).

This means that your projects will always know where to find the Orx library. And should you ever clone and re-compile a new version of Orx, your game projects can make immediate use of the newer version.

Setting up a 2D UFO Project

Now the you have the Orx libraries cloned and compiled, you will need a blank project for your game. Supported options are: Visual Studio, CodeLite, Code::Blocks, XCode or gmake, depending on your operating system. Once you have a game project, you can use it to work through the steps in this tutorial. Orx provides a very nice system for auto creating game projects for you. In the root of the Orx repo, you will find either the init.bat (for Windows) or init.sh (Mac/Linux) command. Create a project for our 2D game from the command line in the Orx folder and running: init c:\temp\ufo or init.sh ~/ufo Orx will create a project for each IDE supported by your OS at the specified location. You can copy this folder anywhere, and your project will always compile and link due to the $ORX environment variable. It knows where the libraries and includes are for Orx. Open your project using your favourite IDE from within the ufo/build folder. When the blank template loads, there are two main folders to note in your solution: config

src Firstly, the src folder contains a single source file, ufo.cpp. This is where we will add the c++ code for the game. The config folder contains configuration files for our game.

What is config?