Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include <SFML/System.hpp>
- #include <SFML/Window.hpp>
- #include <fstream>
- #include <limits>
- #include <string>
- #include <stdio.h>
- using namespace std;
- using namespace sf;
- //Declarations
- //Global variables
- const int scl = 16;
- Sprite Bomberman;
- Sprite Bomb;
- //Classes
- //Structures
- struct BarBlock{
- bool isBroken;
- Sprite stone;
- };
- struct maps{
- int blockCount;
- int width;
- int height;
- Texture Entities;
- Texture Wall;
- Texture Barrier;
- // Texture Other;
- Sprite Walls;
- BarBlock dirt;
- };
- //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 = ("E:/C++ Projects/Bomberman/DATA/mapData/" + fileName);
- //////////////////////////////
- ifstream mapFl(path.c_str());
- if (!mapFl){
- cout << "ERR_FILE.NOTFOUND" << endl;
- cout << path << endl;
- }
- string readline = " ";
- int line_no = 0;
- GotoLine(mapFl, 3);
- mapFl >> readline;
- const int width_ = atoi(readline.c_str());
- GotoLine(mapFl, 5);
- mapFl >> readline;
- const int height_ = atoi(readline.c_str());
- GotoLine(mapFl, 6);
- mapFl >> readline;
- string idlePath = readline;
- GotoLine(mapFl, 7);
- mapFl >> readline;
- string ePath = readline;
- GotoLine(mapFl, 8);
- mapFl >> readline;
- string dirtAr = readline;
- GotoLine(mapFl, 9);
- mapFl >> readline;
- string entityAr = readline;
- GotoLine(mapFl, 10);
- mapFl >> readline;
- string wallAr = readline;
- ////////////////////////////////
- mapFl.close();
- path = ("E:/C++ Projects/Bomberman/" + idlePath);
- if(!rtrn.Wall.loadFromFile(path)){
- cout << "ERROR_CANNOT_OPEN_FILE:" << idlePath;
- }
- path = ("E:/C++ Projects/Bomberman/" + ePath);
- if(!rtrn.Wall.loadFromFile(path)){
- cout << "ERROR_CANNOT_OPEN_FILE:" << ePath;
- }
- path = ("E:/C++ Projects/Bomberman/" + dirtAr);
- mapFl.open(path.c_str());
- int result[(width_ * height_)];
- int index = 0;
- char arrayResult = 0;
- while(mapFl.good()){
- arrayResult = mapFl.get();
- if(index == 440){
- break;
- }
- if(arrayResult != ' '){
- cout << index << endl;
- result[index] = int(arrayResult) - 48;
- index++;
- }
- }
- int oldI = 0;
- for(int i = 0; i != 420; i++){
- cout << result[i] << " ";
- if(i / 20 != oldI){
- cout << endl;
- oldI++;
- }
- }
- BarBlock return_value[width_][height_];
- int test[20][21];
- int Resindex = 0;
- for(int i = 0; i != width_; i++){
- for(int j = 0; j != height_; j++){
- test [i] [j] = result [(width_ * i + j)];
- }
- }
- for (int i = 0; i != 20; i++){
- for (int j = 0; i != 21; j++){
- cout << test [i] [j] << " ";
- }
- cout << endl;
- }
- }
- //More Global variables
- //Main
- int main()
- {
- getMapData("Lvl1.map");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement