AllenYuan

Untitled

May 25th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <time.h>
  3. using namespace sf;
  4.  
  5. int main()
  6. {
  7.   RenderWindow app(VideoMode(520, 450), "Arkanoid Game!");
  8.   app.setFramerateLimit(60);
  9.  
  10.   // load textures
  11.   Texture t1,t2,t3,t4;
  12.   t1.loadFromFile("/Users/alleyuan/code-snippets/16_games/03 Arkanoid/images/block01.png");
  13.   t2.loadFromFile("/Users/alleyuan/code-snippets/16_games/03 Arkanoid/images/background.jpg");
  14.   t3.loadFromFile("/Users/alleyuan/code-snippets/16_games/03 Arkanoid/images/ball.png");
  15.   t4.loadFromFile("/Users/alleyuan/code-snippets/16_games/03 Arkanoid/images/paddle.png");
  16.  
  17.   // set sprite positions
  18.   Sprite sBackground(t2), sBall(t3), sPaddle(t4);
  19.   sPaddle.setPosition(300, 440);
  20.   sBall.setPosition(300,300);
  21.  
  22.   Sprite block[1000]; // blocks
  23.  
  24.   int n = 0; // set block positions
  25.   for (int i = 1; i <= 10; i++)
  26.   for (int j = 1; j <= 10; j++)
  27.   {
  28.     block[n].setTexture(t1);
  29.     block[n].setPosition(i*43,j*20);
  30.     n++;
  31.   }
  32.  
  33.   // game loop
  34.   while (app.isOpen())
  35.   {
  36.     Event e;
  37.     while (app.pollEvent(e))
  38.     {
  39.       if (e.type == Event::Closed)
  40.         app.close();
  41.     }
  42.  
  43.     // draw sprites
  44.     app.clear();
  45.     app.draw(sBackground);
  46.     app.draw(sBall);
  47.     app.draw(sPaddle);
  48.  
  49.     for (int i = 0; i < n; i++)
  50.       app.draw(block[i]);
  51.  
  52.     app.display();
  53.   }
  54.  
  55.   return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment