From 20222ad6866475e027fbc4e5458d70eeb1ebd13e Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 5 Mar 2022 12:31:43 -0800 Subject: [PATCH] Add collision detection for rotation --- src/Main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Main.cpp b/src/Main.cpp index 095a532..71c99e7 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -175,6 +175,13 @@ int main() // Rotation if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) { block.rotation_state++; + // Check to see if new rotation state is overlapping any tiles + for (auto tile : block.get_tiles()) { + if (tile.x <= 0 || tile.x >= GRID_WIDTH || grid[tile.y][tile.x]) { + block.rotation_state--; + break; + } + } } // Horizontal movement