Skip to content

Commit 30e4a89

Browse files
committed
Merge commit '9f71eda80857f81c9deadb497bd82b074ea1bc94' into dice_operations
2 parents 300ec41 + 9f71eda commit 30e4a89

File tree

5 files changed

+55
-22
lines changed

5 files changed

+55
-22
lines changed

resources/catan_sprite_sheet.bmp

825 KB
Binary file not shown.

resources/tiles.bmp

-12 MB
Binary file not shown.

resources/tiles.xcf

-3.61 MB
Binary file not shown.

src/GameView.cpp

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,42 +105,75 @@ 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();
110-
static GLuint tileTextures = loadImageAsTexture("resources/tiles.bmp");
123+
static const GLuint tileTextures = loadImageAsTexture("resources/catan_sprite_sheet.bmp");
111124
glBindTexture(GL_TEXTURE_2D, tileTextures);
112-
typedef std::vector<pair<float, float> > texCoordList;
113-
static const std::map<resourceType, texCoordList> resourceTexCoords = {
114-
make_pair(WHEAT, texCoordList { make_pair(377, 73), make_pair(500, 285),
115-
make_pair(380, 502), make_pair(136, 503), make_pair(10, 288), make_pair(134, 74)}),
116-
make_pair(SHEEP, texCoordList { make_pair(959, 75), make_pair(1076, 288),
117-
make_pair(955, 503), make_pair(712, 501), make_pair(586, 289), make_pair(708, 73)}),
118-
make_pair(WOOD, texCoordList { make_pair(1491, 60), make_pair(1618, 269),
119-
make_pair(1479, 490), make_pair(1260, 493), make_pair(1126, 283), make_pair(1246, 65)}),
120-
make_pair(STONE, texCoordList { make_pair(382, 689), make_pair(506, 898),
121-
make_pair(386, 1118), make_pair(142, 1120), make_pair(17, 905), make_pair(138, 691)}),
122-
make_pair(BRICK, texCoordList { make_pair(1496, 690), make_pair(1617, 908),
123-
make_pair(1490, 1120), make_pair(1248, 1118), make_pair(1124, 898), make_pair(1250, 688)}),
124-
make_pair(DESERT, texCoordList { make_pair(1496, 690), make_pair(1617, 908),
125-
make_pair(1490, 1120), make_pair(1248, 1118), make_pair(1124, 898), make_pair(1250, 688)}),
125+
static const std::map<resourceType, pair<float, float>> topRightPoints = {
126+
make_pair(WOOD, make_pair(260.f, 17.f)),
127+
make_pair(BRICK, make_pair(629.f, 17.f)),
128+
make_pair(STONE, make_pair(262.f, 282.f)),
129+
make_pair(SHEEP, make_pair(621.f, 286.f)),
130+
make_pair(WHEAT, make_pair(267.f, 554.f)),
131+
make_pair(DESERT, make_pair(620.f, 555.f))
126132
};
133+
static const std::vector<pair<float, float>> resourceTexOffsets = {
134+
make_pair(0.f, 0.f),
135+
make_pair(87.f, 130.f),
136+
make_pair(0.f, 261.f),
137+
make_pair(-174.f, 261.f),
138+
make_pair(-260.f, 130.f),
139+
make_pair(-175, -1)
140+
};
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;
127154
static Coordinate adjacentCoordDiffs[] = {Coordinate(0, 1), Coordinate(1, 0), Coordinate(1, -1), Coordinate(0, -1), Coordinate(-1, 0), Coordinate(-1, 1)};
128-
if(resourceTexCoords.find(tile.resource) == resourceTexCoords.end()) {
155+
auto topRightPoint = topRightPoints.find(tile.getType());
156+
if(topRightPoint == topRightPoints.end()) {
129157
throw runtime_error("Cannot draw this tile; it is invalid.");
130158
}
131-
const texCoordList& texCoords = resourceTexCoords.find(tile.resource)->second;
132159
glColor3d(1.0, 1.0, 1.0);
160+
133161
glBegin(GL_TRIANGLE_FAN);
134-
texCoordPair(averagePoint(texCoords));
162+
auto average = averagePoint(resourceTexOffsets);
163+
texCoordPair({average.first + topRightPoint->second.first, average.second + topRightPoint->second.second});
135164
vertexPair(coord);
136-
for(unsigned int i = 0; i < texCoords.size(); i++) {
137-
texCoordPair(texCoords[i]);
165+
for(unsigned int i = 0; i < resourceTexOffsets.size(); i++) {
166+
texCoordPair(std::make_pair(resourceTexOffsets[i].first + topRightPoint->second.first, resourceTexOffsets[i].second + topRightPoint->second.second));
138167
Coordinate diff = adjacentCoordDiffs[i];
139168
vertexPair(Coordinate(coord.first + diff.first, coord.second + diff.second));
140169
}
141-
texCoordPair(texCoords[0]);
170+
texCoordPair(topRightPoint->second);
142171
vertexPair(Coordinate(coord.first + adjacentCoordDiffs[0].first, coord.second + adjacentCoordDiffs[0].second));
143172
glEnd();
173+
174+
if(tile.getDiceValue() != 0) {
175+
drawTexturedCircle(numberTexPoints.find(tile.getDiceValue())->second, radius, coordToScreen(coord), 0.04);
176+
}
144177
glBindTexture(GL_TEXTURE_2D, 0);
145178
}
146179

src/Renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void vertexPair(const Coordinate& coord) {
6060
}
6161

6262
void texCoordPair(const pair<float, float>& p) {
63-
glTexCoord2f(p.first / 2048., p.second / 2048.);
63+
glTexCoord2f(p.first / 2048., p.second / 1024.);
6464
}
6565

6666
pair<float, float> averagePoint(const std::vector<pair<float, float>>& points) {

0 commit comments

Comments
 (0)