erzis

Untitled

Dec 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <iostream>
  3. #include "Character.cpp"
  4.  
  5. int main() {
  6.  
  7. enum Direction { Down, Left, Up, Right };
  8.  
  9. sf::Vector2i source(0, Down);
  10.  
  11. sf::RenderWindow window(sf::VideoMode(800, 800), "Adventure game");
  12. window.setFramerateLimit(60);
  13.  
  14. Character player = Character();
  15.  
  16. while (window.isOpen())
  17. {
  18. sf::Event event;
  19. while (window.pollEvent(event))
  20. {
  21. if (event.type == sf::Event::Closed)
  22. window.close();
  23. }
  24.  
  25. if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  26. {
  27. source.y = Up;
  28. player.Move(source.y);
  29. }
  30. else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
  31. {
  32. source.y = Down;
  33. player.Move(source.y);
  34. }
  35. else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  36. {
  37. source.y = Right;
  38. player.Move(source.y);
  39. }
  40. else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
  41. {
  42. source.y = Left;
  43. player.Move(source.y);
  44. }
  45. window.clear(sf::Color::White);
  46. window.draw(player.chSprite);
  47. window.display();
  48. }
  49. return EXIT_SUCCESS;
  50. }
Add Comment
Please, Sign In to add comment