wip
This commit is contained in:
@@ -8,7 +8,8 @@ struct Paddle;
|
|||||||
struct Block;
|
struct Block;
|
||||||
struct Ball;
|
struct Ball;
|
||||||
Paddle create_new_paddle(Point** buffer, int starting_array_index, int size, int row, char symbol);
|
Paddle create_new_paddle(Point** buffer, int starting_array_index, int size, int row, char symbol);
|
||||||
Block create_new_block(Point** buffer, char symbol, int row, int col, int length);
|
Block create_new_block(char symbol, int row, int col, int size);
|
||||||
|
Block* create_block_buffer(Point** buffer, int starting_symbol, int rows, int col, int length);
|
||||||
|
|
||||||
enum Direction {
|
enum Direction {
|
||||||
LEFT = -1,
|
LEFT = -1,
|
||||||
@@ -19,6 +20,7 @@ enum Direction {
|
|||||||
struct Point {
|
struct Point {
|
||||||
Point();
|
Point();
|
||||||
Point(int row, int col, char symbol) : m_row(row), m_col(col), m_symbol(symbol) {};
|
Point(int row, int col, char symbol) : m_row(row), m_col(col), m_symbol(symbol) {};
|
||||||
|
Point(int row, int col, int symbol) : m_row(row), m_col(col), m_symbol(symbol) {};
|
||||||
int m_row;
|
int m_row;
|
||||||
int m_col;
|
int m_col;
|
||||||
char m_symbol;
|
char m_symbol;
|
||||||
@@ -47,11 +49,12 @@ struct Paddle {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Block {
|
struct Block {
|
||||||
Block(char symbol, int row, int col);
|
// Block();
|
||||||
|
// Block(char symbol, int row, int col, int size);
|
||||||
|
// ~Block();
|
||||||
int _size;
|
int _size;
|
||||||
int _deleted;
|
int _deleted;
|
||||||
char m_symbol;
|
Point** m_nodes;
|
||||||
Point m_nodes[3];
|
|
||||||
void get_pos();
|
void get_pos();
|
||||||
void check_collision(Ball &ball, int &blocks_left);
|
void check_collision(Ball &ball, int &blocks_left);
|
||||||
void _delete();
|
void _delete();
|
||||||
|
|||||||
+68
-34
@@ -23,6 +23,31 @@ Paddle create_new_paddle(Point** buffer, int starting_array_index, int size, int
|
|||||||
return paddle;
|
return paddle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Block create_new_block(char symbol, int row, int col, int size) {
|
||||||
|
Block block;
|
||||||
|
block._size = size;
|
||||||
|
block.m_nodes = new Point*[size];
|
||||||
|
for(int i = 0; i < size; i++) {
|
||||||
|
block.m_nodes[i] = new Point { row, col + i, symbol };
|
||||||
|
}
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block* create_block_buffer(Point** buffer, int starting_symbol, int rows, int cols, int length) {
|
||||||
|
// Block* block_buffer;
|
||||||
|
// block_buffer = new Block[rows * cols];
|
||||||
|
// for(int i = 0; i < rows; i++) {
|
||||||
|
// for(int b = 0; b < cols; b++) {
|
||||||
|
// block_buffer[i + b] = create_new_block(symbol, i, b + length, int size)
|
||||||
|
// }
|
||||||
|
// Block block = create_new_block('3', 0, 0, 3);
|
||||||
|
// // if(buffer[i + 4] == nullptr) std::cout << "block point is a nullptr\n";
|
||||||
|
// buffer[i + 4] = block.m_nodes[i];
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return block_buffer;
|
||||||
|
// }
|
||||||
|
|
||||||
Paddle::~Paddle() {
|
Paddle::~Paddle() {
|
||||||
delete[] m_nodes;
|
delete[] m_nodes;
|
||||||
}
|
}
|
||||||
@@ -90,38 +115,47 @@ void Ball::get_new_pos() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Block::Block(char symbol, int row, int col) {
|
// Block::~Block() {
|
||||||
_size = 3;
|
// delete[] m_nodes;
|
||||||
_deleted = false;
|
// }
|
||||||
m_symbol = symbol;
|
|
||||||
m_nodes[0].m_col = col;
|
|
||||||
for(int i = 0; i < _size; i++) {
|
|
||||||
m_nodes[i].m_row = row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Block::get_pos() {
|
// Block::Block(char symbol, int row, int col, int size) {
|
||||||
for(int i = 1; i < _size; i++) {
|
// _size = size;
|
||||||
m_nodes[i].m_col = m_nodes[0].m_col + i;
|
// m_symbol = symbol;
|
||||||
}
|
// for(int i = 0; i < size; i++) {
|
||||||
}
|
// m_nodes[i] = new Point;
|
||||||
|
// m_nodes[i]->assign(row, col + i);
|
||||||
void Block::_delete() {
|
//
|
||||||
for(int i = 0; i < _size; i++) {
|
// }
|
||||||
m_nodes[i].assign(ROW - 1, COL - 1);
|
// m_nodes[0]->m_col = col;
|
||||||
m_symbol = '.';
|
// for(int i = 0; i < _size; i++) {
|
||||||
_deleted = true;
|
// m_nodes[i].m_row = row;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void Block::check_collision(Ball &ball, int &blocks_left) {
|
//
|
||||||
for(int i = 0; i < _size; i++) {
|
// void Block::get_pos() {
|
||||||
if(m_nodes[i].m_col == ball.m_origin.m_col) {
|
// for(int i = 1; i < _size; i++) {
|
||||||
if(m_nodes[i].m_row == ball.m_origin.m_row) {
|
// m_nodes[i].m_col = m_nodes[0].m_col + i;
|
||||||
ball.change_velocity('y');
|
// }
|
||||||
_delete();
|
// }
|
||||||
blocks_left--;
|
//
|
||||||
}
|
// void Block::_delete() {
|
||||||
}
|
// for(int i = 0; i < _size; i++) {
|
||||||
}
|
// m_nodes[i].assign(ROW - 1, COL - 1);
|
||||||
}
|
// m_symbol = '.';
|
||||||
|
// _deleted = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// 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--;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ int main(int argc, char **argv) {
|
|||||||
// Block('2', 2, 0), Block('2', 2, 3), Block('2', 2, 6), Block('2', 2, 9), Block('2', 2, 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),
|
// Block('1', 3, 0), Block('1', 3, 3), Block('1', 3, 6), Block('1', 3, 9), Block('1', 3, 12),
|
||||||
// };
|
// };
|
||||||
|
Block block = create_new_block('3', 0, 0, 3);
|
||||||
|
for(int i = 0; i < block._size; i++) {
|
||||||
|
// if(buffer[i + 4] == nullptr) std::cout << "block point is a nullptr\n";
|
||||||
|
buffer[i + 4] = block.m_nodes[i];
|
||||||
|
}
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
std::thread input_thread([&] { input.get_input(running, paddle.m_direction); } );
|
std::thread input_thread([&] { input.get_input(running, paddle.m_direction); } );
|
||||||
|
|||||||
Reference in New Issue
Block a user