SFML Pong, but object oriented

functions.cpp 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. float Ball::getRadius() const {
  35. return radius;
  36. }
  37. Paddle::Paddle() {
  38. size.x = 25;
  39. size.y = 100;
  40. setSize(sf::Vector2f(25, 100) - sf::Vector2f(3, 3));
  41. setOutlineThickness(3);
  42. setOutlineColor(sf::Color::Black);
  43. setFillColor(sf::Color(200, 200, 200));
  44. setOrigin(sf::Vector2f(25, 100) / 2.f);
  45. }
  46. float Paddle::getY() const {
  47. return getPosition().y;
  48. }
  49. float Paddle::getX() const {
  50. return getPosition().x;
  51. }
  52. void Paddle::setPosition(float x, float y) {
  53. sf::Transformable::setPosition(x, y);
  54. }
  55. sf::Vector2f Paddle::getSize() const {
  56. return size;
  57. }
  58. void Paddle::move(float x, float y) {
  59. sf::Transformable::move(x, y);
  60. }
  61. Game::Game() {
  62. isPlaying = false;
  63. AITime = sf::seconds(0.1);
  64. paddleSpeed = 400;
  65. rightPaddleSpeed = 0;
  66. ballAngle = 0;
  67. }