AllenYuan

Untitled

May 25th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <time.h>
  3. using namespace sf;
  4.  
  5. struct point
  6. { int x,y; };
  7.  
  8. int main()
  9. {
  10.   srand(time(0));
  11.   RenderWindow app(VideoMode(400, 533), "Doodle Game!"); // render app
  12.   app.setFramerateLimit(60);
  13.  
  14.   Texture t1,t2,t3;
  15.   t1.loadFromFile("/Users/alleyuan/code-snippets/16_games/02 Doodle Jump/images/background.png");
  16.   t2.loadFromFile("/Users/alleyuan/code-snippets/16_games/02 Doodle Jump/images/platform.png");
  17.   t3.loadFromFile("/Users/alleyuan/code-snippets/16_games/02 Doodle Jump/images/doodle.png");
  18.  
  19.   Sprite sBackground(t1), sPlat(t2), sPers(t3);
  20.  
  21.   point plat[20]; // platform locations
  22.  
  23.   for (int i = 0; i < 10; i++) // set platform locations
  24.   {
  25.     plat[i].x = rand()%400;
  26.     plat[i].y = rand()%533;
  27.   }
  28.  
  29.   while (app.isOpen())
  30.   {
  31.     Event e;
  32.     while (app.pollEvent(e))
  33.     {
  34.       if (e.type == Event::Closed) // close window
  35.         app.close();
  36.     }
  37.  
  38.     app.draw(sBackground);
  39.     app.draw(sPers);
  40.     for (int i = 0; i < 10; i++) // draw platforms
  41.     {
  42.       sPlat.setPosition(plat[i].x, plat[i].y);
  43.       app.draw(sPlat);
  44.     }
  45.  
  46.     app.display();
  47.   }
  48.  
  49.   return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment