Advertisement
Guest User

Source

a guest
Jan 17th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3. #include <SFML/Audio.hpp>
  4. #include <SFML/System.hpp>
  5. #include <SFML/Window.hpp>
  6. #include <fstream>
  7. #include <limits>
  8. #include <string>
  9. #include <stdio.h>
  10. using namespace std;
  11. using namespace sf;
  12.  
  13. //Declarations
  14.  
  15. //Global variables
  16. const int scl = 16;
  17. Sprite Bomberman;
  18. Sprite Bomb;
  19. //Classes
  20.  
  21. //Structures
  22. struct BarBlock{
  23. bool isBroken;
  24. Sprite stone;
  25. };
  26. struct maps{
  27. int blockCount;
  28. int width;
  29. int height;
  30. Texture Entities;
  31. Texture Wall;
  32. Texture Barrier;
  33. // Texture Other;
  34. Sprite Walls;
  35. BarBlock dirt;
  36.  
  37. };
  38. //Functions
  39. ifstream& GotoLine(std::ifstream& file, unsigned int num){
  40. file.seekg(std::ios::beg);
  41. for(int i=0; i < num - 1; ++i){
  42. file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
  43. }
  44. return file;
  45. }
  46. maps getMapData(string fileName){
  47. maps rtrn;
  48. ////////////////////////////////
  49. ///Line 1 = comment
  50. ///Line 2 = comment
  51. ///Line 3 = int width
  52. ///Line 4 = comment
  53. ///Line 5 = int height
  54. ///Line 6 = Dirt and wall images
  55. ///Line 7 = Entities images
  56. ///Line 8 = Dirt array
  57. ///Line 9 = Entities array
  58. ///Line 10 = Walls array
  59. ///////////////////////////////
  60. string path = ("E:/C++ Projects/Bomberman/DATA/mapData/" + fileName);
  61. //////////////////////////////
  62. ifstream mapFl(path.c_str());
  63. if (!mapFl){
  64. cout << "ERR_FILE.NOTFOUND" << endl;
  65. cout << path << endl;
  66. }
  67. string readline = " ";
  68. int line_no = 0;
  69. GotoLine(mapFl, 3);
  70. mapFl >> readline;
  71. const int width_ = atoi(readline.c_str());
  72.  
  73. GotoLine(mapFl, 5);
  74. mapFl >> readline;
  75. const int height_ = atoi(readline.c_str());
  76.  
  77. GotoLine(mapFl, 6);
  78. mapFl >> readline;
  79. string idlePath = readline;
  80.  
  81. GotoLine(mapFl, 7);
  82. mapFl >> readline;
  83. string ePath = readline;
  84.  
  85. GotoLine(mapFl, 8);
  86. mapFl >> readline;
  87. string dirtAr = readline;
  88.  
  89. GotoLine(mapFl, 9);
  90. mapFl >> readline;
  91. string entityAr = readline;
  92.  
  93. GotoLine(mapFl, 10);
  94. mapFl >> readline;
  95. string wallAr = readline;
  96. ////////////////////////////////
  97. mapFl.close();
  98. path = ("E:/C++ Projects/Bomberman/" + idlePath);
  99. if(!rtrn.Wall.loadFromFile(path)){
  100. cout << "ERROR_CANNOT_OPEN_FILE:" << idlePath;
  101. }
  102. path = ("E:/C++ Projects/Bomberman/" + ePath);
  103. if(!rtrn.Wall.loadFromFile(path)){
  104. cout << "ERROR_CANNOT_OPEN_FILE:" << ePath;
  105. }
  106. path = ("E:/C++ Projects/Bomberman/" + dirtAr);
  107. mapFl.open(path.c_str());
  108. int result[(width_ * height_)];
  109. int index = 0;
  110. char arrayResult = 0;
  111. while(mapFl.good()){
  112. arrayResult = mapFl.get();
  113. if(index == 440){
  114. break;
  115. }
  116. if(arrayResult != ' '){
  117. cout << index << endl;
  118. result[index] = int(arrayResult) - 48;
  119. index++;
  120. }
  121. }
  122. int oldI = 0;
  123. for(int i = 0; i != 420; i++){
  124. cout << result[i] << " ";
  125. if(i / 20 != oldI){
  126. cout << endl;
  127. oldI++;
  128. }
  129. }
  130. BarBlock return_value[width_][height_];
  131. int test[20][21];
  132. int Resindex = 0;
  133. for(int i = 0; i != width_; i++){
  134. for(int j = 0; j != height_; j++){
  135. test [i] [j] = result [(width_ * i + j)];
  136. }
  137. }
  138. for (int i = 0; i != 20; i++){
  139. for (int j = 0; i != 21; j++){
  140. cout << test [i] [j] << " ";
  141. }
  142. cout << endl;
  143. }
  144. }
  145. //More Global variables
  146. //Main
  147. int main()
  148. {
  149. getMapData("Lvl1.map");
  150. return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement