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,6 +304,15 @@ int main()
// Landing (transfering block to grid and reinitializing) // Landing (transfering block to grid and reinitializing)
if (landed) { if (landed) {
if (block.position.y == 0) {
score = 0;
text.setString("0");
for (int y = 0; y < GRID_HEIGHT; y++) {
for (int x = 0; x < GRID_WIDTH; x++) {
grid[y][x] = nullptr;
}
}
} else {
for (auto tile : block.get_tiles()) { for (auto tile : block.get_tiles()) {
grid[tile.y][tile.x] = block.type->tile_type; grid[tile.y][tile.x] = block.type->tile_type;
} }
@ -326,6 +336,7 @@ int main()
score++; score++;
text.setString(std::to_string(score)); text.setString(std::to_string(score));
} }
}
block = Block(); block = Block();
} else if(is_update_frame) { } else if(is_update_frame) {
block.position.y++; block.position.y++;

Loading…
Cancel
Save