Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <vector>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "ObiektGraficzny.h"
  6. #include "Ciastko.h"
  7. #include "Waz.h"
  8. using namespace std;
  9. using namespace sf;
  10.  
  11.  
  12. int main()
  13. {
  14. float x = 0.0;
  15. float y = 0.0;
  16. bool wynik;
  17. vector<Ciastko*> ciastka;
  18. Ciastko ciastko(30, 30, Color::Red, 7, 7);
  19. Ciastko ciastko2(50, 50, Color::Red, 6, 6);
  20. for (int i = 0; i < 9; i++)
  21. {
  22. x = rand() % 800 + 1;
  23. y = rand() % 600 + 1;
  24. ciastka.push_back(new Ciastko(50.0, 50.0, Color::Blue, x, y));
  25. }
  26.  
  27. Waz waz(30.0, 30.0, Color::Green, 4.0, 4.0);
  28. waz.dodajOgon();
  29. sf::RenderWindow window(VideoMode(800,600),"Snake");
  30. sf::Event event;
  31. while (window.isOpen())
  32. {
  33.  
  34. while (window.pollEvent(event))
  35. {
  36. if (event.type == sf::Event::Closed)
  37. {
  38. window.close();
  39. }
  40.  
  41. }
  42. window.clear();
  43.  
  44. if (Keyboard::isKeyPressed(Keyboard::Left))
  45. {
  46. waz.idzWezem("lewo");
  47. }
  48.  
  49. if (Keyboard::isKeyPressed(Keyboard::Right))
  50. {
  51. waz.idzWezem("prawo");
  52. }
  53.  
  54. if (Keyboard::isKeyPressed(Keyboard::Up))
  55. {
  56. waz.idzWezem("gora");
  57. }
  58.  
  59. if (Keyboard::isKeyPressed(Keyboard::Down))
  60. {
  61. waz.idzWezem("dol");
  62. }
  63. waz.rysujWeza(window);
  64. ciastko.rysuj(window);
  65. wynik=waz.czyWazZjadlCiastko(ciastko);
  66. if (wynik == true)
  67. {
  68. ciastko.ustawKolor();
  69. ciastko.rysuj(window);
  70. }
  71. window.display();
  72. sf::sleep(sf::milliseconds(100));
  73. }
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement