SFML Pong, but object oriented

Classes.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. sf::SoundBuffer ballSoundBuffer;
  26. sf::Sound ballSound;
  27. public:
  28. Ball();
  29. Ball(int radius);
  30. void move(float x, float y);
  31. void setPosition(float x, float y);
  32. float getX() const;
  33. float getY() const;
  34. float getSpeed() const;
  35. float getRadius() const;
  36. float getAngle() const;
  37. void setAngle(float a);
  38. void checkLeftPaddle(const Paddle &leftPaddle);
  39. void checkRightPaddle(const Paddle &rightPaddle);
  40. void checkCollisions();
  41. };