18.2 Games with walls

In many games, like PacMan, the critters are limited to move within the corridors of a maze. How can we implement this?

The simplest approach is to just put in a number of cCritterWall objects and let the critters bounce off the walls. Use as few walls as possible so as to keep down the number of pairs that you'll be processing in your collision-checking ? that is, use one long wall in preference to two short walls butted together end to end.

The speed of the Pop Framework is indeed sufficient to handle worlds with little wall mazes such as PacMan.

The Dambuilder sample game isn't really a game, it's more of a starting point. We'll have a couple of exercises on it below (Exercises 18.1 and 18.2).

For a more Doom-like adventure game experience, you want a world with halls, doors, and rooms. It would be reasonable to make a slightly sophisticated cMaze object which contains some other classes (like perhaps cRoom ) that use cVector points to specify a maze. To implement a particular maze, you'd first draw it on graph paper marked off to be the same size as your _border, and then you'd have your game constructor make a cMaze based on these numbers. And then in the seedCritters call you could perhaps call a cMaze::install(cGame *game) method that would place cCritterWall objects in place to match the coordinates of the maze. You might find a way to use the cMaze to cut down on the number of critter-to-wall collisions you worry about.

The Dambuilder game in 2D view


It's possible to make a completely different kind of wall game based on the traditional wooden game known as Labyrinth. In this game, you have a ball in a maze that has holes here and there in the floor. Your task is to gently roll the ball through the maze without falling into one of the holes. To design this game, you need a cCritterHole class and you need a new cListenerTipper listener for the player that lets you adjust the acceleration in the x or y directions by using the arrow keys. More about this in Exercise 18.8.

Dambuilder in 3D view and Ride the Player mode can serve as starting point for a first-person shooter game


    Part I: Software Engineering and Computer Games
    Part II: Software Engineering and Computer Games Reference