Project update #5

Done on September 13, 2017 – Tilemap and interactions

In this demo, the player spawns in the first level and tries to reach the exit. When he does, he respawns in the second level, reaches the exit again, spawns back in the first one and so on. The 2 tilemaps are edited manually using the Tiled editor and loaded in game.

AlpagosGame_07

It’s been a couple of months since the last project update. For this fifth update, I decided to follow up on my previous post about the Tiled map editor. At the time, I implemented a custom tilemap exporter. I refined this text format and implemented a loader in the game engine.

Below you’ll find both the visual and text format for each of the tilemaps featured in this demo:

Scavengers_LevelDemo1

# Map Scavengers_LevelDemo1
9 7 32 32

# Tileset Scavengers_SpriteSheet
Scavengers_SpriteSheet.png
18 Food Food1 0 0 32 32 Value 1
19 Food Food2 0 0 32 32 Value 2
21 Collision Breakable 0 0 32 32 Value 2
22 Collision Breakable 0 0 32 32 Value 2
23 Collision Breakable 0 0 32 32 Value 3
24 Collision Breakable 0 0 32 32 Value 3
25 Collision Unbreakable 0 0 32 32
26 Collision Unbreakable 0 0 32 32

# TileLayer Static
26 25 25 26 26 25 25 26 26
26 25 26 26 25 25 25 26 26
26 25 37 39 34 20 35 26 26
26 25 32 36 37 38 37 25 25
25 26 37 35 39 53 30 26 25
26 25 25 26 25 25 26 25 26
26 25 26 25 25 25 25 25 25

# TileLayer Dynamic
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 19 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1

# ObjectGroup Interactions
Start PlayerSpawner 112 144 0 0
Exit Exit 160 64 32 32

Scavengers_LevelDemo2

# Map Scavengers_LevelDemo2
6 8 32 32

# Tileset Scavengers_SpriteSheet
Scavengers_SpriteSheet.png
18 Food Food1 0 0 32 32 Value 1
19 Food Food2 0 0 32 32 Value 2
21 Collision Breakable 0 0 32 32 Value 2
22 Collision Breakable 0 0 32 32 Value 2
23 Collision Breakable 0 0 32 32 Value 3
24 Collision Breakable 0 0 32 32 Value 3
25 Collision Unbreakable 0 0 32 32
26 Collision Unbreakable 0 0 32 32

# TileLayer Static
25 25 26 26 25 25
25 26 26 25 25 25
25 26 39 34 25 26
25 26 36 37 26 26
26 25 35 39 26 25
25 25 34 20 25 26
25 26 25 25 25 25
26 26 25 25 26 25

# TileLayer Dynamic
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 18 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1

# ObjectGroup Interactions
Start PlayerSpawner 112 80 0 0
Exit Exit 96 160 32 32

The information contained in the exported files is fully loaded by the engine but only part of it is currently being used:

  • The tilemap basic information (line 2) provides the tilemap size (6×8 tiles) and the tile size (32×32 pixels)
  • The tile layers (line 15 to 33 in the 2nd map) provide the tile indices to display from the spritesheet (see below)
  • The object groups (line 35 to 37 in the 2nd map) provide additional gameplay information, each object composed by a name, type, position, size and optional custom properties (such as the Start and Exit objects)

Scavengers_SpriteSheet

The Start and Exit objects are used for spawning the player and loading the next level. The Tilemap interface allows for an easy access to these objects:

bool GameManager::LoadTilemap()
{
    bool success = true;

    std::string tilemapFilePath = m_tilemapId == 0 ? "Data/Levels/Scavengers_LevelDemo1.gmt" : "Data/Levels/Scavengers_LevelDemo2.gmt";
    if (!m_tilemap.Load(tilemapFilePath))
    {
        ALPAGOS_LOG("Failed to load tilemap!");
        success = false;
    }
    else
    {
        m_startObject = m_tilemap.FindObject("Start");
        m_exitObject = m_tilemap.FindObject("Exit");
    }

    return success;
}

The object can then be used to reposition the player:

// Spawn the player at the Start point if there's one
Vector2 spawnPosition(0, 0);
if (m_startObject)
{
    spawnPosition = m_startObject->GetPosition();
}
m_player.SetPosition(spawnPosition);

At the moment, the information contained in the tileset (line 6 to 13 in the 2nd map) is not used. It essentially provides information that is directly linked to a specific tile. It will be useful to implement collision with the walls, player interaction with the food and more.

Cheers.

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