Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.64 KB | None | 0 0
  1. #include<SFML\Graphics.hpp>
  2. #include<iostream>
  3. #include<iterator>
  4. #include<map>
  5. #include<set>
  6. #include<queue>
  7. #include<string>
  8. #include<fstream>
  9. #include<cmath>
  10. #include<iterator>
  11. #include<stack>
  12.  
  13. using namespace sf;
  14. using namespace std;
  15.  
  16. char prevchoice='p';
  17. struct Astar
  18. {
  19.  
  20. char pixel,AI=' ';
  21. int h, g=0, f;
  22. pair< int, int> parent;
  23. int id;
  24. };
  25. pair<int,pair<int, int>> Min_F(map<int, pair<int, pair<int, int>>> openst)
  26. {
  27.  
  28. pair<int, int>min = make_pair(-1, 1e9);
  29. map<int, pair<int, pair<int, int>>>::iterator it;
  30.  
  31.  
  32. for (auto i = openst.begin(); i != openst.end(); i++)
  33. {
  34.  
  35. if (i->second.first < min.second)
  36. {
  37. it = i;
  38. min.first = i->first;
  39. min.second = i->second.first;
  40.  
  41. }
  42. }
  43. return make_pair(it->first,make_pair(it->second.second.first,it->second.second.second));
  44.  
  45. }
  46.  
  47. stack<pair<int, int>>path,path2;
  48. void PathFind(Astar ary[36][28], int ghost_start_row, int ghost_start_col, int target_row, int target_col,char y)
  49. {
  50.  
  51.  
  52. pair<int, int>pathfinder;
  53. int w;
  54.  
  55. pathfinder.first = target_row, pathfinder.second = target_col;
  56. w = pathfinder.first;
  57. pathfinder.first = ary[pathfinder.first][pathfinder.second].parent.first;
  58. pathfinder.second = ary[w][pathfinder.second].parent.second;
  59.  
  60. if (y == 'R')
  61. {
  62. ary[w][pathfinder.second].AI = 'R';
  63. path.push(make_pair(pathfinder.first, pathfinder.second));
  64. }
  65.  
  66. else
  67. {
  68. ary[w][pathfinder.second].AI = 'B';
  69. path2.push(make_pair(pathfinder.first, pathfinder.second));
  70. }
  71.  
  72.  
  73.  
  74. if (pathfinder.first != ghost_start_row || pathfinder.second != ghost_start_col)
  75. PathFind(ary, ghost_start_row, ghost_start_col, pathfinder.first, pathfinder.second, y);
  76.  
  77. }
  78.  
  79. set <int > close_set;
  80. map<int, pair<int, pair<int, int>>>open_set;
  81. pair<int*, int*>ghost_real_pos,ghost2_real_pos;
  82. void AI(Astar ary[36][28], int ghost_position_row, int ghost_position_col, int target_first_row, int target_first_col,char x)
  83. {
  84. char y='R';
  85. if (x == 'R')
  86. y = 'B';
  87.  
  88.  
  89.  
  90.  
  91. // Up
  92. if (ary[ghost_position_row - 1][ghost_position_col].pixel != '0' &&ary[ghost_position_row - 1][ghost_position_col].AI != y && close_set.count(ary[ghost_position_row - 1][ghost_position_col].id) == 0)
  93. {
  94.  
  95. if (open_set.count(ary[ghost_position_row - 1][ghost_position_col].id) == 0)
  96. {
  97.  
  98.  
  99. ary[ghost_position_row - 1][ghost_position_col].h = (abs(ghost_position_row - 1 - target_first_row) + abs(ghost_position_col - target_first_col));
  100. ary[ghost_position_row - 1][ghost_position_col].g = ary[ghost_position_row][ghost_position_col].g + 1;
  101. ary[ghost_position_row - 1][ghost_position_col].f = ary[ghost_position_row - 1][ghost_position_col].h + ary[ghost_position_row - 1][ghost_position_col].g;
  102.  
  103. //setting pairent
  104. ary[ghost_position_row - 1][ghost_position_col].parent.first = ghost_position_row;
  105. ary[ghost_position_row - 1][ghost_position_col].parent.second = ghost_position_col;
  106.  
  107. open_set[ary[ghost_position_row - 1][ghost_position_col].id] = make_pair(ary[ghost_position_row - 1][ghost_position_col].f, make_pair(ghost_position_row - 1, ghost_position_col));
  108.  
  109. }
  110. }
  111.  
  112.  
  113. //down
  114. if (ary[ghost_position_row + 1][ghost_position_col].pixel != '0' && ary[ghost_position_row + 1][ghost_position_col].AI != y &&close_set.count(ary[ghost_position_row + 1][ghost_position_col].id) == 0)
  115. {
  116.  
  117. if (open_set.count(ary[ghost_position_row + 1][ghost_position_col].id) == 0)
  118. {
  119.  
  120.  
  121. ary[ghost_position_row + 1][ghost_position_col].h = (abs(ghost_position_row + 1 - target_first_row) + abs(ghost_position_col - target_first_col));
  122. ary[ghost_position_row + 1][ghost_position_col].g = ary[ghost_position_row][ghost_position_col].g + 1;
  123. ary[ghost_position_row + 1][ghost_position_col].f = ary[ghost_position_row + 1][ghost_position_col].h + ary[ghost_position_row + 1][ghost_position_col].g;
  124. //setting parent
  125. ary[ghost_position_row + 1][ghost_position_col].parent.first = ghost_position_row;
  126. ary[ghost_position_row + 1][ghost_position_col].parent.second = ghost_position_col;
  127.  
  128. open_set[ary[ghost_position_row + 1][ghost_position_col].id]= make_pair(ary[ghost_position_row + 1][ghost_position_col].f,make_pair(ghost_position_row + 1, ghost_position_col));
  129.  
  130. }
  131.  
  132. }
  133.  
  134.  
  135. // right
  136. if (ary[ghost_position_row ][ghost_position_col + 1].pixel != '0' &&ary[ghost_position_row][ghost_position_col + 1].AI !=y && close_set.count(ary[ghost_position_row ][ghost_position_col+1].id) == 0)
  137. {
  138.  
  139.  
  140. if (open_set.count(ary[ghost_position_row ][ghost_position_col+1].id) == 0)
  141. {
  142.  
  143.  
  144. ary[ghost_position_row][ghost_position_col + 1].h = (abs(ghost_position_row - target_first_row) + abs(ghost_position_col + 1 - target_first_col));
  145. ary[ghost_position_row][ghost_position_col + 1].g = ary[ghost_position_row][ghost_position_col].g + 1;
  146. ary[ghost_position_row][ghost_position_col + 1].f = ary[ghost_position_row][ghost_position_col+1].h + ary[ghost_position_row][ghost_position_col+1].g;
  147.  
  148.  
  149.  
  150.  
  151. //setting parent
  152. ary[ghost_position_row ][ghost_position_col+1].parent.first = ghost_position_row;
  153. ary[ghost_position_row ][ghost_position_col+1].parent.second =ghost_position_col;
  154.  
  155. open_set[ary[ghost_position_row ][ghost_position_col + 1].id]= make_pair(ary[ghost_position_row][ghost_position_col + 1].f,make_pair(ghost_position_row, ghost_position_col + 1));
  156. }
  157.  
  158.  
  159. }
  160.  
  161.  
  162. //left
  163. if (ary[ghost_position_row][ghost_position_col - 1].pixel != '0' &&ary[ghost_position_row][ghost_position_col - 1].AI != y && close_set.count(ary[ghost_position_row ][ghost_position_col-1].id) == 0)
  164. {
  165.  
  166.  
  167. if (open_set.count(ary[ghost_position_row][ghost_position_col-1].id) == 0)
  168. {
  169.  
  170.  
  171. ary[ghost_position_row][ghost_position_col - 1].h = (abs(ghost_position_row - target_first_row) + abs(ghost_position_col - 1 - target_first_col));
  172. ary[ghost_position_row][ghost_position_col - 1].g = ary[ghost_position_row][ghost_position_col].g + 1;
  173. ary[ghost_position_row][ghost_position_col - 1].f = ary[ghost_position_row][ghost_position_col - 1].h + ary[ghost_position_row][ghost_position_col - 1].g;
  174.  
  175.  
  176. //setting parent
  177. ary[ghost_position_row][ghost_position_col - 1].parent.first = ghost_position_row;
  178. ary[ghost_position_row][ghost_position_col - 1].parent.second = ghost_position_col;
  179.  
  180. open_set[ary[ghost_position_row ][ghost_position_col-1].id] =make_pair(ary[ghost_position_row][ghost_position_col - 1].f,make_pair(ghost_position_row, ghost_position_col - 1));
  181. }
  182.  
  183. }
  184.  
  185.  
  186.  
  187. // Erasing from open_set
  188. close_set.insert(ary[ghost_position_row][ghost_position_col].id);
  189. open_set.erase(ary[ghost_position_row][ghost_position_col].id);
  190.  
  191. //next position
  192. pair<int, int> Next_Ghost_pos;
  193. Next_Ghost_pos.first = Min_F(open_set).second.first;
  194. Next_Ghost_pos.second = Min_F(open_set).second.second;
  195.  
  196.  
  197. //check if target reached
  198. if (Next_Ghost_pos.first != target_first_row || Next_Ghost_pos.second != target_first_col)
  199. AI(ary, Next_Ghost_pos.first, Next_Ghost_pos.second, target_first_row, target_first_col,x);
  200.  
  201. else
  202. {
  203.  
  204. pair<int, int>pathfinder;
  205. pathfinder.first = target_first_row, pathfinder.second = target_first_col;
  206. if (x == 'R')
  207. {
  208. path.push(make_pair(pathfinder.first, pathfinder.second));
  209. ary[pathfinder.first][pathfinder.second].AI = 'R';
  210. }
  211. else
  212. {
  213. path2.push(make_pair(pathfinder.first, pathfinder.second));
  214. ary[pathfinder.first][pathfinder.second].AI = 'B';
  215. }
  216. if(x=='R')
  217. PathFind(ary, *ghost_real_pos.first, *ghost_real_pos.second, target_first_row, target_first_col,x);
  218. else
  219. PathFind(ary, *ghost2_real_pos.first, *ghost2_real_pos.second, target_first_row, target_first_col, x);
  220.  
  221.  
  222. }
  223.  
  224.  
  225. }
  226. //moving the ghost
  227. void moving (RectangleShape &ghost, pair<int, int>last, pair<int,int>now)
  228. {
  229.  
  230.  
  231. if (last.first == now.first&&last.second < now.second)
  232. ghost.move(25.0 / 10.0, 0);
  233.  
  234.  
  235. if (last.first == now.first&&last.second > now.second)
  236. ghost.move(-25.0 / 10.0, 0);
  237.  
  238.  
  239. if (last.first < now.first&&last.second == now.second)
  240. ghost.move(0, 25.0 / 10.0);
  241.  
  242.  
  243. if (last.first > now.first&&last.second == now.second)
  244. ghost.move(0, -25.0 / 10.0);
  245.  
  246.  
  247.  
  248. }
  249. //next astar search loc
  250. pair<int,int> next (pair<int, int>last, pair<int, int>now,pair<int,int>red)
  251. {
  252. if (last.first == now.first&&last.second < now.second)
  253. return make_pair(red.first, red.second + 1);
  254. if (last.first == now.first&&last.second > now.second)
  255. return make_pair(red.first, red.second - 1);
  256. if (last.first < now.first&&last.second == now.second)
  257. return make_pair(red.first+ 1, red.second );
  258. if (last.first > now.first&&last.second == now.second)
  259. return make_pair(red.first-1, red.second );
  260. }
  261.  
  262. //drawing function of the map
  263. bool CheckFront = 1, CheckBack = 1;
  264. bool pickupschecker[36][28] = { { 0 } };
  265. void drawing(RenderWindow &w, Astar ary[36][28], RectangleShape box, CircleShape pac, RectangleShape pickup, bool pickupschecker[36][28],RectangleShape ghost1)
  266. {
  267. w.draw(box);
  268. w.draw(pac);
  269. w.draw(ghost1);
  270. for (int i = 0; i < 28; i++)
  271. {
  272. for (int j = 0; j < 36; j++)
  273. {
  274. if (ary[j][i].pixel != '0')
  275. {
  276. pickup.setPosition(i * 25, j * 25);
  277.  
  278. pickup.setOrigin(-12.5, -12.5);
  279.  
  280. if (pac.getGlobalBounds().intersects(pickup.getGlobalBounds()))
  281. pickupschecker[j][i] = 1;
  282.  
  283. if (!pickupschecker[j][i])
  284. w.draw(pickup);
  285. }
  286.  
  287. }
  288. }
  289. w.display();
  290. w.clear();
  291. }
  292. char pacman_movement(Astar map[36][28], char x,int locmap1,int locmap2 )
  293. {
  294.  
  295.  
  296. if (Keyboard::isKeyPressed(Keyboard::Right))
  297. {
  298. prevchoice='d';
  299. if( (map[locmap1][locmap2].pixel == '+' || map[locmap1][locmap2].pixel == '-' || map[locmap1][locmap2].pixel == 'u' || map[locmap1][locmap2].pixel == 'd' || map[locmap1][locmap2].pixel == '<' || map[locmap1][locmap2].pixel == '*'))
  300. {
  301. if (map[locmap1][locmap2].pixel != '>')
  302. x = 'd'; // will change the column
  303. }
  304. }
  305. else if (Keyboard::isKeyPressed(Keyboard::Left))
  306. {
  307. prevchoice='a';
  308. if ( (map[locmap1][locmap2].pixel == '+' || map[locmap1][locmap2].pixel == '-' || map[locmap1][locmap2].pixel == 'u' || map[locmap1][locmap2].pixel == 'd' || map[locmap1][locmap2].pixel == '>' || map[locmap1][locmap2].pixel == '/' ) && map[locmap1][locmap2].pixel != '<')
  309. {
  310. if (map[locmap1][locmap2].pixel != '<')
  311. x = 'a';
  312. }
  313. }
  314. else if (Keyboard::isKeyPressed(Keyboard::Up))
  315. {
  316. prevchoice='w';
  317. if ( (map[locmap1][locmap2].pixel == '+' || map[locmap1][locmap2].pixel == '|' || map[locmap1][locmap2].pixel == '>' || map[locmap1][locmap2].pixel == 'd' || map[locmap1][locmap2].pixel == '<' ) && map[locmap1][locmap2].pixel != 'u')
  318. {
  319. if (map[locmap1][locmap2].pixel != 'u')
  320. x = 'w';
  321. }
  322. }
  323. else if (Keyboard::isKeyPressed(Keyboard::Down))
  324. {
  325. prevchoice='s';
  326. if( (map[locmap1][locmap2].pixel == '+' || map[locmap1][locmap2].pixel == '|' || map[locmap1][locmap2].pixel == 'u' || map[locmap1][locmap2].pixel == '>' || map[locmap1][locmap2].pixel == '<') && map[locmap1][locmap2].pixel != 'd')
  327. {
  328. if (map[locmap1][locmap2].pixel != 'd')
  329. x = 's';
  330. }
  331.  
  332. }
  333. if (prevchoice == 'a' && (map[locmap1][locmap2].pixel=='+'||map[locmap1][locmap2].pixel=='>'||map[locmap1][locmap2].pixel=='u'||map[locmap1][locmap2].pixel=='d'))
  334. {
  335. x=prevchoice;
  336. prevchoice='p';
  337. }
  338. else if(prevchoice == 'd' && (map[locmap1][locmap2].pixel=='+'||map[locmap1][locmap2].pixel=='<'||map[locmap1][locmap2].pixel=='u'||map[locmap1][locmap2].pixel=='d'))
  339. {
  340. x=prevchoice;
  341. prevchoice='p';
  342. }
  343. else if (prevchoice == 'w' && (map[locmap1][locmap2].pixel=='+'||map[locmap1][locmap2].pixel=='>'||map[locmap1][locmap2].pixel=='<'||map[locmap1][locmap2].pixel=='d'))
  344. {
  345. x=prevchoice;
  346. prevchoice='p';
  347. }
  348. else if (prevchoice == 's' && (map[locmap1][locmap2].pixel=='+'||map[locmap1][locmap2].pixel=='>'||map[locmap1][locmap2].pixel=='u'||map[locmap1][locmap2].pixel=='<'))
  349. {
  350. x=prevchoice;
  351. prevchoice='p';
  352. }
  353. return x;
  354. }
  355. int main()
  356. {
  357. bool switcher = 0;
  358. //ghost
  359. RectangleShape ghost(Vector2f(25.0f, 25.0f));
  360. ghost.setPosition(26*25, 4*25);
  361. ghost.setFillColor(Color::Red);
  362. //ghost 2
  363. RectangleShape ghost2(Vector2f(25.0f, 25.0f));
  364. ghost2.setPosition(26 * 25, 4 * 25);
  365. ghost2.setFillColor(Color::Blue);
  366. pair<int, int>current_ghost2_pos=make_pair(5,26),current_ghost1_pos = make_pair(4, 26);
  367. //ghost position
  368. pair<int, int>Blueghost_pos=make_pair(5,26),Redghost_pos = make_pair(4 , 26); //first row , sec column
  369.  
  370.  
  371.  
  372. ghost_real_pos.first = &Redghost_pos.first, ghost_real_pos.second = &Redghost_pos.second;
  373. ghost2_real_pos.first = &Blueghost_pos.first, ghost2_real_pos.second = &Blueghost_pos.second;
  374.  
  375.  
  376. //disabling the ai at portals
  377. pair<int, int>rightportal_ai = make_pair(5, 17);
  378. pair<int, int>leftportal_ai = make_pair(22, 17);
  379. bool disable_ai_at_left_portal = 0;
  380. bool disable_ai_at_righ_portal = 0;
  381. //pair of ai movement right and form back
  382. pair< int, int > target_front = make_pair(4, 26);
  383. pair< int, int > target_back = make_pair(4, 1);
  384.  
  385. bool target_front_arrived = 0;
  386. bool target_back_arrived = 0;
  387.  
  388. int locmap1 = 4, locmap2 = 1;
  389. char x = 'p';
  390. RenderWindow gameplay(VideoMode(700, 750), "GamePlay", Style::Default);
  391. Astar map[36][28];
  392.  
  393. ifstream pac;
  394. // Map
  395. Texture layout;
  396. RectangleShape Maptexture(Vector2f(750, 800));
  397. Maptexture.setPosition(-22, 53);
  398. layout.loadFromFile("Test1.png");
  399. Maptexture.setTexture(&layout);
  400. // pickups
  401. RectangleShape pickup(Vector2f(5.0f, 5.0f));
  402. pickup.setFillColor(Color::White);
  403.  
  404. //make sure to use the new map file
  405. pac.open("Pac2.txt");
  406. int r = 0, id = 0;
  407. while (!pac.eof())
  408. {
  409. for (int i = 0; i < 28; i++)
  410. {
  411. pac >> map[r][i].pixel;
  412.  
  413. id++;
  414. }
  415.  
  416. r++;
  417. }
  418. pac.close();
  419. //setting the id
  420. r = 0;
  421. for (int i = 0; i < 36; i++)
  422. {
  423. for (int j = 0; j < 28; j++)
  424. {
  425. map[i][j].id =r ;
  426.  
  427. cout << map[i][j].pixel << " ";
  428. r++;
  429. }
  430. cout << endl;
  431. }
  432. cout << endl << endl;
  433. //just tracing
  434. /*for (int i = 0; i < 36; i++)
  435. {
  436. for (int j = 0; j < 28; j++)
  437. {
  438. cout << j << " ";
  439.  
  440. }
  441. cout << endl;
  442. }
  443. */
  444. // wall unit
  445. RectangleShape Wallunit;
  446. float Wallunit_x = 25.0f, Wallunit_y = 25.0f;
  447. Wallunit.setSize(Vector2f(Wallunit_x, Wallunit_y));
  448.  
  449. // player
  450. CircleShape player(17);
  451. player.setFillColor(Color::Yellow);
  452. player.setPosition(25, 100);
  453. player.setOrigin(0, 1);
  454.  
  455. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker,ghost);
  456.  
  457. //path
  458. int size = path.size();
  459. while (gameplay.isOpen())
  460. {
  461.  
  462.  
  463.  
  464.  
  465.  
  466. AI(map, Redghost_pos.first, Redghost_pos.second, locmap1, locmap2,'R');
  467.  
  468. size = path.size();
  469.  
  470.  
  471.  
  472. Event e;
  473. while (gameplay.pollEvent(e))
  474. if (e.type == e.Closed)
  475. gameplay.close();
  476.  
  477. // check the movement
  478. x = pacman_movement(map,x,locmap1,locmap2);
  479.  
  480. // portals working successfully
  481. if (map[locmap1][locmap2].pixel == '/'&&x == 'a') {
  482. locmap2 = 28;
  483.  
  484.  
  485. player.setPosition(Vector2f(float(28 * 25), float(17 * 25)));
  486.  
  487. }
  488. else if (map[locmap1][locmap2].pixel == '*'&&x == 'd')
  489. {
  490. locmap2 = -1;
  491.  
  492. player.setPosition(Vector2f(float(-25), float(17 * 25)));
  493.  
  494. }
  495.  
  496. //
  497. pair<int, int>last,cur,last2,cur2;
  498. if (path.size()!=1)
  499. {
  500. last = make_pair(path.top().first, path.top().second);
  501. path.pop();
  502. cur = make_pair(path.top().first, path.top().second);
  503.  
  504. }
  505. /*if (path2.size() != 1)
  506. {
  507. last2 = make_pair(path2.top().first, path2.top().second);
  508. path2.pop();
  509. cur2 = make_pair(path2.top().first, path2.top().second);
  510. }*/
  511.  
  512. bool ghost_left = 0;
  513. //movement in all directions
  514.  
  515. if (x == 'd'&&map[locmap1][locmap2 + 1].pixel != '0')
  516. {
  517.  
  518. locmap2++;
  519. Redghost_pos = next(last, cur, Redghost_pos);
  520. // Blueghost_pos = next(last2, cur2, Blueghost_pos);
  521. for (int i = 0; i < 10; i++)
  522. {
  523.  
  524. player.move(25.0 / 10.0, 0);
  525. moving( ghost, last, cur);
  526. // moving (ghost2, last2, cur2);
  527. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker, ghost);
  528.  
  529. }
  530. }
  531. else if (x == 's'&&map[locmap1 + 1][locmap2].pixel != '0')
  532. {
  533.  
  534. locmap1++;
  535.  
  536. Redghost_pos = next(last, cur, Redghost_pos);
  537.  
  538. for (int i = 0; i < 10; i++)
  539. {
  540. player.move(0, 25.0 / 10.0);
  541. moving(ghost, last, cur);
  542.  
  543.  
  544. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker,ghost);
  545. }
  546. }
  547. else if (x == 'a'&&map[locmap1][locmap2 - 1].pixel != '0')
  548. {
  549. locmap2--;
  550. Redghost_pos = next(last, cur, Redghost_pos);
  551. for (int i = 0; i < 10; i++)
  552. {
  553. player.move(-(25.0 / 10.0), 0);
  554. moving( ghost, last, cur);
  555. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker,ghost);
  556. }
  557. }
  558. else if (x == 'w'&&map[locmap1 - 1][locmap2].pixel != '0')
  559. {
  560. locmap1--;
  561. Redghost_pos = next(last, cur, Redghost_pos);
  562. for (int i = 0; i < 10; i++)
  563. {
  564. player.move(0, -(25.0 / 10.0));
  565. moving( ghost, last, cur);
  566. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker, ghost);
  567.  
  568. }
  569. }
  570. else
  571. {
  572. Redghost_pos = next(last, cur, Redghost_pos);
  573. for (int i = 0; i < 10; i++)
  574. {
  575.  
  576. moving(ghost, last, cur);
  577. drawing(gameplay, map, Maptexture, player, pickup, pickupschecker, ghost);
  578.  
  579.  
  580. }
  581. }
  582.  
  583. target_front.first = 26;
  584. target_front.second = 4;
  585. //clearing old data
  586. while (1)
  587. {
  588. if (!path.empty())
  589. path.pop();
  590. else
  591. break;
  592. }
  593. open_set.clear();
  594. close_set.clear();
  595. /*for (int i = 0; i < 36; i++)
  596. {
  597. for (int j = 0; j < 28; j++)
  598. {
  599. cout << map[i][j].AI << " ";
  600. }
  601. cout << endl;
  602.  
  603. }*/
  604. //make sure to use the new map file
  605. pac.open("Pac2.txt");
  606. int r = 0;
  607. while (!pac.eof())
  608. {
  609. for (int i = 0; i < 28; i++)
  610. {
  611. pac >> map[r][i].pixel;
  612.  
  613.  
  614. }
  615.  
  616. r++;
  617. }
  618. pac.close();
  619. //setting the id
  620. r = 0;
  621. for (int i = 0; i < 36; i++)
  622. {
  623. for (int j = 0; j < 28; j++)
  624. {
  625. map[i][j].id = r;
  626.  
  627.  
  628. r++;
  629. }
  630. }
  631.  
  632. gameplay.setFramerateLimit(90);
  633. }
  634. return 0;
  635. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement