Skip to content
Snippets Groups Projects
Commit dbdf27fb authored by Frederik Alexander Keens's avatar Frederik Alexander Keens
Browse files

Merge branch 'water-surround' into 'main'

surround maps that are too small with water

See merge request !35
parents 81aa04cc 7a869852
No related branches found
No related tags found
2 merge requests!35surround maps that are too small with water,!29Merge main into box2d to implement physics
......@@ -80,6 +80,31 @@ std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
int height = pt.get<int>("level.height");
std::string name = pt.get<std::string>("level.name");
// if level is smaler than 20x20 surround with water tiles
if (width < 20 || height < 20) {
int w_start = (20 - width) / 2;
int h_start = (20 - height) / 2;
std::vector<uint8_t> transformed_tiles_array;
transformed_tiles_array.reserve(20*20);
for (int y = 0; y < 20; y++)
{
for (int x = 0; x < 20; x++)
{
if (x < w_start || y < h_start || x >= w_start + width || y >= h_start + height)
{
transformed_tiles_array.push_back(1);
}
else
{
transformed_tiles_array.push_back(level_tilesarray[x - w_start + (y - h_start)*width]);
}
}
}
level_tilesarray = std::move(transformed_tiles_array);
width = 20;
height = 20;
}
// create tiles, buildings and units vector from tiles array
std::vector<Tile> tiles;
std::vector<Building> buildings;
......@@ -129,6 +154,7 @@ std::shared_ptr<Level> Level::loadLevel(const std::string& path, Engine& engine)
Level level(name, width, height, tiles, buildings, units, std::vector<Effect>{}, turnQ);
level.m_turnQ.front().startTurn(level.m_units, level.m_buildings);
std::cout << "exiting" << std::endl;
return std::make_shared<Level>(level);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment