C++ 使用SFML为卡坦创建电路板

C++ 使用SFML为卡坦创建电路板,c++,sfml,C++,Sfml,我想用SFML为卡坦游戏创建一个棋盘,我只需要19个形状(六边形),每个形状我都可以在6个角和6个边上创建城市或道路。 对于我制作的形状: std::vector<sf::CircleShape> shape(19); int n = 0; int shape_y = 100; for (size_t index = 0; index < shape.size(); index++) { if (index < 3) { sf::CircleSha

我想用SFML为卡坦游戏创建一个棋盘,我只需要19个形状(六边形),每个形状我都可以在6个角和6个边上创建城市或道路。 对于我制作的形状:

std::vector<sf::CircleShape> shape(19);
int n = 0;
int shape_y = 100;
for (size_t index = 0; index < shape.size(); index++) {
    if (index < 3) {
        sf::CircleShape sh(80, 6);
        sh.setPosition(200 + n, shape_y);
        sh.setFillColor(sf::Color::Magenta);
        shape[index] = sh;
        n += 140;
    }
    if (index == 3)
        n = 0;
    if (index < 7 && index >= 3) {
        sf::CircleShape sh(80, 6);
        sh.setPosition(130 + n, shape_y + 120);
        sh.setFillColor(sf::Color::Blue);
        shape[index] = sh;
        n += 140;
    }
    if (index == 7)
        n = 0;
    if (index >= 7 && index < 12) {
        sf::CircleShape sh(80, 6);
        sh.setPosition(60 + n, shape_y + 240);
        sh.setFillColor(sf::Color::Red);
        shape[index] = sh;
        n += 140;
    }
    if (index == 12)
        n = 0;
    if (index >= 12 && index < 16) {
        sf::CircleShape sh(80, 6);
        sh.setPosition(130 + n, shape_y + 360);
        sh.setFillColor(sf::Color::Green);
        shape[index] = sh;
        n += 140;
    }
    if (index == 16)
        n = 0;
    if (index >= 16 && index < 19) {
        sf::CircleShape sh(80, 6);
        sh.setPosition(200 + n, shape_y + 480);
        sh.setFillColor(sf::Color::Yellow);
        shape[index] = sh;
        n += 140;
    }
}
std::向量形状(19);
int n=0;
int shape_y=100;
对于(size_t index=0;index=3){
sf::圆形sh(80,6);
sh.设定位置(130+n,形状y+120);
sh.setFillColor(sf::Color::Blue);
形状[指数]=sh;
n+=140;
}
如果(索引==7)
n=0;
如果(索引>=7&&index<12){
sf::圆形sh(80,6);
sh.设置位置(60+n,形状y+240);
sh.setFillColor(sf::Color::红色);
形状[指数]=sh;
n+=140;
}
如果(索引==12)
n=0;
如果(索引>=12&&index<16){
sf::圆形sh(80,6);
sh.设置位置(130+n,形状y+360);
sh.setFillColor(sf::Color::Green);
形状[指数]=sh;
n+=140;
}
如果(索引==16)
n=0;
如果(索引>=16&&index<19){
sf::圆形sh(80,6);
sh.设置位置(200+n,形状y+480);
sh.setFillColor(sf::Color::黄色);
形状[指数]=sh;
n+=140;
}
}
这看起来像这样:

但是我是如何从形状中得到角和边的呢?如果我使用getPoint(0)作为角点,则它不会绘制其所属的点。
如果这不是一个好主意,我可以用什么来解决这个问题呢?

我很久以前就采用了这种机制,这是一种实现这一点的简单方法

我的方法是将每个六边形表示为一个圆。画出的六边形嵌在那个圆圈里。为了检查鼠标是否位于角落或侧面,我做了一个简单的检查:

  • 如果该点同时位于3个圆内,则为一个角(这3个六边形的相交角)

  • 如果点在两个圆内,则为边

  • 如果点在一个圆内,它就是一个完整的六边形

概念证明:

蓝色六边形符合正确的电路板,每个都有一个红色圆圈(略大于六边形)

绿色六边形不在棋盘上(它们不是游戏棋盘的一部分),它们有助于了解鼠标是否位于外侧六边形的边或角上


完整的代码已经存在,但是已经很旧了,可能已经过时了

,因为
getPoint
返回了一个请求点,我不知道“如何从形状中获取角和边”是一个问题。您是否尝试过使用
sf::CircleShape::SetOutlineHickness()
?这样可以修改轮廓相对于边的偏移/位置。现在无法检查,但我很确定你也可以设置一个负宽度,使其向内。重读你的问题,我可能误解了你。你能不能用一个简单的绘图程序来画你想要的东西,这样我们就可以把它和你得到的东西进行比较?@VTT是的,getPoint做这个,但我想把那个点精确地画在它所在的地方,但它不能做到这一点。如果我这样做:sf::Vector2f pixel=sh.getPoint(0);设置位置(像素x,像素y);