parent
193f5f915e
commit
18a5f6bfa9
@ -1,10 +1,49 @@ |
||||
#include "levelmanager.hpp" |
||||
#include "worldbuilder.hpp" |
||||
#include "constants.hpp" |
||||
#include "save.hpp" |
||||
|
||||
using lighting::LightRender; |
||||
using std::shared_ptr, std::make_shared; |
||||
|
||||
LevelManager::LevelManager() { |
||||
// does nothing yet
|
||||
} |
||||
|
||||
size_t LevelManager::create_level() { |
||||
GameLevel level; |
||||
level.index = $levels.size(); |
||||
|
||||
level.world = make_shared<DinkyECS::World>(); |
||||
save::load_configs(*level.world); |
||||
|
||||
level.map = make_shared<Map>(GAME_MAP_X, GAME_MAP_Y); |
||||
WorldBuilder builder(*level.map); |
||||
builder.generate(*level.world); |
||||
|
||||
level.lights = make_shared<LightRender>(level.map->width(), level.map->height()); |
||||
|
||||
$levels.push_back(level); |
||||
|
||||
dbc::check(level.index == $levels.size() - 1, "Level index is not the same as $levels.size() - 1, off by one error"); |
||||
return level.index; |
||||
} |
||||
|
||||
GameLevel &LevelManager::next() { |
||||
dbc::check($current_level < $levels.size(), "attempt to get next level when at end"); |
||||
$current_level++; |
||||
return $levels.at($current_level); |
||||
} |
||||
|
||||
GameLevel &LevelManager::previous() { |
||||
dbc::check($current_level > 0, "attempt to go to previous level when at 0"); |
||||
$current_level--; |
||||
return $levels.at($current_level); |
||||
} |
||||
|
||||
GameLevel &LevelManager::current() { |
||||
return $levels.at($current_level); |
||||
} |
||||
|
||||
void LevelManager::create_level() { |
||||
// does nothing yet
|
||||
GameLevel &LevelManager::get(size_t index) { |
||||
return $levels.at(index); |
||||
} |
||||
|
@ -1,9 +1,30 @@ |
||||
#pragma once |
||||
|
||||
#include "dinkyecs.hpp" |
||||
#include "lights.hpp" |
||||
#include "map.hpp" |
||||
#include <vector> |
||||
#include <memory> |
||||
|
||||
|
||||
struct GameLevel { |
||||
size_t index = 0; |
||||
std::shared_ptr<Map> map = nullptr; |
||||
std::shared_ptr<DinkyECS::World> world = nullptr; |
||||
std::shared_ptr<lighting::LightRender> lights = nullptr; |
||||
}; |
||||
|
||||
class LevelManager { |
||||
public: |
||||
std::vector<GameLevel> $levels; |
||||
size_t $current_level = 0; |
||||
|
||||
LevelManager(); |
||||
|
||||
void create_level(); |
||||
size_t create_level(); |
||||
GameLevel &next(); |
||||
GameLevel &previous(); |
||||
GameLevel ¤t(); |
||||
size_t current_index(); |
||||
GameLevel &get(size_t index); |
||||
}; |
||||
|
Loading…
Reference in new issue