Skip to content
Snippets Groups Projects

Merge the refactoring + box2d movement

1 file
+ 17
14
Compare changes
  • Side-by-side
  • Inline
+ 17
14
@@ -56,22 +56,22 @@ Level::Level(const std::string& path, Engine& engine)
// if level is smaler than 20x20 surround with water tiles
if (m_width < 20 || m_height < 20)
{
int x_start = (20 - width) / 2;
int y_start = (20 - height) / 2;
int x_start = (20 - m_width) / 2;
int y_start = (20 - m_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 < x_start || y < y_start || x >= x_start + width || y >= y_start + height)
if (x < x_start || y < y_start || x >= x_start + m_width || y >= y_start + m_height)
{
transformed_tiles_array.push_back(1);
}
else
{
transformed_tiles_array.push_back(
level_tilesarray[x - x_start + (y - y_start) * width]);
level_tilesarray[x - x_start + (y - y_start) * m_width]);
}
}
}
@@ -94,20 +94,24 @@ Level::Level(const std::string& path, Engine& engine)
if (level_tilesarray[i] >= 50)
{
// tile id >= 50 -> building -> have to add Plain Tile and Building
tiles.push_back(Tile(TileId(TileId::PLAIN), x, y));
BuildingId building_id = static_cast<BuildingId>((level_tilesarray[i] - 50) % 5);
BuildingFaction faction_id =
static_cast<BuildingFaction>((level_tilesarray[i] - 50) / 5);
tiles.push_back(Tile(TileId(TileId::PLAIN), tileX, tileY));
BuildingId building_id = static_cast<BuildingId>((level_tilesarray[i] - 50) % 5);
Faction faction_id = static_cast<Faction>((level_tilesarray[i] - 50) / 5);
if (building_id == BuildingId::HEADQUARTER)
{
// an infantery unit should be added onto every HQ
units.push_back(Unit(
x, y, static_cast<UnitFaction>(faction_id), UnitId::INFANTERY,
UnitState::UNAVAILABLE, engine.getUnitConfig()));
int index = static_cast<int>(faction_id);
if (!has_factions[index])
{
addUnit(
tileX, tileY, faction_id, UnitTypeId::INFANTERY, UnitState::UNAVAILABLE,
engine.getUnitConfig());
}
has_factions[static_cast<int>(faction_id)] = true; // collect existing factions
// for later building turnQ
}
buildings.push_back(Building(tileX, tileY, building_id, factionId));
buildings.push_back(Building(tileX, tileY, building_id, faction_id));
}
else
{
@@ -142,8 +146,7 @@ Level::Level(const std::string& path, Engine& engine)
m_turnQ = turnQ;
level.m_turnQ.front().startTurn(level.m_units, level.m_buildings);
return std::make_shared<Level>(level);
m_turnQ.front().startTurn(m_units, m_buildings);
}
std::pair<int, int> Level::calcTilePos(int mouseX, int mouseY)
Loading