feat: Ways to die on floor and collision. Added score to bird
This commit is contained in:
@@ -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();
|
||||
};
|
||||
|
||||
+8
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user