Archive

Posts Tagged ‘Graphics’

2D Platform Games Part 3: Scrolling and Parallax Backgrounds

January 21, 2013 6 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 2: Collision Detection Tweaks. 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.

While it is perfectly acceptable to have a platform game with each level or section based on a single screen, some games require a larger world, and to display this we need to allow the world to scroll (from side to side, up and down or both) on-screen. In this article we will learn how to add scrolling to our project, as well as so-called parallax backgrounds which are background images which also scroll, but slower than the foreground level, giving a “2.5D” impression of depth. Read more…

Advertisements

2D Platform Games Part 1: Collision Detection for Dummies

January 18, 2013 42 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.

Try the demo! This article will teach you how to write the following sample project from start to finish: 2D collision detection demo (use the left and right arrow keys to move and the space bar to jump)

Since the one-day game coding challenges of SimpleTetris and SimpleAsteroids, several people asked me if I could do a timed challenge to make a Mario or Donkey Kong-style platform game. For shame, I haven’t had chance to do this yet, but while I’ve been thinking about that I thought it might be nice to look at how collision detection works, as this is surely the trickiest part of coding a 2D platform game.

Now, let’s not beat about the bush: collision detection is a nightmare when done right. There are many types of 2D platform game, from strictly grid-based to Mario-style platformers where collision detection is simplified by limiting the game world to using certain specific types of platform at certain specific slope angles, all the way to modern games like LittleBigPlanet where the world is completely free-form with arbitrary platform geometry.

There are some brilliant articles on 2D collision detection on the net and I have linked to my favourites at the end of this article. The important thing that they have in common is they are either quite theoretical, use a certain degree of non-trivial math to get the job done or do not have complete source code available for free (and the best ones are written in Flash / ActionScript or Java anyway, not C++). Here I would like to present a practical, hands-on approach to 2D collision detection, developing a complete example in C++ from start to finish. We will look at the various problems that crop up and how to solve them. Read more…

Coding Challenge: Write Asteroids in 10 hours or less

June 13, 2012 17 comments

Update 17-Jun-2012: Fixed some typos, the broken formatting in some of the code and the missing types after static_cast and dynamic_cast operators, and updated the code snippets to reflect two bug fixes.

Update 18-Jun-2012: Wrote the final section regarding the implementation of shields and waves.

The sun is shining brightly, it’s nice and warm outside and unbearably hot in the office, I didn’t manage to fall asleep til 7 this morning and people are asking me to go to the beach. This, of course, can only mean one thing: it’s time for another coding challenge!

Last time we managed to rattle through Tetris in a smooth 7 hours 59 minutes. Reader Jez Ward has upped the ante by issuing a challenge to write Asteroids in 10 hours or less. This is significantly more complex than Tetris for a few reasons:

  1. It’s a free-form game world and not a grid, which requires the use of per-pixel collision detection
  2. The ship has to accelerate and move in a way that roughly resembles basic physics
  3. The ship and asteroids do not have rectangular shapes but are irregular geometric constructions

…all of which basically means that significant portions of the game have to be engineered using different techniques to Tetris, which I thought made it a good 2nd-stage challenge for beginning game programmers to follow along with. Read more…

Coding Challenge: Write Tetris In 8 Hours or Less

May 22, 2012 19 comments

UPDATE (next day): You can read the postmortem report here!

Can I write the entire game of Tetris in 8 hours or less using my Simple2D wrapper library? Let’s find out. I’ll update this blog as I go! Read more…

Installing Simple2D and Compiling your first application

May 21, 2012 34 comments

Simple2D is my graphics library for students and beginners looking to experiment with drawing 2D graphics in C++ in the simplest possible way. It is based on the Direct2D API but removes almost all of the complexity. This article contains instructions on installing the software and all of the extras it requires, and shows how to compile your first program using Simple2D.

Read more…

Pages: 1 2 3

%d bloggers like this: