Commit fd9cfd0b authored by Stuart John Watson's avatar Stuart John Watson

Added level loading

parent 63d64450
......@@ -11,7 +11,7 @@
#include "../vroot.h"
#include "../lodepng/lodepng.h"
Game::Game(int _root):rootWindow(_root){
Game::Game(int _root,std::string _load):rootWindow(_root),levelToLoad(_load){
}
Game::~Game(){
......@@ -55,15 +55,15 @@ void Game::loop(){
// Print Level Seed
std::cout << "Drawing seed for level " << dungeonLevel << ": " << milliseconds_since_epoch << std::endl;
std::shared_ptr<DungeonGenerator> d(new DungeonGenerator(200,200,milliseconds_since_epoch));
//std::shared_ptr<Loader> d(new Loader(202,202,"../testLevels/maze.lvl"));
levels.emplace_back(d);
// Populate the dungeon with rooms and corridors
d->populate();
if (!levelToLoad.empty()){
std::shared_ptr<Loader> d(new Loader(202,202,levelToLoad));
levels.emplace_back(d);
d->populate();
} else {
std::shared_ptr<DungeonGenerator> d(new DungeonGenerator(200,200,milliseconds_since_epoch));
levels.emplace_back(d);
d->populate();
}
// Create hero at coordinates of the dungeon start
std::tuple<int,int> heroStart = levels.back()->upStairPosition();
......
......@@ -16,13 +16,14 @@
class Game {
public:
Game(int);
Game(int,std::string);
~Game();
int readTiles(std::string,Display*&,Drawable,GC);
void loop();
protected:
int nTiles;
int const rootWindow;
std::string const levelToLoad;
unsigned int tileHeight;
std::vector<std::shared_ptr<Dungeon>> levels;
std::vector<std::shared_ptr<Entity>> entities;
......
......@@ -12,17 +12,29 @@
int main(int argc, char **argv){
int ROOT=0;
std::string LOAD;
const struct option longopts[] = {
{"root", no_argument, &ROOT, 1}
{"root", no_argument, &ROOT,1},
{"load", required_argument, 0, 'l'},
{0,0,0,0}
};
int index;
getopt_long(argc, argv, "", longopts, &index);
char c;
while ((c = getopt_long(argc, argv, "", longopts, &index)) != -1){
switch(c){
case 0:
break;
case 'l':
LOAD = std::string(optarg);
break;
}
}
std::cout << ROOT << std::endl;
std::cout << LOAD << std::endl;
// Create a game class
Game main(ROOT);
Game main(ROOT,LOAD);
main.loop();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment