Move snapping to event system

cpp
Elnu 3 years ago
parent 9cb6f35ec1
commit 7827f00524

@ -157,6 +157,8 @@ int main()
int shape_height = WINDOW_HEIGHT / GRID_HEIGHT; int shape_height = WINDOW_HEIGHT / GRID_HEIGHT;
sf::RectangleShape shape(sf::Vector2f(shape_width, shape_height)); sf::RectangleShape shape(sf::Vector2f(shape_width, shape_height));
bool snap;
while (window.isOpen()) while (window.isOpen())
{ {
sf::Event event; sf::Event event;
@ -165,6 +167,12 @@ int main()
switch (event.type) { switch (event.type) {
case sf::Event::Closed: case sf::Event::Closed:
window.close(); window.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Space) {
snap = true;
}
break;
default: default:
break; break;
} }
@ -219,8 +227,9 @@ int main()
snap_offset++; snap_offset++;
} }
after_snap_loop: after_snap_loop:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space)) { if (snap) {
block.position.y += snap_offset; block.position.y += snap_offset;
snap = false;
} }
// Drawing block and land checking // Drawing block and land checking

Loading…
Cancel
Save