SFML Pong, but object oriented

Classes.h 1.1KB

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