fuck this shit

This commit is contained in:
DarthMooMancer
2025-11-23 23:09:26 -05:00
parent d216202858
commit fbd412d9f1
4 changed files with 59 additions and 92 deletions
+46 -43
View File
@@ -4,6 +4,7 @@
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
void Window::clear_display() {
for(int i = 0; i < ROW; i++) {
@@ -13,14 +14,14 @@ void Window::clear_display() {
}
}
void Window::update_board(Paddle paddle, Ball ball) {
void Window::update_board(Paddle paddle, Ball ball, std::vector<Block>) {
for(int i = 0; i < paddle.m_nodes.size(); i++) {
view[paddle.m_nodes[i].y][paddle.m_nodes[i].x] = paddle.m_nodes[i].m_symbol;
}
view[ball.m_origin.y][ball.m_origin.x] = ball.m_origin.m_symbol;
}
void Window::draw_display(int fps) {
void Window::draw_display(int fps) const {
std::cout << "\033[H" << std::flush;
for(int i = 0; i < ROW; i++) {
for(int j = 0; j < COL; j++) {
@@ -37,6 +38,17 @@ Engine::Engine() {
cbreak();
noecho();
nodelay(stdscr, true);
vec2 block_size = { 5, 3 };
int row, int_symbol, col;
char char_symbol;
for(int index = 0; index < block_size.y * block_size.x; index++) {
row = index / 5;
int_symbol = ('3' - '0') - row;
char_symbol = '0' + int_symbol;
col = (index % 5) * 3;
Block new_block = { { col, row }, char_symbol };
block_buffer.push_back(new_block);
}
}
Engine::~Engine() {
@@ -52,46 +64,37 @@ void Engine::run() {
// Block** block_buffer = create_block_buffer('3', 3, 5, 3);
// rasterize_buffer(buffer, block_buffer, 4);
std::thread input_thread([&] { input.get_input(running, paddle.m_direction); } );
while (process_input() && quit_if()) {
// while (process_input() && quit_if()) {
while (process_input()) {
paddle.determine_new_position(win.view);
paddle.check_collision(ball);
// trim_block_buffer_on_collision(buffer, buffer_size, block_buffer, block_buffer_size, ball);
ball.determine_new_position(paddle.m_hearts, (ROW - 5), (COL / 2));
win.clear_display();
win.update_board(paddle, ball);
win.update_board(paddle, ball, block_buffer);
win.draw_display(FPMS);
if(paddle.m_hearts <= 0) {
running = false;
std::cout << "No Hearts left! You lose!\n";
}
// if(paddle.m_hearts <= 0) {
// running = false;
// std::cout << "No Hearts left! You lose!\n";
// }
// if(is_block_buffer_empty(block_buffer, block_buffer_size)) {
// running = false;
// std::cout << "No Blocks left! You win!\n";
// }
std::cout << "Hearts left: " << paddle.m_hearts << "\n";
}
input_thread.join();
// cleanup(block_buffer, block_buffer_size);
}
// 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;
// char char_symbol;
// for(int index = 0; index < rows * cols; index++) {
// row = index / 5;
// int_symbol = (starting_symbol - '0') - row;
// char_symbol = '0' + int_symbol;
// col = (index % 5) * 3;
// block_buffer[index] = new Block(length, row, col, char_symbol);
// }
// return block_buffer;
// }
bool Engine::process_input() {
int ch;
while((ch = getch()) != ERR) {
if(ch == 'd') paddle.dir = Direction::RIGHT;
if(ch == 'a') paddle.dir = Direction::LEFT;
if(ch == 'q') return false;
}
return true;
}
//
// bool is_block_buffer_empty(Block** block_buffer, int block_buffer_size) {
// int total_clear_blocks = 0;
@@ -191,17 +194,17 @@ void Ball::determine_new_position(int &paddle_lives, int reset_ball_x, int reset
m_origin.y += vel.y;
}
// 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 < m_nodes.size(); i++) {
// if(m_nodes[i] != ball.m_origin) continue;
// return true;
// }
// return false;
// }
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 < m_nodes.size(); i++) {
if(m_nodes[i] != ball.m_origin) continue;
return true;
}
return false;
}