diff --git a/cpp/res/pieces/black-bishop.png b/cpp/res/pieces/black-bishop.png new file mode 100644 index 0000000..c00730d Binary files /dev/null and b/cpp/res/pieces/black-bishop.png differ diff --git a/cpp/res/pieces/black-king.png b/cpp/res/pieces/black-king.png new file mode 100644 index 0000000..c3928dd Binary files /dev/null and b/cpp/res/pieces/black-king.png differ diff --git a/cpp/res/pieces/black-knight.png b/cpp/res/pieces/black-knight.png new file mode 100644 index 0000000..9f806a0 Binary files /dev/null and b/cpp/res/pieces/black-knight.png differ diff --git a/cpp/res/pieces/black-pawn.png b/cpp/res/pieces/black-pawn.png new file mode 100644 index 0000000..a2e480b Binary files /dev/null and b/cpp/res/pieces/black-pawn.png differ diff --git a/cpp/res/pieces/black-queen.png b/cpp/res/pieces/black-queen.png new file mode 100644 index 0000000..0a02a4d Binary files /dev/null and b/cpp/res/pieces/black-queen.png differ diff --git a/cpp/res/pieces/black-rook.png b/cpp/res/pieces/black-rook.png new file mode 100644 index 0000000..0128fae Binary files /dev/null and b/cpp/res/pieces/black-rook.png differ diff --git a/cpp/res/pieces/trimmed.png b/cpp/res/pieces/trimmed.png new file mode 100644 index 0000000..fe657c4 Binary files /dev/null and b/cpp/res/pieces/trimmed.png differ diff --git a/cpp/res/pieces/white-bishop.png b/cpp/res/pieces/white-bishop.png new file mode 100644 index 0000000..2db222c Binary files /dev/null and b/cpp/res/pieces/white-bishop.png differ diff --git a/cpp/res/pieces/white-king.png b/cpp/res/pieces/white-king.png new file mode 100644 index 0000000..dfe57d8 Binary files /dev/null and b/cpp/res/pieces/white-king.png differ diff --git a/cpp/res/pieces/white-knight.png b/cpp/res/pieces/white-knight.png new file mode 100644 index 0000000..bc515e6 Binary files /dev/null and b/cpp/res/pieces/white-knight.png differ diff --git a/cpp/res/pieces/white-pawn.png b/cpp/res/pieces/white-pawn.png new file mode 100644 index 0000000..36d4b80 Binary files /dev/null and b/cpp/res/pieces/white-pawn.png differ diff --git a/cpp/res/pieces/white-queen.png b/cpp/res/pieces/white-queen.png new file mode 100644 index 0000000..4084290 Binary files /dev/null and b/cpp/res/pieces/white-queen.png differ diff --git a/cpp/res/pieces/white-rook.png b/cpp/res/pieces/white-rook.png new file mode 100644 index 0000000..6564d81 Binary files /dev/null and b/cpp/res/pieces/white-rook.png differ diff --git a/cpp/src/view/gui.cpp b/cpp/src/view/gui.cpp index 37d6e5c..595a617 100644 --- a/cpp/src/view/gui.cpp +++ b/cpp/src/view/gui.cpp @@ -1,10 +1,11 @@ #include "gui.hpp" #include +#include GUI::GUI() { window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board"); - // load_textures(); + load_textures(); } void GUI::update_board( @@ -12,7 +13,7 @@ void GUI::update_board( ) { window.clear(); draw_board(selected_square, legal_moves); - // draw_pieces(b); + draw_pieces(b); window.display(); } @@ -31,10 +32,11 @@ void GUI::handle_events() { void GUI::load_textures() { const std::string names[6] = - {"pawn", "rook", "knight", "bishop", "queen", "king"}; + {"rook", "knight", "bishop", "queen", "king", "pawn" + }; // don't touch the order, it's reflecting the one in the Piece enum for (int i = 0; i < 6; ++i) { - textures[i][0].loadFromFile("res/white-" + names[i] + ".png"); - textures[i][1].loadFromFile("res/black-" + names[i] + ".png"); + textures[i][0].loadFromFile("res/pieces/white-" + names[i] + ".png"); + textures[i][1].loadFromFile("res/pieces/black-" + names[i] + ".png"); } } @@ -74,11 +76,15 @@ void GUI::draw_pieces(const Board& board) { for (int i = 0; i < 64; ++i) { int piece = board.piece_at(i); if (piece != Piece::None) { - int color = board.colour_at(i) == Colour::White ? 0 : 1; - pieces[i].setTexture(textures[piece - 1][color]); + int colour = board.colour_at(i) == Colour::White ? 0 : 1; + pieces[i].setTexture(textures[piece - 1][colour]); + + sf::Vector2 center = textures[piece - 1][colour].getSize() / 2u; + pieces[i].setOrigin(center.x, center.y); + pieces[i].setPosition( - (i % 8) * TILE_SIZE, - (7 - (int) (i / 8)) * TILE_SIZE + (i % 8 + .5) * TILE_SIZE, + (7 - (int) (i / 8) + .5) * TILE_SIZE ); window.draw(pieces[i]); }