AllenYuan

Untitled

May 27th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <time.h>
  3. using namespace sf;
  4.  
  5. int main()
  6. {
  7. srand(time(0));
  8.  
  9. RenderWindow app(VideoMode(480, 480), "Minesweeper");
  10.  
  11. int w = 32; // width of a texture rectangle
  12. int grid[12][12]; // grid, encoded by index of rectangle in tiles.jpg to display
  13. int sgrid[12][12]; // shown grid
  14.  
  15. // load texture/sprite
  16. Texture t;
  17. t.loadFromFile("/Users/alleyuan/code-snippets/16_games/05 Minesweeper/images/tiles.jpg");
  18. Sprite s(t);
  19.  
  20. // paint a grid of untouched squares
  21. for (int i = 1; i <= 10; i++)
  22. for (int j = 1; j <= 10; j++)
  23. {
  24. sgrid[i][j] = 10;
  25. }
  26.  
  27. while (app.isOpen()) // game loop
  28. {
  29. // event handlers
  30. Event e;
  31. while (app.pollEvent(e))
  32. {
  33. if (e.type == Event::Closed)
  34. app.close();
  35. }
  36.  
  37. // redraw sgrid
  38. app.clear(Color::White);
  39. for (int i = 1; i <= 10; i++)
  40. for (int j = 1; j <= 10; j++)
  41. {
  42. s.setTextureRect(IntRect(sgrid[i][j]*w,0,w,w));
  43. s.setPosition(i*w, j*w);
  44. app.draw(s);
  45. }
  46. app.display();
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment