SFML Pong, but object oriented

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <SFML/Graphics.hpp>
  2. #include <SFML/Audio.hpp>
  3. const int gameWidth = 800;
  4. const int gameHeight = 600;
  5. class Paddle : public sf::RectangleShape {
  6. private:
  7. float x,
  8. y;
  9. sf::Vector2f size;
  10. public:
  11. Paddle();
  12. void move(float x, float y);
  13. void draw(sf::RenderWindow);
  14. float getX() const;
  15. float getY() const;
  16. sf::Vector2f getSize() const;
  17. void setPosition(float x, float y);
  18. void render(sf::RenderWindow) const;
  19. };
  20. class Ball : public sf::CircleShape {
  21. private:
  22. float radius = 10,
  23. angle = 0;
  24. const float ballSpeed = 400;
  25. public:
  26. Ball();
  27. Ball(int radius);
  28. void move(float x, float y);
  29. void setPosition(float x, float y);
  30. float getX() const;
  31. float getY() const;
  32. float getSpeed() const;
  33. float getRadius() const;
  34. float getAngle() const;
  35. void setAngle(float a);
  36. void checkLeftPaddle(const Paddle &leftPaddle, sf::Sound &ballSound);
  37. void checkRightPaddle(const Paddle &rightPaddle, sf::Sound &ballSound);
  38. void checkCollisions(sf::Sound &ballsound);
  39. };