Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Constants.hpp"
- struct Node {
- public:
- Node(Constants::NodeType nodeType_) {
- nodeType = nodeType_;
- }
- void setCoordonates(sf::Vector2f coord) {
- m_coord = coord;
- }
- sf::Vector2f getCoordonates() {
- return m_coord;
- }
- sf::ConvexShape getShape() {
- if(m_coord == sf::Vector2f{-1, -1}) {
- throw std::invalid_argument("You did not set the coordinates for this shape");
- }
- if(!m_shapeAssigned) {
- m_shapeAssigned = true;
- m_shape = setShape();
- }
- return m_shape;
- }
- public:
- Constants::NodeType nodeType;
- int height;
- int width;
- sf::RectangleShape hitbox;
- private:
- sf::ConvexShape setShape() {
- hitbox = sf::RectangleShape(sf::Vector2f{100, 30});
- hitbox.setPosition(m_coord - sf::Vector2f{50, 15});
- hitbox.setFillColor(sf::Color::Transparent);
- hitbox.setOutlineColor(sf::Color::Green);
- hitbox.setOutlineThickness(2);
- switch(nodeType) {
- case Constants::StartNode:
- return startNodeShape();
- case Constants::AssignNode:
- return assignNodeShape();
- case Constants::ConditionalNode:
- return conditionalNodeShape();
- case Constants::StopNode:
- return stopNodeShape();
- default:
- return sf::ConvexShape(0);
- }
- }
- sf::ConvexShape startNodeShape() {
- width = 100;
- height = 30;
- sf::ConvexShape convexShape;
- convexShape.setPointCount(4);
- convexShape.setPoint(0, m_coord + sf::Vector2f{-width/2, -height/2});
- convexShape.setPoint(1, m_coord + sf::Vector2f{ width/2, -height/2});
- convexShape.setPoint(2, m_coord + sf::Vector2f{ width/2, height/2});
- convexShape.setPoint(3, m_coord + sf::Vector2f{-width/2, height/2});
- return convexShape;
- }
- sf::ConvexShape assignNodeShape() {
- width = 100;
- height = 30;
- sf::ConvexShape convexShape;
- convexShape.setPointCount(4);
- convexShape.setPoint(0, m_coord + sf::Vector2f{-width/2, -height/2});
- convexShape.setPoint(1, m_coord + sf::Vector2f{ width/2, -height/2});
- convexShape.setPoint(2, m_coord + sf::Vector2f{ width/2-20, height/2});
- convexShape.setPoint(3, m_coord + sf::Vector2f{-width/2+20, height/2});
- return convexShape;
- }
- sf::ConvexShape conditionalNodeShape() {
- width = 100;
- height = 30;
- sf::ConvexShape convexShape;
- convexShape.setPointCount(4);
- convexShape.setPoint(0, m_coord + sf::Vector2f{-width/2+20, -height/2});
- convexShape.setPoint(1, m_coord + sf::Vector2f{ width/2-20, -height/2});
- convexShape.setPoint(2, m_coord + sf::Vector2f{ width/2, height/2});
- convexShape.setPoint(3, m_coord + sf::Vector2f{-width/2, height/2});
- return convexShape;
- }
- sf::ConvexShape stopNodeShape() {
- width = 100;
- height = 30;
- sf::ConvexShape convexShape;
- convexShape.setPointCount(4);
- convexShape.setPoint(0, m_coord + sf::Vector2f{-width/2, -height/2});
- convexShape.setPoint(1, m_coord + sf::Vector2f{ width/2, -height/2});
- convexShape.setPoint(2, m_coord + sf::Vector2f{ width/2, height/2});
- convexShape.setPoint(3, m_coord + sf::Vector2f{-width/2, height/2});
- return convexShape;
- }
- private:
- sf::Vector2f m_coord = sf::Vector2f{-1, -1};
- sf::ConvexShape m_shape;
- bool m_shapeAssigned = false;
- };
Advertisement
Add Comment
Please, Sign In to add comment