Archive

Posts Tagged ‘Platform game’

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

January 4, 2014 5 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…

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 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…

2D Platform Games Part 7: Player Character Animation

January 28, 2013 4 comments

IMPORTANT! All of the articles in this series require you to have either Visual Studio 2010 or the Visual C++ 2010 Redistributable Package (4.8MB) installed in order to be able to try the pre-compiled EXEs provided with the examples. The Redistributable Package can be freely bundled with your own applications.

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 6: Creating Platforms and Geometry the Player can be Inside (Ladders, Ropes and Water). 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. A sprite sheet of our player. This is a 160x160 sprite containing 4 rows of 20x40 player sprites at 8 columns each. The first row of sprites represents the player walking left, the second row represents the player walking right, sprites 1-3 on the third row represent the player jumping left, sprites 4-6 on the third row represent the player jumping right, and the fourth row represents the player climbing up or down a ladder.

Figure 1. A sprite sheet of our player. This is a 160×160 sprite containing 4 rows of 20×40 player sprites at 8 columns each. The first row of sprites represents the player walking left, the second row represents the player walking right, sprites 1-3 on the third row represent the player jumping left, sprites 4-6 on the third row represent the player jumping right, and the fourth row represents the player climbing up or down a ladder.

After the trauma of player physics, collision detection and surface dynamics it’s probably a good time to take a little breather and tackle a less vexing subject, that of animating your player. We shall look at how to animate the player as they walk left and right along a normal platform or slope, when they jump, and when they climb or descend a ladder. This covers all the types of animation we need so far in our project, and gives a flavour of the maths involved which should make it easy to adapt to new animations as and when you need them.

Read more…

2D Platform Games Part 6: Creating Platforms and Geometry the Player can be Inside (Ladders, Ropes and Water)

January 28, 2013 7 comments

IMPORTANT! All of the articles in this series require you to have either Visual Studio 2010 or the Visual C++ 2010 Redistributable Package (4.8MB) installed in order to be able to try the pre-compiled EXEs provided with the examples. The Redistributable Package can be freely bundled with your own applications.

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 5: Surface Dynamics (slippery and sticky 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.

Introduction

So far all the geometry in our game world has followed the same rules:

  1. You can stand on top of a platform
  2. You can’t be inside a platform, and if you would be, you are moved away from it (all platforms are solid)
  3. You can only move left and right, and jump
  4. You can always jump (as long as nothing is in the way)
  5. The platforms can be at any angle but you can only walk up slopes of a certain maximum gradient dictated by the force of gravity
  6. The physics model of the player changes depending on the type of surface (platform) being stood on
  7. The physics model of the player when in mid-air remains the same as the last platform that was stood on

Some items we may want to add to the game world do not follow these rules. Consider ladders, ropes and bodies of water:

  1. You can be at any position inside them
  2. You can move up and down at constant velocities (therefore, gravity should not apply while inside the object)
  3. You should not be able to jump when inside the object (for ladders and ropes however, you should be able to jump away from the object)
  4. The physics model of the player after leaving the object should not be the same as when the player was inside it
  5. Some types of object should not be able to be stood on top of (ropes and water), others should (ladder)

Enabling geometry to work in this way obviously requires some significant changes to our collision detection and resolution model, and some changes to how the player physics work. Read more…

2D Platform Games Part 5: Surface Dynamics (slippery and sticky platforms)

January 21, 2013 4 comments

IMPORTANT! All of the articles in this series require you to have either Visual Studio 2010 or the Visual C++ 2010 Redistributable Package (4.8MB) installed in order to be able to try the pre-compiled EXEs provided with the examples. The Redistributable Package can be freely bundled with your own applications.

This article builds upon the demo project created in 2D Platform Games Part 4: Moving Platforms and Crush Detection. 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.

So far we’ve covered static platforms and moving platforms and provided accurate collision detection for each. We’ve also started to create a framework which lets us configure the behavioral properties of individual platforms. This puts us in a good position to introduce new types of platforms, like the classic ‘slippery ice’ and ‘sticky’ platforms which are the examples I shall show below. These types of platforms which merely change the movement physics of the player don’t require any changes to the collision detection system, whereas ladders and pass-through platforms (where you can jump onto them from below but are solid on top) do, so we defer these to subsequent articles. Read more…

2D Platform Games Part 4: Moving Platforms and Crush Detection

January 21, 2013 4 comments

IMPORTANT! All of the articles in this series require you to have either Visual Studio 2010 or the Visual C++ 2010 Redistributable Package (4.8MB) installed in order to be able to try the pre-compiled EXEs provided with the examples. The Redistributable Package can be freely bundled with your own applications.

This article builds upon the demo project created in 2D Platform Games Part 3: Scrolling and Parallax Backgrounds. 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.

It’s common for platform games to feature platforms which move from side to side, up and down, or both. While a moving platform is nothing more than a static platform which has its position adjusted each frame, it presents some special problems with respect to handling the player. In this article, we will learn:

  • How to add arbitrary movement to platforms of our choice
  • How to make the player move relative to the platform’s position when standing on it (so that the motion of the player follows the motion of the platform)
  • How to detect whether the player has been squashed or crushed Read more…