Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Shape = boost::variant<Rectangle, Circle>;
- enum Shape_Type {
- RECTANGLE, CIRCLE
- };
- struct Position {
- float x, y;
- Position(float position_x, float position_y) {
- x = position_x;
- y = position_y;
- }
- };
- class Object : private Shape {
- private:
- std::string name;
- public:
- Object() = default;
- Object(std::string name, Rectangle rectangle) : name(name), Shape(rectangle) {}
- Object(std::string name, Circle circle) : name(name), Shape(circle) {}
- void setPosition(float, float);
- void setAngle(float);
- Shape* getShape() {
- Shape* shape = this;
- return shape;
- }
- Position getPosition();
- const std::string* getName() {
- return &name;
- }
- };
- class Rectangle {
- private:
- sf::RectangleShape rectangleshape;
- public:
- Rectangle() = default;
- Rectangle(float width, float height) : rectangleshape(sf::RectangleShape(sf::Vector2f(width, height))) {}
- void setPosition(float position_x, float position_y) {
- rectangleshape.setPosition(position_x, position_y);
- }
- void setAngle(float angle) {
- rectangleshape.setRotation(angle);
- }
- sf::RectangleShape* getRectangleShape() {
- return &rectangleshape;
- }
- Position getPosition() {
- return Position(rectangleshape.getPosition().x, rectangleshape.getPosition().y);
- }
- };
- class Circle {
- private:
- sf::CircleShape circleshape;
- public:
- Circle() = default;
- Circle(std::string name, float radius) : circleshape(sf::CircleShape(radius)) {}
- void setPosition(float position_x, float position_y) {
- circleshape.setPosition(position_x, position_y);
- }
- void setAngle(float angle) {
- circleshape.setRotation(angle);
- }
- sf::CircleShape* getCircleShape() {
- return &circleshape;
- }
- Position getPosition() {
- return Position(circleshape.getPosition().x, circleshape.getPosition().y);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement