Remove broken conditional drawing code

cpp
Elnu 3 years ago
parent 9ddc9caf4a
commit e663e8c061

@ -157,7 +157,6 @@ int main()
sf::RectangleShape shape(sf::Vector2f(shape_width, shape_height)); sf::RectangleShape shape(sf::Vector2f(shape_width, shape_height));
bool snap, rotate, move_left, move_right; bool snap, rotate, move_left, move_right;
bool redraw = true;
sf::Clock update_clock; sf::Clock update_clock;
sf::Clock move_clock; sf::Clock move_clock;
@ -224,7 +223,6 @@ int main()
for (auto tile : block.get_tiles()) { for (auto tile : block.get_tiles()) {
if (tile.x <= 0 || tile.x >= GRID_WIDTH || grid[tile.y][tile.x]) { if (tile.x <= 0 || tile.x >= GRID_WIDTH || grid[tile.y][tile.x]) {
block.rotation_state--; block.rotation_state--;
redraw = true;
break; break;
} }
} }
@ -242,21 +240,16 @@ int main()
movement++; movement++;
move_right = false; move_right = false;
} }
bool obstructed = false;
if (movement != 0) { if (movement != 0) {
for (auto tile : block.get_tiles()) { for (auto tile : block.get_tiles()) {
if (tile.x + movement < 0 || tile.x + movement >= GRID_WIDTH || grid[tile.y][tile.x + movement]) { if (tile.x + movement < 0 || tile.x + movement >= GRID_WIDTH || grid[tile.y][tile.x + movement]) {
obstructed = true;
goto after_movement_loop; goto after_movement_loop;
} }
} }
}
after_movement_loop:
if (!obstructed) {
block.position.x += movement; block.position.x += movement;
redraw = true;
} }
} }
after_movement_loop:
// Snapping // Snapping
int snap_offset = 0; int snap_offset = 0;
@ -273,20 +266,18 @@ int main()
if (snap) { if (snap) {
block.position.y += snap_offset; block.position.y += snap_offset;
snap = false; snap = false;
redraw = true;
} }
// Drawing block and land checking // Land checking
bool landed = false; bool landed = false;
for (auto tile : block.get_tiles()) { for (auto tile : block.get_tiles()) {
if (tile.y == GRID_HEIGHT - 1 || grid[tile.y + 1][tile.x] != nullptr) { if (tile.y == GRID_HEIGHT - 1 || grid[tile.y + 1][tile.x] != nullptr) {
landed = true; landed = true;
redraw = true;
break; break;
} }
} }
if (redraw) { // Draw block
window.clear(); window.clear();
if (!landed) { if (!landed) {
sf::Color ghost_color = block.type->tile_type->color; sf::Color ghost_color = block.type->tile_type->color;
@ -301,8 +292,6 @@ int main()
window.draw(shape); window.draw(shape);
} }
} }
}
// Landing (transfering block to grid and reinitializing) // Landing (transfering block to grid and reinitializing)
if (landed) { if (landed) {
@ -346,10 +335,6 @@ int main()
block.position.y++; block.position.y++;
} }
if (!redraw) {
continue;
}
// Drawing grid // Drawing grid
for (int y = 0; y < GRID_HEIGHT; y++) { for (int y = 0; y < GRID_HEIGHT; y++) {
for (int x = 0; x < GRID_WIDTH; x++) { for (int x = 0; x < GRID_WIDTH; x++) {
@ -366,8 +351,6 @@ int main()
window.draw(text); window.draw(text);
window.display(); window.display();
redraw = false;
} }
return 0; return 0;

Loading…
Cancel
Save