Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML\Graphics.hpp>
- #include <SFML\Window.hpp>
- int points = 0;
- int main() {
- sf::RenderWindow screen(sf::VideoMode(800, 600), "Flashing Snake");
- screen.setFramerateLimit(30);
- sf::Font font;
- font.loadFromFile("stuff/font/bas.ttf");
- sf::Text text("Punkty: ", font);
- text.setCharacterSize(65);
- sf::Texture textureApple;
- sf::Texture textureSnake;
- sf::Sprite apple;
- apple.setTexture(textureApple);
- apple.setTextureRect(sf::IntRect(10, 10, 20, 20));
- apple.setPosition(150, 200);
- apple.setColor(sf::Color::Red);
- sf::Sprite snake;
- snake.setTexture(textureSnake);
- snake.setTextureRect(sf::IntRect(10, 10, 32, 32));
- snake.setPosition(190, 270);
- snake.setColor(sf::Color::Green);
- while (screen.isOpen())
- {
- sf::Event event;
- while (screen.pollEvent(event)) {
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- snake.move(0, -10);
- screen.clear();
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
- snake.move(0, 10);
- screen.clear();
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- snake.move(-10, 0);
- screen.clear();
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- snake.move(10, 0);
- screen.clear();
- }
- if (event.type == sf::Event::Closed)
- {
- screen.close();
- }
- }
- if (snake.getGlobalBounds().intersects(apple.getGlobalBounds()))
- {
- apple.setPosition(400, 200);
- }
- screen.draw(apple);
- screen.draw(snake);
- screen.draw(text);
- screen.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement