Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int direction;
- int x, y;
- int main()
- {
- sf::RenderWindow window(sf::VideoMode(800, 600), "Generic name for a window");
- window.setFramerateLimit(70);
- window.setVerticalSyncEnabled(true);
- sf::RectangleShape player(sf::Vector2f(40, 40));
- player.setFillColor(sf::Color::Cyan);
- sf::Event event;
- while (window.isOpen())
- {
- window.clear(sf::Color::White);
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- if (event.type == sf::Event::KeyPressed)
- {
- if (event.key.code == sf::Keyboard::A)
- {
- direction = 1;
- }
- else if (event.key.code == sf::Keyboard::W)
- {
- direction = 2;
- }
- else if (event.key.code == sf::Keyboard::D)
- {
- direction = 3;
- }
- else if (event.key.code == sf::Keyboard::S)
- {
- direction = 4;
- }
- }
- }
- if (direction == 1)
- {
- if (x == 0)
- direction = 3;
- else
- x -= 10;
- }
- else if (direction == 2)
- {
- if (y == 0)
- direction = 4;
- else
- y -= 10;
- }
- else if (direction == 3)
- {
- if ((x + 40) == 800)
- direction = 1;
- else
- x += 10;
- }
- else if (direction == 4)
- {
- if ((y + 40) == 600)
- direction = 2;
- else
- y += 10;
- }
- player.setPosition(x, y);
- window.draw(player);
- window.display();
- }
- int pause; cin >> pause; //Pause the program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement