Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using Shape = boost::variant<Rectangle, Circle>;
  2.  
  3. enum Shape_Type {
  4.  
  5. RECTANGLE, CIRCLE
  6.  
  7. };
  8.  
  9. struct Position {
  10.  
  11. float x, y;
  12.  
  13. Position(float position_x, float position_y) {
  14.  
  15. x = position_x;
  16.  
  17. y = position_y;
  18.  
  19. }
  20.  
  21. };
  22.  
  23. class Object : private Shape {
  24.  
  25. private:
  26.  
  27. std::string name;
  28.  
  29. public:
  30.  
  31. Object() = default;
  32.  
  33. Object(std::string name, Rectangle rectangle) : name(name), Shape(rectangle) {}
  34.  
  35. Object(std::string name, Circle circle) : name(name), Shape(circle) {}
  36.  
  37. void setPosition(float, float);
  38.  
  39. void setAngle(float);
  40.  
  41. Shape* getShape() {
  42.  
  43. Shape* shape = this;
  44.  
  45. return shape;
  46. }
  47.  
  48. Position getPosition();
  49.  
  50. const std::string* getName() {
  51.  
  52. return &name;
  53. }
  54.  
  55. };
  56.  
  57. class Rectangle {
  58.  
  59. private:
  60.  
  61. sf::RectangleShape rectangleshape;
  62.  
  63. public:
  64.  
  65. Rectangle() = default;
  66.  
  67. Rectangle(float width, float height) : rectangleshape(sf::RectangleShape(sf::Vector2f(width, height))) {}
  68.  
  69. void setPosition(float position_x, float position_y) {
  70.  
  71. rectangleshape.setPosition(position_x, position_y);
  72.  
  73. }
  74.  
  75. void setAngle(float angle) {
  76.  
  77. rectangleshape.setRotation(angle);
  78.  
  79. }
  80.  
  81. sf::RectangleShape* getRectangleShape() {
  82.  
  83. return &rectangleshape;
  84. }
  85.  
  86. Position getPosition() {
  87.  
  88. return Position(rectangleshape.getPosition().x, rectangleshape.getPosition().y);
  89. }
  90.  
  91. };
  92.  
  93. class Circle {
  94.  
  95. private:
  96.  
  97. sf::CircleShape circleshape;
  98.  
  99. public:
  100.  
  101. Circle() = default;
  102.  
  103. Circle(std::string name, float radius) : circleshape(sf::CircleShape(radius)) {}
  104.  
  105. void setPosition(float position_x, float position_y) {
  106.  
  107. circleshape.setPosition(position_x, position_y);
  108.  
  109. }
  110.  
  111. void setAngle(float angle) {
  112.  
  113. circleshape.setRotation(angle);
  114.  
  115. }
  116.  
  117. sf::CircleShape* getCircleShape() {
  118.  
  119. return &circleshape;
  120. }
  121.  
  122. Position getPosition() {
  123.  
  124. return Position(circleshape.getPosition().x, circleshape.getPosition().y);
  125. }
  126.  
  127. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement