I have been looking around and have found a couple of examples on how to do this, but none of them have worked.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <fstream>
#include <limits>
using namespace std;
using namespace sf;
//Declarations
//Global variables
const int scl = 8; //the images will be placed vector2f(image[][].x * scl, image[][].y * scl)
Sprite Bomberman;
Sprite Bomb;
//Classes
//Structures
struct block{
bool isBroken;
Sprite stone;
};
struct maps{
int blockCount;
int width;
int height;
};
//Functions
ifstream& GotoLine(std::ifstream& file, unsigned int num){
file.seekg(std::ios::beg);
for(int i=0; i < num - 1; ++i){
file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
return file;
}
maps getMapData(string fileName){
maps rtrn;
////////////////////////////////
///Line 1 = comment
///Line 2 = comment
///Line 3 = int width
///Line 4 = comment
///Line 5 = int height
///Line 6 = Dirt and wall images
///Line 7 = Entities images
///Line 8 = Dirt array
///Line 9 = Entities array
///Line 10 = Walls array
///////////////////////////////
string path = ("/DATA/mapData/" + fileName);
//////////////////////////////
ifstream& mapFl(char(path));
string readline = "";
int line_no = 0;
GotoLine(mapFl, 3);
mapFl >> readline;
int width_ = atoi(readline.c_str());
while (line_no != 5 && getline(mapFl, readline)) {
++line_no;
}
int height_ = atoi(readline.c_str());
while (line_no != 6 && getline(mapFl, readline)) {
++line_no;
}
string idlePath = readline;
while (line_no != 7 && getline(mapFl, readline)) {
++line_no;
}
string ePath = readline;
while (line_no != 8 && getline(mapFl, readline)) {
++line_no;
}
string dirtAr = readline;
while (line_no != 9 && getline(mapFl, readline)) {
++line_no;
}
string entityAr = readline;
while (line_no != 10 && getline(mapFl, readline)) {
++line_no;
}
string wallAr = readline;
////////////////////////////////
}
//More Global variables
//Main
int main()
{
cout << "Hello world!" << endl;
return 0;
}
|
These are the contents of the map file.
---------------------- 2 IMAGES, 3 ARRAYS -----------------------
//width
20
//height
20
/DATA/images/Map1/DIRT_WALL.png
/DATA/images/Map1/ENTITIES.png
/DATA/Arrays/Lvl1/DIRT.array
/DATA/Arrays/Lvl1/ENTITIES.array
/DATA/Arrays/Lvl1/WALLS_1.array
(Contents of the map file) //Btw, this file is located and named: /DATA/mapData/Lvl1.map
With the directory coming before /DATA/ being the project directory.
The problem is that it doesnt want to compile and it keeps giving me errors relating to either Gotoline when i use that method, or getline, when i use that method. Thanks!
Thanks for the help!