Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- int main(){
- enum Direction{Down, Left, Up, Right};
- sf::Vector2i source(0, Down);
- sf::RenderWindow window(sf::VideoMode(800, 800), "Adventure game");
- window.setFramerateLimit(60);
- sf::Texture texture;
- texture.loadFromFile("tiles/char2.png");
- sf::Sprite player(texture);
- while(window.isOpen())
- {
- sf::Event event;
- while(window.pollEvent(event))
- {
- if(event.type == sf::Event::Closed)
- window.close();
- }
- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
- {
- source.y = Up;
- player.move(0, -10);
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
- {
- source.y = Down;
- player.move(0, 10);
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
- {
- source.y = Right;
- player.move(10, 0);
- }
- else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
- {
- source.y = Left;
- player.move(-10, 0);
- }
- player.setTextureRect(sf::IntRect(source.x * 100, source.y * 130, 130, 130));
- window.clear(sf::Color::White);
- window.draw(player);
- window.display();
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment