fix: blocks have proper collision and can be broken. Basically done.
This commit is contained in:
+21
-2
@@ -20,7 +20,7 @@ Paddle::Paddle() {
|
||||
_size = 3;
|
||||
m_nodes[0].m_col = 6;
|
||||
for(int i = 0; i < _size; i++) {
|
||||
m_nodes[i].m_row = 8;
|
||||
m_nodes[i].m_row = ROW - 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void Ball::change_velocity(char d) {
|
||||
}
|
||||
|
||||
void Ball::check_collision(int &lives) {
|
||||
if(m_origin.m_row <= 0 || m_origin.m_row >= ROW -1) {
|
||||
if(m_origin.m_row <= 0) {
|
||||
change_velocity('y');
|
||||
} if(m_origin.m_col <= 0 || m_origin.m_col >= COL -1) {
|
||||
change_velocity('x');
|
||||
@@ -78,6 +78,7 @@ void Ball::get_new_pos() {
|
||||
|
||||
Block::Block(char symbol, int row, int col) {
|
||||
_size = 3;
|
||||
_deleted = false;
|
||||
m_symbol = symbol;
|
||||
m_nodes[0].m_col = col;
|
||||
for(int i = 0; i < _size; i++) {
|
||||
@@ -90,3 +91,21 @@ void Block::get_pos() {
|
||||
m_nodes[i].m_col = m_nodes[0].m_col + i;
|
||||
}
|
||||
}
|
||||
|
||||
void Block::_delete() {
|
||||
for(int i = 0; i < _size; i++) {
|
||||
m_nodes[i].assign(ROW - 1, COL - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Block::check_collision(Ball &ball, int &blocks_left) {
|
||||
for(int i = 0; i < _size; i++) {
|
||||
if(m_nodes[i].m_col == ball.m_origin.m_col) {
|
||||
if(m_nodes[i].m_row == ball.m_origin.m_row) {
|
||||
ball.change_velocity('y');
|
||||
_delete();
|
||||
blocks_left--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user