Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include <iostream>
- using namespace std;
- int main()
- {
- // Inicializa a janela de desenho (800 x 600), com o título abaixo
- sf::RenderWindow window(sf::VideoMode(800, 600), "SFML funciona!");
- // Cria uma forma ("shape") circular, com raio = 100
- sf::Texture tex;
- if(!tex.loadFromFile("data/img/car.png"))
- {
- cout << "Erro na leitura da imagem!" << endl;
- exit(EXIT_FAILURE);
- }
- // Cria um sprite e informa que a textura será a imagem lida:
- sf::Sprite img(tex);
- sf::SoundBuffer buffer;
- if (!buffer.loadFromFile("data/sound/car.wav"))
- return -1;
- // Enquanto a janela estiver aberta...
- while (window.isOpen())
- {
- sf::Event event;
- // Enquanto há eventos para processar...
- while (window.pollEvent(event))
- {
- // Se o usuário clicar no botão para fechar a janela, finaliza
- if (event.type == sf::Event::Closed)
- window.close();
- // Se o usuário pressionou ESC, finaliza
- if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
- window.close();
- }
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
- img.move(-0.01, 0);
- }
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
- img.move(0.01, 0);
- }
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
- img.move(0, 0.01);
- }
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
- img.move(0, -0.01);
- }
- // Limpa o conteúdo da janela
- window.clear();
- // Desenha o círculo
- window.draw(img);
- // Exibe o conteúdo da janela na tela (double buffering)
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement