diff options
author | Stephen Enders <smenders@gmail.com> | 2021-01-27 20:45:23 -0500 |
---|---|---|
committer | Stephen Enders <smenders@gmail.com> | 2021-01-27 20:45:23 -0500 |
commit | 100907bd56b18c50aab9efb10700956b8c164c05 (patch) | |
tree | deb1ffffc9b90aa6b993978f83faa91b7fa2ca0d /src/ur.cpp | |
parent | a408a43cd105b89a8d44292e2ef69802a5660497 (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.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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)); |