drawing pieces correctly
BIN
cpp/res/pieces/black-bishop.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
cpp/res/pieces/black-king.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
cpp/res/pieces/black-knight.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
cpp/res/pieces/black-pawn.png
Normal file
After Width: | Height: | Size: 734 B |
BIN
cpp/res/pieces/black-queen.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
cpp/res/pieces/black-rook.png
Normal file
After Width: | Height: | Size: 1014 B |
BIN
cpp/res/pieces/trimmed.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
cpp/res/pieces/white-bishop.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
cpp/res/pieces/white-king.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
cpp/res/pieces/white-knight.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
cpp/res/pieces/white-pawn.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
cpp/res/pieces/white-queen.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
cpp/res/pieces/white-rook.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
@ -1,10 +1,11 @@
|
|||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
|
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
|
||||||
GUI::GUI() {
|
GUI::GUI() {
|
||||||
window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board");
|
window.create(sf::VideoMode(WINDOW_SIZE, WINDOW_SIZE), "Chess Board");
|
||||||
// load_textures();
|
load_textures();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI::update_board(
|
void GUI::update_board(
|
||||||
@ -12,7 +13,7 @@ void GUI::update_board(
|
|||||||
) {
|
) {
|
||||||
window.clear();
|
window.clear();
|
||||||
draw_board(selected_square, legal_moves);
|
draw_board(selected_square, legal_moves);
|
||||||
// draw_pieces(b);
|
draw_pieces(b);
|
||||||
window.display();
|
window.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +32,11 @@ void GUI::handle_events() {
|
|||||||
|
|
||||||
void GUI::load_textures() {
|
void GUI::load_textures() {
|
||||||
const std::string names[6] =
|
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) {
|
for (int i = 0; i < 6; ++i) {
|
||||||
textures[i][0].loadFromFile("res/white-" + names[i] + ".png");
|
textures[i][0].loadFromFile("res/pieces/white-" + names[i] + ".png");
|
||||||
textures[i][1].loadFromFile("res/black-" + 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) {
|
for (int i = 0; i < 64; ++i) {
|
||||||
int piece = board.piece_at(i);
|
int piece = board.piece_at(i);
|
||||||
if (piece != Piece::None) {
|
if (piece != Piece::None) {
|
||||||
int color = board.colour_at(i) == Colour::White ? 0 : 1;
|
int colour = board.colour_at(i) == Colour::White ? 0 : 1;
|
||||||
pieces[i].setTexture(textures[piece - 1][color]);
|
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(
|
pieces[i].setPosition(
|
||||||
(i % 8) * TILE_SIZE,
|
(i % 8 + .5) * TILE_SIZE,
|
||||||
(7 - (int) (i / 8)) * TILE_SIZE
|
(7 - (int) (i / 8) + .5) * TILE_SIZE
|
||||||
);
|
);
|
||||||
window.draw(pieces[i]);
|
window.draw(pieces[i]);
|
||||||
}
|
}
|
||||||
|