Skip to content

Commit 5b1986e

Browse files
committed
Changed tile drawing to use new images
1 parent 7e2a8da commit 5b1986e

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-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: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,40 @@ void DrawingGameVisitor::visit(Player& player) {
107107

108108
void DrawingGameVisitor::visit(ResourceTile& tile) {
109109
Coordinate coord = tile.getLocation();
110-
static GLuint tileTextures = loadImageAsTexture("resources/tiles.bmp");
110+
static const GLuint tileTextures = loadImageAsTexture("resources/catan_sprite_sheet.bmp");
111111
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)}),
112+
static const std::map<resourceType, pair<float, float>> topRightPoints = {
113+
make_pair(WOOD, make_pair(260.f, 17.f)),
114+
make_pair(BRICK, make_pair(629.f, 17.f)),
115+
make_pair(STONE, make_pair(262.f, 282.f)),
116+
make_pair(SHEEP, make_pair(621.f, 286.f)),
117+
make_pair(WHEAT, make_pair(267.f, 554.f)),
118+
make_pair(DESERT, make_pair(620.f, 555.f))
119+
};
120+
static const std::vector<pair<float, float>> resourceTexOffsets = {
121+
make_pair(0.f, 0.f),
122+
make_pair(87.f, 130.f),
123+
make_pair(0.f, 261.f),
124+
make_pair(-174.f, 261.f),
125+
make_pair(-260.f, 130.f),
126+
make_pair(-175, -1)
126127
};
127128
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()) {
129+
auto topRightPoint = topRightPoints.find(tile.getType());
130+
if(topRightPoint == topRightPoints.end()) {
129131
throw runtime_error("Cannot draw this tile; it is invalid.");
130132
}
131-
const texCoordList& texCoords = resourceTexCoords.find(tile.resource)->second;
132133
glColor3d(1.0, 1.0, 1.0);
133134
glBegin(GL_TRIANGLE_FAN);
134-
texCoordPair(averagePoint(texCoords));
135+
auto average = averagePoint(resourceTexOffsets);
136+
texCoordPair({average.first + topRightPoint->second.first, average.second + topRightPoint->second.second});
135137
vertexPair(coord);
136-
for(unsigned int i = 0; i < texCoords.size(); i++) {
137-
texCoordPair(texCoords[i]);
138+
for(unsigned int i = 0; i < resourceTexOffsets.size(); i++) {
139+
texCoordPair(std::make_pair(resourceTexOffsets[i].first + topRightPoint->second.first, resourceTexOffsets[i].second + topRightPoint->second.second));
138140
Coordinate diff = adjacentCoordDiffs[i];
139141
vertexPair(Coordinate(coord.first + diff.first, coord.second + diff.second));
140142
}
141-
texCoordPair(texCoords[0]);
143+
texCoordPair(topRightPoint->second);
142144
vertexPair(Coordinate(coord.first + adjacentCoordDiffs[0].first, coord.second + adjacentCoordDiffs[0].second));
143145
glEnd();
144146
glBindTexture(GL_TEXTURE_2D, 0);

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)