The Structure of a Game – Introduction
Inspiration
When I first began programming, it seemed like there were a vast amount of tutorials out there which taught you how to do a specific task such as “make a shooting game” or something of that nature. These were great for me at first, as I didn’t know my left toe from my right thumb. Eventually however, I began to get better and I craved more organized and useful information such as how to actually structure games, and how to use proper OOP techniques etc. There simply just isn’t enough of it out there. I found a few articles explaining several ideas and concepts, and I read many different books on OOP and design patterns…then after about a year of working together the different I came up with a great mesh of it all to develop my current game structure.
Purpose
My purpose for this article and those that follow in this series is to teach you piece by piece how to build a reusable game structure for your games as well as explain different game coding techniques and concepts along the way. I’ll be providing code that I’ve written, however for maximum benefit I recommend that you modify or rewrite it to your style and needs. For example, each time I start a new project I simply copy all of my game code over from my latest game and then delete classes which I won’t need, as well as tweak existing code to fit the current project.
Requirements
It is good practice to write down some goals and requirements for what you would like your game engine to incorporate, so let’s consider this now. Our game structure will have consist of the following:
- The ability to save game state, pause, speed up and slow down
- We can set a camera position and size to render what is in the game world.
- The game logic will be separate from the rendering logic.
- Data driven development. IE: Creatures and levels will be built outside of the core code engine itself, usually from XML or on a higher level in an editor of some sorts.
- Object creation is centered in one location
- Control of entities is done through “controller” classes.
- And of course…it will run incredibly fast.
If any of that sounded complicated, fear not. I will be discussing the reasons for each part as well as explaining how it all works. We will create one piece at a time and build upon the structure as we move along, making improvements along the way.
As I complete each section I will update this article to link to each piece. You may visit the google project page to aquire all of the project files and source code as well.
Additional Articles in this series:
- Building a Foundation For Your Games and Handling Screens
- Game Entities and Objects
- Managing Game Objects and Rendering a Game World
- The Game Factory – How You Should REALLY be creating objects
- Artificial Intelligence – Boids / Steering Behaviors
- AI – Finite State Machines
- More AI – Pathfinding, etc…
- Particle Effects
- Advanced Collision Detection
- Programming UI
- Data Driven Development
- And more…



(5 votes, average: 3.40 out of 5)




Oliver said
am November 10 2008 @ 3:16 am
Thank you.I’ve been waiting for this and can’t wait to read and learn from you.
Whitey said
am November 12 2008 @ 7:48 am
Great! When are the next articles coming?
Dont suppose you could send me a sneak peak?
Oli Dainton said
am December 5 2008 @ 4:08 pm
This is exactly the kind of article I have been looking for. There just don’t seem to be any resources for learning game structure in oop. Look forward to reading the rest. Cheers.
mclelun said
am January 17 2009 @ 6:35 am
Thanks alot! I am always wondering how to structure a game as well. Too many spaceship shooting tutorial on the web :p
Scottae said
am January 25 2009 @ 2:53 pm
This is awesome stuff. I am really enjoying your blog. Thx
Mike said
am September 8 2009 @ 9:40 pm
sweet tutorials man
Keep em coming!
mwshang said
am April 26 2010 @ 2:37 am
thank you very much!
it’s good tutorials!
Francis said
am July 23 2010 @ 9:30 pm
Wow ! This is extremely good information ! There aren’t many articles out there about structuring a solution and this can be very helpful. Thank you !