Advertisement
erzis

Untitled

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