fix: blocks have proper collision and can be broken. Basically done.

This commit is contained in:
DarthMooMancer
2025-09-01 05:35:54 -04:00
parent 702be0363f
commit f1e32089ae
6 changed files with 56 additions and 22 deletions
+25 -15
View File
@@ -10,13 +10,14 @@ int main() {
Paddle paddle;
Ball ball;
Block block_list[15] = {
Block('3', 0, 0), Block('3', 0, 3), Block('3', 0, 6), Block('3', 0, 9), Block('3', 0, 12),
Block('2', 1, 0), Block('2', 1, 3), Block('2', 1, 6), Block('2', 1, 9), Block('2', 1, 12),
Block('1', 2, 0), Block('1', 2, 3), Block('1', 2, 6), Block('1', 2, 9), Block('1', 2, 12),
Block('3', 1, 0), Block('3', 1, 3), Block('3', 1, 6), Block('3', 1, 9), Block('3', 1, 12),
Block('2', 2, 0), Block('2', 2, 3), Block('2', 2, 6), Block('2', 2, 9), Block('2', 2, 12),
Block('1', 3, 0), Block('1', 3, 3), Block('1', 3, 6), Block('1', 3, 9), Block('1', 3, 12),
};
bool running = true;
int lives = 3;
int blocks_left = 15;
std::thread input_thread(&Input::get_input, &input, std::ref(running), std::ref(paddle));
while (running) {
@@ -24,23 +25,32 @@ int main() {
paddle.get_new_pos();
ball.check_collision(lives);
for(int i = 0; i < 15; i++) {
if(block_list[i]._deleted) {
continue;
}
block_list[i].get_pos();
block_list[i].check_collision(ball, blocks_left);
}
if(ball.m_origin.m_row >= ROW -1) {
lives--;
ball.m_origin.assign(ROW - 7, (COL / 2));
ball.change_velocity('y');
window.update_display(paddle, ball, block_list);
window.tick(500);
}
// if(ball.m_origin.m_row >= ROW -1) {
// lives--;
// ball.m_origin.assign(ROW - 5, (COL / 2));
// ball.vy = 1;
// window.update_display(paddle, ball, block_list);
// window.tick(500);
// }
paddle.check_collision(ball);
ball.get_new_pos();
// std::cout << "Lives left: " << lives << std::endl;
// if(lives <= 0) {
// std::cout << "You lose!" << std::endl;
// running = false;
// }
std::cout << "Lives left: " << lives << std::endl;
if(lives <= 0) {
window.clear();
std::cout << "You lose!" << std::endl;
running = false;
} if(blocks_left <= 0) {
window.clear();
std::cout << "You win!" << std::endl;
running = false;
}
}
input_thread.join();
return 0;