Don't like ads? PRO users don't see any ads ;-)
Guest

Code qui crash

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.03 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void Level::LoadLevel(std::string fileName)
  2. {
  3.         int loadCounterX = 0;
  4.         int loadCounterY = 0;
  5.         std::ifstream openfile(fileName);
  6.  
  7.         if(openfile.is_open())
  8.         {
  9.  
  10.                 openfile >> w >> h;
  11.  
  12.         while(!openfile.eof())
  13.  
  14.         {
  15.  
  16.         openfile >> mapInt[loadCounterX][loadCounterY];
  17.         loadCounterX++;
  18.  
  19.         if(loadCounterX >= w)
  20.         {
  21.         loadCounterX = 0;
  22.         loadCounterY++;
  23.         }
  24.         }
  25.         }
  26.  
  27.  
  28. }
  29.  
  30. void Level::DrawLevel(sf::RenderWindow& window)
  31. {
  32.         sf::Texture tile0;
  33.         sf::Texture tile1;
  34.         sf::Texture tile2;
  35.         sf::Texture tile3;
  36.  
  37.         tile0.loadFromFile("grass.png");
  38.         tile1.loadFromFile("roadUp.png");
  39.         tile2.loadFromFile("roadCenter.png");
  40.         tile3.loadFromFile("roadDown.png");
  41.  
  42.  
  43.         sf::Sprite tile;
  44.         for(int j = 0; j < w; j++)
  45.         {
  46.                 for(int i = 0; i < h; i++)
  47.                 {
  48.                         if(mapInt[i][j] == 0)
  49.                         {
  50.                                 tile.setTexture(tile0);
  51.                         }
  52.                         else if(mapInt[i][j] == 1)
  53.                         {
  54.                                 tile.setTexture(tile1);
  55.                         }
  56.                         else
  57.                         {
  58.                                 std::cerr << "Le fileStream marche pas" << std::endl;
  59.                         }
  60.  
  61.                         tile.setPosition(j*64, i*64);
  62.                         window.draw(tile);
  63.                 }
  64.  
  65.         }
  66. }