Back to Top

Learn escape games programming

Working with maps

maps

Many computer-based escape games make heavy use of maps. Here are the key coding elements that are required to create various types of maps.

Everything begins with a VIEW, a window that allows us to look at the game from any position (x, y, z) and angle (pan, tilt, roll) we want to. Maps that make use of VIEW elements can help us create "real" 3D maps, which allow us to follow the player, display a static or dynamic section of the virtual world, etc.

Here's how a VIEW definition looks like; don't worry, we'll discuss each line of code.

VIEW* TopView =

{                

layer = 10;

The layer value allows us to specify which views (maps) can be placed on top of each other, or on top of other world elements. This may come in handy if you want to place a border around your TopView map by using a panel that's got a layer of 15, get it?

pos_x = 10;

pos_y = 10;

The pos_x and pos_y variables set the x and y coordinates of the VIEW; the upper left corner of your screen has the (0, 0) coordinates. My recommendation is to keep the map in one of the screen corners, unless you are temporarily using a full-screen map to show the game players a lot of info at once.

size_x = 128;

size_y = 128;

We also need to set the size of our VIEW; I have defined one that's got 128x128 pixels in the example above, but you can use any size you need, as long as it doesn't exceed the screen resolution.

It is important to know that each additional VIEW is, in fact, a fully rendered 3D game view, so it uses additional CPU resources. So, to keep frame rate high, you need to limit the size of the VIEWs, especially if you plan to run your escape game on low-end hardware.

arc = 45;

The arc value sets the camera angle for the current view. Action game creators use another name for "arc", calling it "field of view". By playing with "arc", you can show more or less from the world; it's as if you'd zoom in or out, if you will.

ambient = 100;

Since VIEWs are camera renders, they've got their own ambient parameters. So, you can make your 3D map look brighter or darker than the rest of the level by playing with its "ambient" value.

flags = SHOW;

The last line of code in the VIEW definition displays our 3D map. Most real-life games utilize a toggle button to show/hide the VIEW. To make your game harder, you shouldn't allow the player to keep the map on at all times; use a battery-powered map of the level, for example.

}

Okay, so now that we've examined a typical VIEW/map definition, how do we use one in our games? Your project will need to utilize a function that moves the player, of course, so let's assume that you've got one that uses the "player" pointer for player's entity. In this case, the example below will do a good job, using our previously defined TopView that follows the player at all times, being placed 500 units above it and looking down at it (its tilt angle is set to -90 degrees).

function TopMap ()

{

while (!player) {wait (1);}

TopView.tilt = -90;

while (1)

{

vec_set(TopView.x, player.x);

TopView.z += 500;

TopView.pan = player.pan;

wait (1);

}

}