Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <vector>
- #define BLOCK_SIZE 50
- class Block
- {
- private:
- sf::Image blockImage;
- sf::Texture blockTexture;
- sf::Sprite block;
- public:
- Block();
- void render(sf::RenderWindow& window) {window.draw(block);}
- };
- Block::Block()
- {
- blockImage.create(BLOCK_SIZE, BLOCK_SIZE);
- for(size_t x = 0; x != BLOCK_SIZE; ++x)
- for(size_t y = 0; y != BLOCK_SIZE; ++y)
- blockImage.setPixel(x, y, sf::Color::Blue);
- blockTexture.loadFromImage(blockImage);
- block.setTexture(blockTexture);
- block.setPosition(400, 300);
- }
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Test", sf::Style::Close);
- window.setFramerateLimit(60);
- sf::Event windowEvent;
- std::vector<Block> blockList;
- blockList.push_back(Block());
- while(window.isOpen())
- {
- while(window.pollEvent(windowEvent))
- if(windowEvent.type == sf::Event::Closed)
- window.close();
- window.clear(sf::Color());
- for(auto&& block : blockList)
- block.render(window);
- window.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement