3.5. OBJECT-BASED 2D MAPS (2/2) Intro On the previous lesson we saw the foundations of an object-based map - a map created using objects. This way, an statue (for example) can be created only putting the object that represents that statue into the map, so no tiles are glued like in a puzzle in order to draw the statue. Also, objects carry their own information (physical size, opacity, script events...).
In this lesson we will explain the features that were left unexplained in the previous lesson. Mostly, physical issues (movement issues) and NPCs issues (locating NPCs inside the map). Movement in a Object-based map
1 | 1 | 2 | 1
1 | 1 | 2 | 2
1 | 1 | 1 | 1
3 | 3 | 3 | 3
Ground Layer
|  | X |
|  | X | X
X | X | X | X
Physical Layer
| ### OR |

Movement Flags in a tile-based map (binary or directional flags)
As we said some lessons ago, the most important physical law in a game (forgetting line of sight) is (the ability of) movement. In tile-based maps, movement was controlled either using binary information embedded in the tiles (you can pass/you cannot pass), or "directional" information embedded in the tiles (four flags indicating whether an NPC can or cannot move onto that direction).

| ## + |  | ## = |

Movement Flags from Ground Layer and Object layer... and combined
In an Object-Based map, the ground layer still uses the same technique: A binary flag that specifies whether an NPC can walk or not over a tile. But in the object layer, things are different. Every object (in the image, the twin dragons) stores inside the information about whether a NPC can walk or not at certain parts of the object. Therefore, the level designer only has to indicate the movement flags once for every object.
Finally, the information of the ground layer and the information stored in every object are combined in order to create a grid composed by "can/cannot walk" binary flags. In the example image (in red the impassable tiles), the NPC can walk behind the twin statues, and over the bridge, but not in the water.
Oh, and what happens with the line of sight? See lesson 3.1, all the concepts explained in that lesson (the "you can see but you cannot pass" flag) applies here.

Entities in a map. Coordinates and Physical interactions

As in a tile-based map, a NPC must exist somewhere inside the map. And as in the tile-based map, NPCs are located inside the map using coordinates referencing the rows and columns of the map, taking as reference the upper-left corner (0,0). But in a object-based map, the coordinate of an entity depends on where are its legs. If you check the image, our NPC is in X:7, Y:8.
You can understand why coordinates are managed this way if you imagine an entity as a figure in an old board game. In good old days, a figure wasn't made of plastic or metal - it was just a piece of cardboard with an image printed onto it. But it needed something for standing up - a plastic piece (base). Well, the green section (in the example image) is like the plastic piece who allows the entity to stand up, and the red section is the cardboard piece with the image printed onto it ^_-.
How collisions are managed? Well, as in a board game, one figure cannot walk into another one if their bases are in the same place. In other words - movement and colisions are tile-dependant, one entity cannot walk into the coordinate of another entity. However, the size of the tile is very little, so it does not give the sensation of "bulky" movement.
The same goes for other entities inside a map. An egg, an effect... they collide with the NPC if their bases are in the same coordinate.