Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Audio.hpp>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. // Inicializa a janela de desenho (800 x 600), com o título abaixo
  10. sf::RenderWindow window(sf::VideoMode(800, 600), "SFML funciona!");
  11.  
  12. // Cria uma forma ("shape") circular, com raio = 100
  13. sf::Texture tex;
  14. if(!tex.loadFromFile("data/img/car.png"))
  15. {
  16. cout << "Erro na leitura da imagem!" << endl;
  17. exit(EXIT_FAILURE);
  18. }
  19. // Cria um sprite e informa que a textura será a imagem lida:
  20. sf::Sprite img(tex);
  21.  
  22. sf::SoundBuffer buffer;
  23. if (!buffer.loadFromFile("data/sound/car.wav"))
  24. return -1;
  25. // Enquanto a janela estiver aberta...
  26. while (window.isOpen())
  27. {
  28. sf::Event event;
  29. // Enquanto há eventos para processar...
  30. while (window.pollEvent(event))
  31. {
  32. // Se o usuário clicar no botão para fechar a janela, finaliza
  33. if (event.type == sf::Event::Closed)
  34. window.close();
  35.  
  36. // Se o usuário pressionou ESC, finaliza
  37. if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
  38. window.close();
  39. }
  40.  
  41. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
  42. img.move(-0.01, 0);
  43. }
  44.  
  45. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
  46. img.move(0.01, 0);
  47. }
  48.  
  49. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
  50. img.move(0, 0.01);
  51. }
  52.  
  53. if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
  54. img.move(0, -0.01);
  55. }
  56.  
  57. // Limpa o conteúdo da janela
  58. window.clear();
  59.  
  60. // Desenha o círculo
  61. window.draw(img);
  62.  
  63. // Exibe o conteúdo da janela na tela (double buffering)
  64. window.display();
  65. }
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement