Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. #define BLOCK_SIZE 50
  6.  
  7. class Block
  8. {
  9.     private:
  10.         sf::Image blockImage;
  11.         sf::Texture blockTexture;
  12.         sf::Sprite block;
  13.     public:
  14.         Block();
  15.         void render(sf::RenderWindow& window) {window.draw(block);}
  16. };
  17.  
  18. Block::Block()
  19. {
  20.     blockImage.create(BLOCK_SIZE, BLOCK_SIZE);
  21.     for(size_t x = 0; x != BLOCK_SIZE; ++x)
  22.         for(size_t y = 0; y != BLOCK_SIZE; ++y)
  23.             blockImage.setPixel(x, y, sf::Color::Blue);
  24.     blockTexture.loadFromImage(blockImage);
  25.     block.setTexture(blockTexture);
  26.     block.setPosition(400, 300);
  27. }
  28.  
  29. int main()
  30. {
  31.     sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test", sf::Style::Close);
  32.     window.setFramerateLimit(60);
  33.     sf::Event windowEvent;
  34.  
  35.     std::vector<Block> blockList;
  36.     blockList.push_back(Block());
  37.  
  38.     while(window.isOpen())
  39.     {
  40.         while(window.pollEvent(windowEvent))
  41.             if(windowEvent.type == sf::Event::Closed)
  42.                 window.close();
  43.  
  44.         window.clear(sf::Color());
  45.         for(auto&& block : blockList)
  46.             block.render(window);
  47.         window.display();
  48.     }
  49.  
  50.     return EXIT_SUCCESS;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement