Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. //#define _CRT_SECURE_NO_WARNINGS
  2. //
  3. //#include <cstdio>
  4. //#include <cstdlib>
  5. //#include <cstdint>
  6. //#include <cstring>
  7. //
  8. //int main(void)
  9. //{
  10. //  const size_t SUDOKU_WIDTH = 9;
  11. //  const size_t SUDOKU_SIZE = SUDOKU_WIDTH * SUDOKU_WIDTH;
  12. //  FILE* sudoku_file = fopen("sudoku.txt", "r+");
  13. //  uint8_t sudoku[SUDOKU_SIZE];
  14. //  const size_t MAX_LINE_SIZE = 25;
  15. //  size_t i = 0;
  16. //
  17. //  char line[MAX_LINE_SIZE], * p;
  18. //
  19. //  while (fgets(line, MAX_LINE_SIZE, sudoku_file) != NULL)
  20. //  {
  21. //      p = strtok(line, " .|-\n\t");
  22. //
  23. //      while (p != NULL && i < SUDOKU_SIZE)
  24. //      {
  25. //          sudoku[i++] = *p - '0';
  26. //          p = strtok(NULL, ".|- ");
  27. //      };
  28. //  }
  29. //
  30. //  for (i = 0; i < SUDOKU_SIZE; ++i)
  31. //  {
  32. //      printf("[%d]", (int)sudoku[i]);
  33. //      if ((i + 1) % SUDOKU_WIDTH == 0) putchar('\n');
  34. //
  35. //      fflush(stdout);
  36. //  }
  37. //
  38. //  system("PAUSE");
  39. //  return EXIT_SUCCESS;
  40. //}
  41.  
  42. int main() {
  43.     sf::RenderWindow window(sf::VideoMode(512, 512), "feet", sf::Style::Close | sf::Style::Titlebar);
  44.     sf::RectangleShape player(sf::Vector2f(100, 100));
  45.     player.setFillColor(sf::Color::Red);
  46.     player.setOrigin(50.0f, 50.0f);
  47.     player.setPosition(100, 100);
  48.     const float Gravity = 1;
  49.     int groundHeight = 440;
  50.     float moveSpeed = 1.0f, jumpSpeed = 10.0f;
  51.     sf::Vector2f velocity(sf::Vector2f(0, 0)), position(velocity);
  52.  
  53.     while (window.isOpen())
  54.     {
  55.         sf::Event event;
  56.         while (window.pollEvent(event))
  57.         {
  58.             switch (event.type)
  59.             {
  60.             case sf::Event::Closed:
  61.                 window.close();
  62.                 break;
  63.             }
  64.         }
  65.         // player.move(0, player.getPosition().y + .5f);
  66.              /*if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)){
  67.                  player.move(0.5f,0.0f);
  68.              }
  69.              if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)){
  70.                  player.move(-0.5f,0.0f);
  71.              }*/
  72.              /*if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
  73.                  sf::Vector2i mousePos = sf::Mouse::getPosition(window);
  74.                  player.setPosition((float)mousePos.x, (float)mousePos.y);
  75.              }*/
  76.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  77.             velocity.x = moveSpeed;
  78.         else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
  79.             velocity.x - moveSpeed;
  80.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
  81.             velocity.y = -jumpSpeed;
  82.  
  83.         player.move(velocity.x, velocity.y);
  84.  
  85.         if (player.getPosition().y + player.getSize().y < groundHeight || velocity.y < 0)
  86.         {
  87.             velocity.y += Gravity;
  88.         }
  89.         else {
  90.             player.setPosition(player.getPosition().x, groundHeight - player.getSize().y);
  91.             velocity.y = 0;
  92.         }
  93.         if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape)) {
  94.             window.close();
  95.  
  96.         }
  97.         window.clear(sf::Color(150, 150, 150));
  98.         window.draw(player);
  99.         window.display();
  100.     }
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement