Skip to content

Commit 87f6979

Browse files
committed
Added drawing tile dice values
1 parent 5b1986e commit 87f6979

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/GameView.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ void DrawingGameVisitor::visit(Player& player) {
105105

106106
}
107107

108+
void drawTexturedCircle(std::pair<float, float> texCenter, float texRadius, std::pair<float, float> screenCenter, float screenRadius, int articulation = 20) {
109+
glBegin(GL_TRIANGLE_FAN);
110+
texCoordPair(texCenter);
111+
glVertex2f(screenCenter.first, screenCenter.second);
112+
for(int i = 0; i < articulation + 1; i++) {
113+
double angle = ((double) i) * (2. * M_PI) / (double)articulation;
114+
double tangle = ((double) -i) * (2. * M_PI) / (double)articulation;
115+
texCoordPair({texCenter.first + texRadius * std::cos(tangle), texCenter.second + texRadius * std::sin(tangle)});
116+
glVertex2d(screenCenter.first + (screenRadius * std::cos(angle)), screenCenter.second + (screenRadius * std::sin(angle)));
117+
}
118+
glEnd();
119+
}
120+
108121
void DrawingGameVisitor::visit(ResourceTile& tile) {
109122
Coordinate coord = tile.getLocation();
110123
static const GLuint tileTextures = loadImageAsTexture("resources/catan_sprite_sheet.bmp");
@@ -125,12 +138,26 @@ void DrawingGameVisitor::visit(ResourceTile& tile) {
125138
make_pair(-260.f, 130.f),
126139
make_pair(-175, -1)
127140
};
141+
static const std::map<int, pair<float, float>> numberTexPoints = {
142+
make_pair(2, make_pair(1238.5f, 70.5f)),
143+
make_pair(3, make_pair(1365.5f, 70.5f)),
144+
make_pair(4, make_pair(1238.5f, 178.5f)),
145+
make_pair(5, make_pair(1365.5f, 178.5f)),
146+
make_pair(6, make_pair(1238.5f, 286.5f)),
147+
make_pair(8, make_pair(1365.5f, 286.5f)),
148+
make_pair(9, make_pair(1238.5f, 404.5f)),
149+
make_pair(10, make_pair(1365.5f, 404.5f)),
150+
make_pair(11, make_pair(1238.5f, 515.5f)),
151+
make_pair(12, make_pair(1365.5f, 515.5f))
152+
};
153+
static const float radius = 59.5f;
128154
static Coordinate adjacentCoordDiffs[] = {Coordinate(0, 1), Coordinate(1, 0), Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0), Coordinate(-1, 1)};
129155
auto topRightPoint = topRightPoints.find(tile.getType());
130156
if(topRightPoint == topRightPoints.end()) {
131157
throw runtime_error("Cannot draw this tile; it is invalid.");
132158
}
133159
glColor3d(1.0, 1.0, 1.0);
160+
134161
glBegin(GL_TRIANGLE_FAN);
135162
auto average = averagePoint(resourceTexOffsets);
136163
texCoordPair({average.first + topRightPoint->second.first, average.second + topRightPoint->second.second});
@@ -143,6 +170,10 @@ void DrawingGameVisitor::visit(ResourceTile& tile) {
143170
texCoordPair(topRightPoint->second);
144171
vertexPair(Coordinate(coord.first + adjacentCoordDiffs[0].first, coord.second + adjacentCoordDiffs[0].second));
145172
glEnd();
173+
174+
if(tile.getDiceValue() != 0) {
175+
drawTexturedCircle(numberTexPoints.find(tile.getDiceValue())->second, radius, coordToScreen(coord), 0.04);
176+
}
146177
glBindTexture(GL_TEXTURE_2D, 0);
147178
}
148179

0 commit comments

Comments
 (0)