feat: Ways to die on floor and collision. Added score to bird

This commit is contained in:
DarthMooMancer
2025-09-04 19:54:29 -04:00
parent a7b1ebb9c5
commit dba8c6e126
2 changed files with 10 additions and 2 deletions
+2 -1
View File
@@ -13,9 +13,10 @@ struct Point {
}; };
struct Bird { struct Bird {
Bird() : m_fly(false) {}; Bird() : m_fly(false), m_score(0) {};
Point m_body { (ROW/2), 4, '*' }; Point m_body { (ROW/2), 4, '*' };
bool m_fly; bool m_fly;
int m_score;
void move(); void move();
void check_collision(); void check_collision();
}; };
+8 -1
View File
@@ -31,17 +31,24 @@ int main() {
if(pipes.front().m_nodes->m_col < 3) { if(pipes.front().m_nodes->m_col < 3) {
pipes.erase(pipes.begin()); pipes.erase(pipes.begin());
} }
if(bird.m_body.m_row >= ROW - 1) {
running = false;
std::cout << "You died! Your score is: " << bird.m_score << std::endl;
}
for(int j = 0; j < pipes.size(); j++) { for(int j = 0; j < pipes.size(); j++) {
for(int i = 0; i < pipes.front().m_size; i++) { for(int i = 0; i < pipes.front().m_size; i++) {
if(pipes.at(j).m_nodes[i].m_col != bird.m_body.m_col) continue; if(pipes.at(j).m_nodes[i].m_col != bird.m_body.m_col) continue;
if(pipes.at(j).m_nodes[i].m_row != bird.m_body.m_row) continue; if(pipes.at(j).m_nodes[i].m_row != bird.m_body.m_row) continue;
if(pipes.at(j).m_nodes[i].m_symbol == ' ') continue; if(pipes.at(j).m_nodes[i].m_symbol == ' ') continue;
running = false; running = false;
std::cout << "You died!" << std::endl; std::cout << "You died! Your score is: " << bird.m_score << std::endl;
} }
} }
window.update_display(bird, pipes); window.update_display(bird, pipes);
frames++; frames++;
if(pipes.front().m_nodes->m_col == bird.m_body.m_col) {
bird.m_score++;
}
if(frames > 4) { if(frames > 4) {
pipes.push_back(Pipe()); pipes.push_back(Pipe());
frames = 0; frames = 0;