From a31f2d0559aad97ce4de39e63b0bde94f5137282 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sat, 5 Mar 2022 13:24:44 -0800 Subject: [PATCH] Move rotation to event system --- src/Main.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 50608c6..92e274c 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -150,7 +150,7 @@ int main() int shape_height = WINDOW_HEIGHT / GRID_HEIGHT; sf::RectangleShape shape(sf::Vector2f(shape_width, shape_height)); - bool snap; + bool snap, rotate; while (window.isOpen()) { @@ -162,8 +162,15 @@ int main() window.close(); break; case sf::Event::KeyPressed: - if (event.key.code == sf::Keyboard::Space) { - snap = true; + switch (event.key.code) { + case sf::Keyboard::Space: + snap = true; + break; + case sf::Keyboard::Up: + rotate = true; + break; + default: + break; } break; default: @@ -177,7 +184,7 @@ int main() window.setFramerateLimit(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down) ? 8 : 6); // Rotation - if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) { + if (rotate) { block.rotation_state++; // Check to see if new rotation state is overlapping any tiles for (auto tile : block.get_tiles()) { @@ -186,6 +193,7 @@ int main() break; } } + rotate = false; } // Horizontal movement