From dba8c6e1263152ce48af3c486359c3ad02ef9bbb Mon Sep 17 00:00:00 2001 From: DarthMooMancer Date: Thu, 4 Sep 2025 19:54:29 -0400 Subject: [PATCH] feat: Ways to die on floor and collision. Added score to bird --- include/elements.hpp | 3 ++- src/main.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/elements.hpp b/include/elements.hpp index aac857f..cb4e4ce 100644 --- a/include/elements.hpp +++ b/include/elements.hpp @@ -13,9 +13,10 @@ struct Point { }; struct Bird { - Bird() : m_fly(false) {}; + Bird() : m_fly(false), m_score(0) {}; Point m_body { (ROW/2), 4, '*' }; bool m_fly; + int m_score; void move(); void check_collision(); }; diff --git a/src/main.cpp b/src/main.cpp index 206e829..63b7e8a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,17 +31,24 @@ int main() { if(pipes.front().m_nodes->m_col < 3) { 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 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_row != bird.m_body.m_row) continue; if(pipes.at(j).m_nodes[i].m_symbol == ' ') continue; 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); frames++; + if(pipes.front().m_nodes->m_col == bird.m_body.m_col) { + bird.m_score++; + } if(frames > 4) { pipes.push_back(Pipe()); frames = 0;