TEST 2 – Level builder

Prince of Persia

In this post I will try to explain how the levels are constructed in Prince of Persia. This information is very well explained in the technical documentation linked in the previous post and in the Prince of Persia Specifications of File Formats document by the Princed development team.

Basically each level is composed of a maximum of 24 rooms. Each room is constructed with 30 tiles (10 tiles for each of the three stages). Each tile is identified with a code representing its type: floor, wall, door, torch… In addition, each tile has a modifier that lets you define certain aspects as the object (eg, walls decoration or activation of doors when you step over plates). Each level also contains other information that allows linking the room, defines guard’s position and strengh, prince’s initial position, and so on…

The level builder must take into account two important things:

1. Due to the unique perspective of the rooms, these should be drawn from left to right and bottom to top. In addition, the tiles must be overlaped so that new tiles hide parts of previous tiles.

2. For the dungeon levels, Jordan implemented an algorithm that allowed, from a reduced tileset, generating different types of walls giving a sense of variety to the rooms. Basically the algorithm constructs the walls from a basic block and then applies a design modifier according to the position of the tile on the screen. Very clever! In my case, for simplicity, I have not implemented this algorithm, but I’ve just created a spritesheet with all possible designs walls (not many).

First room of level 1

First room of level 1

Finally, with all this information, I built a json file for each level that allows me to build automatically every room. This json is generated from the xml file exported by apoplexy, a level editor for Prince of Persia 1 and 2.

The result can be seen here, you can navigate through the first level moving between rooms with the cursors keys. As an added bonus I implemented the animations for torches and potions.

For the next post I will try to delve into the shadowy world of collision detection… arghhh!

Advertisements

3 thoughts on “TEST 2 – Level builder

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s