Skip to content
Snippets Groups Projects
Commit 8af9f64c authored by TheUltimateOptimist's avatar TheUltimateOptimist
Browse files

implemented load level

parent fe650c77
No related branches found
No related tags found
1 merge request!17Merge feature to load levels from file
......@@ -44,15 +44,28 @@ Level::Level(std::string name, int width, int height, std::vector<Tile> tiles,
int width = pt.get<int>("level.width");
int height = pt.get<int>("level.height");
std::string name = pt.get<std::string>("level.name");
// create tiles and buildings vector from tiles array
std::vector<Tile> tiles;
std::vector<Building> buildings;
tiles.reserve(width*height);
for (uint8_t value : level_tilesarray)
for (int i = 0; i < level_tilesarray.size(); i++)
{
tiles.push_back(Tile())
int x = i % width;
int y = i / width;
if (level_tilesarray[i] >= 50) {
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);
buildings.push_back(Building(x, y, building_id, faction_id));
}
else {
TileId tile_id = static_cast<TileId>(level_tilesarray[i]);
tiles.push_back(Tile(tile_id, x, y));
}
}
throw std::runtime_error("some");
return Level(name, width, height, tiles, buildings, {}, {});
};
void Level::render(Engine &engine, std::vector<SDL_Event> &events) {
......
......@@ -10,6 +10,8 @@
#include <vector>
#include <SDL2/SDL.h>
#include <SDL_image.h>
#include <stdexcept>
using namespace advanced_wars;
......@@ -30,76 +32,12 @@ int main() {
Window window("Advanced Wars", 960, 960);
Engine engine(window);
Level levell = Level::loadLevel("level.h5");
return 0;
// Construct a level
std::vector<Tile> tiles;
for (int y = 0; y < 20; y++) {
for (int x = 0; x < 20; x++) {
tiles.push_back(Tile(TileId::PLAIN, x, y));
}
}
// Fill the edges with water
for (size_t n = 0; n < 20; n++) {
// Vertical
tiles.at(n * 20) = Tile(TileId::WATER, 0, n);
tiles.at(n * 20 + 19) = Tile(TileId::WATER, 19, n);
// Horizontal
tiles.at(n) = Tile(TileId::WATER, n, 0);
tiles.at(19 * 20 + n) = Tile(TileId::WATER, n, 19);
}
// Make the edges cliffs
for (size_t n = 1; n < 19; n++) {
// Vertical
tiles.at(n * 20 + 1) = Tile(TileId::CLIFF_RIGHT, 1, n);
tiles.at(n * 20 + 18) = Tile(TileId::CLIFF_LEFT, 18, n);
// Horizontal
tiles.at(20 + n) = Tile(TileId::CLIFF_BOTTOM, n, 1);
tiles.at(18 * 20 + n) = Tile(TileId::CLIFF_TOP, n, 18);
}
// Fix the corners
tiles.at(20 + 1) = Tile(TileId::CLIFF_CORNER_TOP_LEFT, 1, 1);
tiles.at(20 + 18) = Tile(TileId::CLIFF_CORNER_TOP_RIGHT, 18, 1);
tiles.at(18 * 20 + 1) = Tile(TileId::CLIFF_CORNER_BOTTOM_LEFT, 1, 18);
tiles.at(18 * 20 + 18) = Tile(TileId::CLIFF_CORNER_BOTTOM_RIGHT, 18, 18);
// Buildings
std::vector<Building> buildings;
for (int y = 0; y < 6; y++) {
for (int x = 0; x < 5; x++) {
BuildingId id = static_cast<BuildingId>(x);
BuildingFaction faction = static_cast<BuildingFaction>(y);
buildings.push_back(Building(3 + x, 3 + 2 * y, id, faction));
}
}
// Units
std::vector<Unit> units;
for (int y = 0; y < 19; y++) {
for (int x = 0; x < 6; x++) {
units.push_back(Unit(x + 9, y + 2, UnitFaction::URED,
static_cast<UnitId>(y), static_cast<UnitState>(x)));
}
}
std::vector<Effect> effects({Effect(3, 15, EffectId::LAND_EXPLOSION, true),
Effect(5, 15, EffectId::AIR_EXPLOSION, true),
Effect(5, 18, EffectId::NAVAL_EXPLOSION, true)});
Level level("Osnabrück", 20, 20, tiles, buildings, units, effects);
Level level = Level::loadLevel("spritesheet.h5");
engine.set_scene(level);
Spritesheet spritesheet("/media/data/rust/sprite-extractor/spritesheet.h5",
engine);
Spritesheet spritesheet("spritesheet.h5", engine);
engine.set_spritesheet(spritesheet);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment