Commit 1ba255bd authored by Stuart John Watson's avatar Stuart John Watson

Started on system to load levels from files.

At current they are many hacks!
parent 61439a47
......@@ -14,6 +14,7 @@ add_executable(IdleCrawler
src/dungeon/dungeon.cpp
src/dungeon/rectangle.cpp
src/dungeon/space.cpp
src/dungeon/loader.cpp
src/entity/entity.cpp
src/entity/vision/vision.cpp
src/entity/vision/alive/alive.cpp
......
#include "space.h"
#include "types.h"
#include <string>
#include <fstream>
#include <streambuf>
#include <iostream>
Loader::Loader(int w,int h,std::string _filename): Dungeon(w,h,0){
filename = _filename.c_str();
}
TILE_TYPES TILE_REVERSE_LOOKUP(char c){
switch (c) {
case ' ': return UNSET;
case '#': return WALL;
case '.': return FLOOR;
case '+': return DOOR;
case '^': return STAIRS_UP;
case 'v': return STAIRS_DOWN;
case '~': return UNSEEN;
}
}
void Loader::populate(){
Space::populate()
std::ifstream f(filename);
int xAt = 0;
int yAt = 0;
char c = f.get();
while (!f.eof()){
if (c=='\n'){
yAt ++;
xAt = 0;
} else {
setTile(xAt,yAt,TILE_REVERSE_LOOKUP(c));
xAt++;
}
c = f.get();
}
}
......@@ -61,4 +61,12 @@ public:
};
class Loader : public Dungeon {
public:
Loader(int,int,std::string);
void populate();
protected:
const char* filename;
};
#endif
......@@ -11,7 +11,7 @@ enum TILE_TYPES {
STAIRS_DOWN,
UNSEEN
};
const char TILES_TYPES_MAP[]= {' ','#','.','+','^','v','+'};
const char TILES_TYPES_MAP[]= {' ','#','.','+','^','v','~'};
const int TILE_COLOUR_MAP[] = {0x607D8B,0x212121,0xFAFAFA,0x795548,0x4CAF50,0xFF9800,0x607D8B};
enum LOCATION {
......
......@@ -48,7 +48,8 @@ void Game::loop(){
// Print Level Seed
std::cout << "Drawing seed for level " << dungeonLevel << ": " << milliseconds_since_epoch << std::endl;
levels.emplace_back( Dungeon(200,200,milliseconds_since_epoch) );
//levels.emplace_back( Dungeon(200,200,milliseconds_since_epoch) );
levels.emplace_back( Loader(202,202,"../testLevels/maze.lvl"));
// Populate the dungeon with rooms and corridors
levels.back().populate();
......@@ -58,10 +59,11 @@ void Game::loop(){
//Hero levelHero = Hero(levels.back(),std::get<0>(heroStart), std::get<1>(heroStart),20 /*vision*/);
theHero = &levelHero;
#if 0
// Generate nMobs
std::default_random_engine generator;
generator.seed(milliseconds_since_epoch);
for(int n = 0; n < 10; n++){
for(int n = 0; n < 0; n++){
// Generate random coordinates for the starting point for each mob
std::uniform_int_distribution<int> x_dist(0, levels.back().getWidth() );
std::uniform_int_distribution<int> y_dist(0, levels.back().getHeight() );
......@@ -75,6 +77,7 @@ void Game::loop(){
std::shared_ptr<RandomMove> r(new RandomMove( levels.back(), mobx, moby, 0 /*vision*/, milliseconds_since_epoch+n));
entities.emplace_back( r );
}
#endif
int scale = wa.width/levels.back().getWidth();
if (wa.height/levels.back().getHeight() < scale){
......
......@@ -21,7 +21,7 @@ class Game {
protected:
int const rootWindow;
std::vector<Dungeon> levels;
std::vector<Loader> levels;
std::vector<std::shared_ptr<Entity>> entities;
Hero *theHero;
......
This diff is collapsed.
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