starting refactoring

This commit is contained in:
DarthMooMancer
2025-11-18 23:53:53 -05:00
parent a955f2d067
commit 46a975f90e
2 changed files with 20 additions and 35 deletions
+9 -24
View File
@@ -12,13 +12,6 @@ Paddle create_new_paddle(vec2** buffer, int starting_array_index, int size, int
return paddle;
}
Ball create_new_ball(vec2** buffer, int buffer_index, int default_vx, int default_vy, int row, int col, char symbol) {
Ball ball { default_vx, default_vy };
ball.m_origin = new vec2 { row, col, symbol };
buffer[buffer_index] = ball.m_origin;
return ball;
}
Block** create_block_buffer(int starting_symbol, int rows, int cols, int length) {
Block** block_buffer = new Block*[rows * cols];
int row, int_symbol, col;
@@ -115,18 +108,11 @@ void Paddle::check_collision(Ball &ball) {
}
}
Ball::~Ball() {
delete m_origin;
m_origin = nullptr;
}
void Ball::change_velocity(char d) {
if(d == 'x') {
if(vx == -1) vx = 1;
else if (vx == 1) vx = -1;
vel.x *= -1;
} else if(d == 'y') {
if(vy == -1) vy = 1;
else if (vy == 1) vy = -1;
vel.y *= -1;
}
}
@@ -159,18 +145,17 @@ Block::~Block() {
}
}
Block::Block(int size, int row, int col, char symbol) {
_size = size;
m_nodes = new vec2*[size];
for(int i = 0; i < size; i++) {
m_nodes[i] = new vec2 { row, col + i, symbol };
Block::Block(vec2 pos, char symbol) {
for(int i = 0; i < m_nodes.size(); i++) {
m_nodes[i].set(pos.x + i, pos.y);
m_nodes[i].m_symbol = symbol;
}
}
bool Block::check_collision(Ball &ball) {
for(int i = 0; i < _size; i++) {
if(m_nodes[i]->x != ball.m_origin->x) continue;
if(m_nodes[i]->y != ball.m_origin->y) continue;
for(int i = 0; i < m_nodes.size(); i++) {
if(m_nodes[i] != ball.m_origin) continue;
if(m_nodes[i] != ball.m_origin) continue;
return true;
}
return false;