Advertisement
erzis

Untitled

Nov 22nd, 2016
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <SFML\Graphics.hpp>
  2. #include <SFML\Window.hpp>
  3.  
  4. int points = 0;
  5.  
  6. int main() {
  7.  
  8. sf::RenderWindow screen(sf::VideoMode(800, 600), "Flashing Snake");
  9. screen.setFramerateLimit(30);
  10.  
  11.  
  12. sf::Font font;
  13. font.loadFromFile("stuff/font/bas.ttf");
  14.  
  15. sf::Text text("Punkty: ", font);
  16. text.setCharacterSize(65);
  17.  
  18. sf::Texture textureApple;
  19. sf::Texture textureSnake;
  20.  
  21. sf::Sprite apple;
  22. apple.setTexture(textureApple);
  23. apple.setTextureRect(sf::IntRect(10, 10, 20, 20));
  24. apple.setPosition(150, 200);
  25. apple.setColor(sf::Color::Red);
  26.  
  27. sf::Sprite snake;
  28. snake.setTexture(textureSnake);
  29. snake.setTextureRect(sf::IntRect(10, 10, 32, 32));
  30. snake.setPosition(190, 270);
  31. snake.setColor(sf::Color::Green);
  32.  
  33. while (screen.isOpen())
  34. {
  35. sf::Event event;
  36. while (screen.pollEvent(event)) {
  37. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  38. {
  39. snake.move(0, -10);
  40. screen.clear();
  41.  
  42. }
  43. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  44. {
  45. snake.move(0, 10);
  46. screen.clear();
  47.  
  48. }
  49. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  50. {
  51. snake.move(-10, 0);
  52. screen.clear();
  53. }
  54. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  55. {
  56. snake.move(10, 0);
  57. screen.clear();
  58. }
  59. if (event.type == sf::Event::Closed)
  60. {
  61. screen.close();
  62. }
  63. }
  64.  
  65. if (snake.getGlobalBounds().intersects(apple.getGlobalBounds()))
  66. {
  67. apple.setPosition(400, 200);
  68. }
  69.  
  70. screen.draw(apple);
  71. screen.draw(snake);
  72. screen.draw(text);
  73. screen.display();
  74. }
  75. return EXIT_SUCCESS;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement