From 100907bd56b18c50aab9efb10700956b8c164c05 Mon Sep 17 00:00:00 2001 From: Stephen Enders Date: Wed, 27 Jan 2021 20:45:23 -0500 Subject: 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. --- src/ur.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ur.cpp') 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> textures = loadTextures(TEXTURE_PATH); - const std::shared_ptr> board = createBoard(textures); + const std::shared_ptr> board = + createBoard(textures); const std::shared_ptr 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)); -- cgit v1.2.3-54-g00ecf