Remove broken conditional drawing code

cpp
Elnu 2 years ago
parent 9ddc9caf4a
commit e663e8c061

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

Loading…
Cancel
Save