Shopping Cart 0 items - $0.00 0
Shop

Game engine

Intro


There are numerous game engine on the market that have flashy names like Unreal Engine, Unity or Frostbite. But what is a game engine anyway? To understand this concept we have too look at a simple game first.

From simple games to game engines

We start with the simplest and oldest video game out there: PONG
Now back in the days when Pong was developed it was made completely different then on todays computer with partly analog circuits and without a microprocessor. In this article we have a glimpse on the game in C#, the high level programming language that is also used in Unity.


Gamecode structure

If you take a look at the picture above you can see what is needed for a game like this:
* A Window that draws the Objects
* A Ball with a certain velocity changes direction when it collides with the Player object
* Two Player Objects that are moveable with keyboard Inputs
* Ball reset when it collides with the left or right wall
* Top and Bottom “wall” collision
* A Score to tell which Player is leading
* A line in the middle for visual orientation

…. and that’s basically it. A small game doesn’t need an impressive engine, not even a good structure.
Heck you can even write everything in a one file!



First you have all the variables or for non programmer the “parameters” of the game. You can change the font, ball position or current fps in the file.
Then the game logic or the verbs of the game come into play. Programmers call this methods. It contains all the information how the magic behind the game works like when the ball collides with Player.
Lastly we have the main method. This is the “main menu” of the game that brings all methods and variables in the right order together. The program starts here.

Everything in this game is written in a single class which is a big no no when it comes to good programming.
It’s hard to reuse parts of the code if you want to develop a new game. This is not game engine!
But for now let’s continue to a more complex game.

Tiny Game Engine

This was a Gamejam Game that I wrote during university. You shoot the ball and the ball has to hit all yellow objects (golems). There are different Objects that affect the game like the red boxes that has to be broken trough with a certain speed.


The game got a little more complex than Pong so it was needed to divide it into 6 classes.
The main aspect of this game is the Level editor. If you watch closely you see the pink circles in the array (data table) that represent an Object (here called 7 = RightBlock). That’s already impressive because you could start building whole levels!
What if you want to make Editor more convenient so that you can just drag and drop the items into the table?
Or read the numbers out of file so you can change levels with your collogues?
What if you want to use this array to create a side scroller? (yes this is the start of a side scrolling code)

In contrast to Pong this simple level editor is already a tiny game engine! You can reuse part of the code for different games. We are on something so let’s continue now with the real engines… 🙂

Game Engine