Tutorial 3 (Indices) - Aerll/rpp GitHub Wiki

About indices

Indices are nothing more than numbers assigned to every tile. They are exactly the same, as the ones, that can be displayed in the editor by enabling Info. This means they have values from 0 to 255.
There is one more special index -1, which represents a tile outside of the map boundaries.

In r++ there are 2 ways to represent such index. We can either use an integer or coordinates, like this:

int index1 = 17;
int index2 = [1, 1];

Here both variables index1 and index2 will have the same value.

Coordinates may come in handy on many occasions, however be careful when using them to represent a tile. Important thing to remember, is that in this scenario, they are only valid in range [0, 0] to [15, 15].

Thanks to this, we are able to write something like:

Insert([1, 0]);

This will insert a tile 1.

Ranges

Ranges represent a list of consecutive values. Essentially they are a shortcut for 1, 2, 3, 4, 5, 6, 7, 8, 9, ... etc.

To create a range, we simply put _ in between 2 values:

range tiles = 1_9;

This will create a new range called tiles, which represents values from 1 to 9.

Let's say that we have a bunch of consecutive tiles that we want to insert.
Normally we would need to write:

Insert(1, 2, 3, 4, 5, 6, 17, 18, 19, 20, 21, 22);

With ranges, we can get the same result by simply writing:

Insert(1_6, 17_22);

Rotations

In r++ indices have yet another interesting property. They can be rotated. For convenience, r++ uses the same symbols, as the ones you will find in the editor. Additionally N stands for a tile without any rotation.

Note: by default int doesn't have any rotation, not even N. This might be unintuitive, but is necessary for the automapper. No rotation means that we don't care about the rotation at all, meanwhile N means that we only care about the tile without any rotation.

To rotate a tile, we use . followed by one of the rotations. Here's all of them:

int tile:N   = 1.N;
int tile:V   = 1.V;
int tile:H   = 1.H;
int tile:R   = 1.R;
int tile:VH  = 1.VH;
int tile:VR  = 1.VR;
int tile:HR  = 1.HR;
int tile:VHR = 1.VHR;

Note: r++ also supports the new XYR notation.

We can use this in pretty much any scenario:

int tile = 1;
tile = tile.V; // <- tile is now 1.V
tile = [1, 0].VH; // <- tile is now 1.VH

range tiles = 1_9.VHR; // <- tiles from 1 to 9 with VHR rotation
⚠️ **GitHub.com Fallback** ⚠️