SFML Pong, but object oriented

functions.cpp 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "Ball.h"
  2. #include "Paddle.h"
  3. #include "Game.h"
  4. Ball::Ball() {
  5. setRadius(radius - 3);
  6. setOutlineThickness(3);
  7. setOutlineColor(sf::Color::Black);
  8. setFillColor(sf::Color::White);
  9. setOrigin(radius / 2, radius / 2);
  10. }
  11. Ball::Ball(int r) {
  12. setRadius(r - 3);
  13. setOutlineThickness(3);
  14. setOutlineColor(sf::Color::Black);
  15. setFillColor(sf::Color::White);
  16. setOrigin(r / 2, r / 2);
  17. radius = r;
  18. }
  19. float Ball::getX() const {
  20. return getPosition().x;
  21. }
  22. float Ball::getY() const {
  23. return getPosition().y;
  24. }
  25. void Ball::setPosition(float x, float y) {
  26. sf::Transformable::setPosition(x, y);
  27. }
  28. float Ball::getSpeed() const {
  29. return ballSpeed;
  30. }
  31. void Ball::move(float x, float y) {
  32. sf::Transformable::move(x, y);
  33. }
  34. Paddle::Paddle() {
  35. size.x = 25;
  36. size.y = 100;
  37. setSize(sf::Vector2f(25, 100) - sf::Vector2f(3, 3));
  38. setOutlineThickness(3);
  39. setOutlineColor(sf::Color::Black);
  40. setFillColor(sf::Color(200, 200, 200));
  41. setOrigin(sf::Vector2f(25, 100) / 2.f);
  42. }
  43. float Paddle::getY() const {
  44. return getPosition().y;
  45. }
  46. float Paddle::getX() const {
  47. return getPosition().x;
  48. }
  49. void Paddle::setPosition(float x, float y) {
  50. sf::Transformable::setPosition(x, y);
  51. }
  52. sf::Vector2f Paddle::getSize() const {
  53. return size;
  54. }
  55. void Paddle::move(float x, float y) {
  56. sf::Transformable::move(x, y);
  57. }
  58. Ball::Ball() {
  59. const sf::Time AITime = sf::seconds(0.1f);
  60. const float paddleSpeed = 400.f;
  61. float rightPaddleSpeed = 0.f;
  62. float ballAngle = 0.f;
  63. }