Add game over reset

cpp
Elnu 3 years ago
parent e4b894e23d
commit 386678ab21

@ -7,6 +7,7 @@
#include <SFML/System/Vector2.hpp> #include <SFML/System/Vector2.hpp>
#include <SFML/Window/Keyboard.hpp> #include <SFML/Window/Keyboard.hpp>
#include <iostream> #include <iostream>
#include <iterator>
#include <string> #include <string>
#define WINDOW_WIDTH 280 #define WINDOW_WIDTH 280
@ -303,28 +304,38 @@ int main()
// Landing (transfering block to grid and reinitializing) // Landing (transfering block to grid and reinitializing)
if (landed) { if (landed) {
for (auto tile : block.get_tiles()) { if (block.position.y == 0) {
grid[tile.y][tile.x] = block.type->tile_type; score = 0;
} text.setString("0");
// Check for completed rows for (int y = 0; y < GRID_HEIGHT; y++) {
for (int y = 0; y < GRID_HEIGHT; y++) { for (int x = 0; x < GRID_WIDTH; x++) {
bool completed = true; grid[y][x] = nullptr;
for (int x = 0; x < GRID_WIDTH; x++) {
if (!grid[y][x]) {
completed = false;
break;
} }
} }
if (!completed) { } else {
continue; for (auto tile : block.get_tiles()) {
grid[tile.y][tile.x] = block.type->tile_type;
} }
for (int z = y - 1; z >= 0; z--) { // Check for completed rows
for (int y = 0; y < GRID_HEIGHT; y++) {
bool completed = true;
for (int x = 0; x < GRID_WIDTH; x++) { for (int x = 0; x < GRID_WIDTH; x++) {
grid[z + 1][x] = grid[z][x]; if (!grid[y][x]) {
completed = false;
break;
}
}
if (!completed) {
continue;
}
for (int z = y - 1; z >= 0; z--) {
for (int x = 0; x < GRID_WIDTH; x++) {
grid[z + 1][x] = grid[z][x];
}
} }
score++;
text.setString(std::to_string(score));
} }
score++;
text.setString(std::to_string(score));
} }
block = Block(); block = Block();
} else if(is_update_frame) { } else if(is_update_frame) {

Loading…
Cancel
Save