summaryrefslogtreecommitdiff
path: root/src/ur.cpp
diff options
context:
space:
mode:
authorStephen Enders <smenders@gmail.com>2021-01-27 20:45:23 -0500
committerStephen Enders <smenders@gmail.com>2021-01-27 20:45:23 -0500
commit100907bd56b18c50aab9efb10700956b8c164c05 (patch)
treedeb1ffffc9b90aa6b993978f83faa91b7fa2ca0d /src/ur.cpp
parenta408a43cd105b89a8d44292e2ef69802a5660497 (diff)
Move board to use piece_t
Since we need to know what "position" a piece is placed in reuse the piece struct to track the board placement.
Diffstat (limited to 'src/ur.cpp')
-rw-r--r--src/ur.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/ur.cpp b/src/ur.cpp
index dc61eb3..6bd27f4 100644
--- a/src/ur.cpp
+++ b/src/ur.cpp
@@ -160,7 +160,8 @@ main()
const std::shared_ptr<std::vector<sf::Texture>> textures =
loadTextures(TEXTURE_PATH);
- const std::shared_ptr<std::vector<sf::Sprite>> board = createBoard(textures);
+ const std::shared_ptr<std::vector<struct piece_t>> board =
+ createBoard(textures);
const std::shared_ptr<struct player_t> p1 =
createPlayer((*textures)[P1_PIECE]);
@@ -266,11 +267,13 @@ main()
// did the piece drop into place
bool in_place = false;
sf::FloatRect intersect;
- for (auto& s : *(board)) {
+ for (auto& bp : (*board)) {
+ auto s = bp.sprite;
if (s.getGlobalBounds().intersects(
grabbed_piece->sprite.getGlobalBounds(), intersect)) {
if (intersect.width > SPRITE_SIZE / 2 &&
intersect.height > SPRITE_SIZE / 2) {
+ // check valid placement
grabbed_piece->sprite.setPosition(s.getPosition());
in_place = true;
break;
@@ -296,7 +299,7 @@ main()
window.setView(view);
for (auto s : *(board)) {
- window.draw(s);
+ window.draw(s.sprite);
}
auto mPos = window.mapPixelToCoords(sf::Mouse::getPosition(window));