Archive

Archive for the ‘Game Development Walkthroughs’ Category

2D Platform Games Part 12: A Framework for Interactive Game Objects

January 4, 2014 4 comments

IMPORTANT! To run the pre-compiled EXEs in this article, you must have Windows 7 Service Pack 1 with Platform Update for Windows 7 installed, or Windows 8.

This article builds upon the demo project created in 2D Platform Games Part 11: Collision Detection Edge Cases for The Uninitiated. Start with 2D Platform Games Part 1: Collision Detection for Dummies if you just stumbled upon this page at random!

Download source code and compiled EXE for the code in this article as well as the complete source code and compiled EXE for the level editor.

We’ve spent a lot of time adding different types of platforms and collision detection behaviour to our project, but of course the real meat of any platform game is in the objects you can interact with like coins, baddies, levers and switches and so on.

Goals and Terminology

Over the next 5 parts of this series, we will build a framework in which we can place interactive game objects like enemies and collectibles, and look at all the complexities of this topic which must be tackled for a complete working implementation, including:

  • Defining a class hierarchy for interactive game objects (which I’ll call game entities from hereon to differentiate them from actual C++ objects and platform geometry and instances) (Part 12 – this article)
  • Handling the movement logic of static game entities (those which do not move in the game world), game entities with pre-defined paths (for example enemies which move backwards and forwards in a fixed pattern) (Part 13) and game entities which can move around the game world of their own accord under the rules of physics we have already defined (which I’ll call free-roaming) (Part 14)
  • Handling animation of game entities with a unified animation function (for example, changing the sprites used for animation depending on the direction the game entity is travelling in) (Part 13)
  • Unifying the collision processing code for entity-platform, entity-entity and player-entity collisions (Part 14, Part 16)
  • Allowing entities to have custom behaviour on collisions with other entities, platforms or the player (for example, making a coin disappear and adding its value to the player’s score when the player collides with it) (Part 16)
  • Unifying the internal representation of the game world to simplify the code and make it more easily extensible (Part 16)

We will also review the collision detection code and go through some really tricky edge cases that only come up when non-player game entities are added to the world, in Part 15.

Finally, I shall also present a new level editor which will allow you to place game entities and modify their properties, in turn giving way to a new level definition format for our level files (the level editor also contains a lot of other minor improvements and bug fixes). Read more…

Advertisements

Tetris: Adding gamepad support

August 30, 2013 4 comments

In this article, we will look at how to add gamepad support to a game using our Tetris clone as an example.

Simple2D 1.11 includes gamepad support using XInput – the new replacement for DirectInput in DirectX 11 – and makes it ridiculously easy to add support to existing games as we shall see here. If you would rather code everything yourself and want the nitty gritty, check out my 2-part mini-series XInput Tutorial: Adding gamepad support to your Windows game for the low-level details.

Download (SimpleTetris 1.5): Source code | Executable

Read more…

Tetris: Adding polish with music, sound effects, backgrounds, game options, an intro sequence and other tweaks

March 15, 2013 2 comments

Our previous version of SimpleTetris is working quite well as a single-player game, but lacks the professional touch. In this article, we’ll look at:

  • how to make pausing and unpausing the game also pause and unpause all of its subsystems
  • how to add music and sound effects and tie them into game events with SimpleFMOD (a library developed in another series on this web site which uses the well-known FMOD SoundSystem to produce audio – see the first part of the FMOD series for more information on how to use FMOD)
  • how to make an event-triggered throw-away animation using Simple2D
  • how to use bitmap images (sprites) as animated backgrounds
  • how to add game options which can be loaded and saved
  • how to add an intro sequence and a credits page

Most of these changes can be slotted in without any changes to the game logic, but there are a few gotchas and some little tweaks we can apply to make things better. I’ll note these below.

Download (SimpleTetris 1.41): Source code | Executable

For comparison, also have on hand the executable for the previous version of the game (SimpleTetris 1.31).

I strongly recommend that you run both versions and do a side-by-side comparison of the behaviour while working through the sections below, then hopefully the changes described will make sense more easily. Read more…

2D Platform Games Part 11: Collision Detection Edge Cases for The Uninitiated

February 19, 2013 8 comments

IMPORTANT! To run the pre-compiled EXEs in this article, you must have Windows 7 Service Pack 1 with Platform Update for Windows 7 installed, or Windows 8.

This article builds upon the demo project created in 2D Platform Games Part 10: Improved Level Management and Storage. Start with 2D Platform Games Part 1: Collision Detection for Dummies if you just stumbled upon this page at random!

Download source code and compiled EXE for the code in this article as well as the complete source code and compiled EXE for the level editor.

With the ability to create levels easily comes the ability for your colleagues to produce gameplay scenarios you hadn’t thought of, and by consequence reveal a host of tricky bugs in your code. In this article, we shall look at a variety of so-called edge cases – an engineering term meaning things which don’t happen often, or only under a very specific set of circumstances – and how to fix them so they work correctly. The included source code includes a number of levels which demonstrate each problem so you can load them into the code from Part 10 to see how the behaviour compares with the updated code from this article.

Read more…

2D Platform Games Part 10: Improved Level Management and Storage

February 6, 2013 4 comments

IMPORTANT! To run the pre-compiled EXEs in this article, you must have Windows 7 Service Pack 1 with Platform Update for Windows 7 installed, or Windows 8.

This article builds upon the demo project created in 2D Platform Games Part 9: Storing Levels in Files / Level Editors. Start with 2D Platform Games Part 1: Collision Detection for Dummies if you just stumbled upon this page at random!

Download source code and compiled EXE for the code in this article as well as the complete source code and compiled EXE for the level editor.

In Part 9 we looked at how to store and retrieve game levels from files in a format that could be used both by the game itself and by an auxiliary level editor application. In this article we will make things a little more robust and usable with some improvements:

  1. Allow the game to load the specified level as a command-line argument
  2. Re-factor all of the level data into a single class so it can be version-controlled and remove duplicate variable declarations in the game and level editor
  3. Add functions to the Platform class to create platforms from the GeometryDefinitions stored in the level files, neatening things up by making them more object-oriented and removing duplicate code from the game and level editor

Let’s get cracking!
Read more…

2D Platform Games Part 9: Storing Levels in Files / Level Editors

January 29, 2013 4 comments

IMPORTANT! From Part 8 onwards, you no longer require the Visual C++ 2010 Redistributable Package installed in order to be able to try the pre-compiled EXEs provided with the examples.

IMPORTANT! From Part 6 onwards, compatibility with Windows Vista in the pre-compiled EXEs has been dropped. To run the pre-compiled EXEs, you must have Windows 7 Service Pack 1 with Platform Update for Windows 7 installed, or Windows 8.

This article builds upon the demo project created in 2D Platform Games Part 8: Pass-through Platforms. Start with 2D Platform Games Part 1: Collision Detection for Dummies if you just stumbled upon this page at random!

Download source code and compiled EXE for the code in this article as well as the complete source code and compiled EXE for the level editor.

Until now we have just used a fairly arbitrary demo level that was hard-wired into our game code. This is neither very flexible nor very fast. It’s hard to create levels, and we also can’t offload that task to other members of our team. The solution, of course, is to make a level editor application which can save levels into files that the game can load.

Figure 1. Basic level editor for our platform game

Figure 1. Basic level editor for our platform game

Now, I can’t show you in one article how to learn Windows or other GUI programming and write a level editor, however we will look at several important topics around this:

  • how to re-factor the way levels are stored in memory so they can be exported to a file
  • how to export a level to a file
  • how to import a level from a file
  • how to add versioning to your level files
  • the basics of what a feature-complete level editor should do
  • sharing common code between the game and level editor applications
  • some tips and code snippets on how to create useful level editing tools and how to make your Windows-based level editor work with Direct2D

Read more…

2D Platform Games Part 8: Pass-through Platforms

January 29, 2013 3 comments

IMPORTANT! From Part 8 onwards, you no longer require the Visual C++ 2010 Redistributable Package installed in order to be able to try the pre-compiled EXEs provided with the examples. Thanks to Dbug for reminding me that libraries can be statically linked 😛

IMPORTANT! From Part 6 onwards, compatibility with Windows Vista in the pre-compiled EXEs has been dropped. To run the pre-compiled EXEs, you must have Windows 7 Service Pack 1 with Platform Update for Windows 7 installed, or Windows 8.

This article builds upon the demo project created in 2D Platform Games Part 7: Player Character Animation. Start with 2D Platform Games Part 1: Collision Detection for Dummies if you just stumbled upon this page at random!

Download source code and compiled EXE for the code in this article.

Figure 1. Rainbow Islands uses only pass-through platforms for the entire game

Pass-through platforms are a type of platform commonly found in video games whereby the player can jump up through the platform from underneath, landing on its solid top surface. The platform behaves like a normal platform in all respects, except that when the player jumps up from underneath and hits it, he/she continues travelling upwards instead of encountering a solid obstacle. Games such as the all-time classic Rainbow Islands and more modern affairs such as the amusing time-waster Monsters (Probably) Stole my Princess! use pass-through platforms exclusively. Read more…

%d bloggers like this: