From a955f2d067048d5d89cb34ad323819feebd616a4 Mon Sep 17 00:00:00 2001 From: DarthMooMancer <107283522+DarthMooMancer@users.noreply.github.com> Date: Fri, 14 Nov 2025 23:19:39 -0500 Subject: [PATCH] renaming --- .DS_Store | Bin 0 -> 6148 bytes CMakeLists.txt | 2 +- include/elements.hpp | 64 ------------------------------- include/engine.hpp | 59 ++++++++++++++++++++++++++++ include/input.hpp | 7 +--- include/window.hpp | 12 ++---- src/{elements.cpp => engine.cpp} | 62 +++++++++++++++--------------- src/main.cpp | 14 +++---- src/window.cpp | 4 +- 9 files changed, 106 insertions(+), 118 deletions(-) create mode 100644 .DS_Store delete mode 100644 include/elements.hpp create mode 100644 include/engine.hpp rename src/{elements.cpp => engine.cpp} (63%) diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2bac81565403f278fb06598d61b126ca8a9a16bb GIT binary patch literal 6148 zcmeHKy-EW?5T4bjK?@^V2nt>mt%CXlXE+PRLP%p7lSmS{c)_2-?tBBEKzsuW8}$Wz z3QMg;u(1%o*=%I_<+V-|y=CV7!w=Q7ukt7|&l<&yH`_ zA2zZ%jc;?hEq9-|z!a3jI-1m`6K@Yu?V=lV`Ildx%6HqEzgOEy`rO0f9`ED}^NvxC zPQe>f!(*Pgy!WFn_ulPCadAg;JM}L6@C=WC_KNu@z^cVKao6&7mbV@Xc|D_aOh;7rw4jB@e#GV9nvSX^ql2w;d9zWUZ6!=#P zs9aQu%6KJvwq{ struct Input { int m_getch; void get_input(bool &running, enum Direction &dir); }; - -#endif // INPUT_HPP diff --git a/include/window.hpp b/include/window.hpp index d3076a2..a41b58a 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -1,14 +1,10 @@ -#ifndef WINDOW_HPP -#define WINDOW_HPP - +#pragma once +#include #include "globals.hpp" -#include "elements.hpp" struct Window { - Point* m_board[ROW][COL] = {}; + vec2* m_board[ROW][COL] = {}; void clear_display(); void draw_display(int fps); - void update_board(Point** buffer, int buffer_size); + void update_board(vec2** buffer, int buffer_size); }; - -#endif diff --git a/src/elements.cpp b/src/engine.cpp similarity index 63% rename from src/elements.cpp rename to src/engine.cpp index b42405f..32cd058 100644 --- a/src/elements.cpp +++ b/src/engine.cpp @@ -1,25 +1,25 @@ -#include "elements.hpp" +#include #include "globals.hpp" -Paddle create_new_paddle(Point** buffer, int starting_array_index, int size, int row, char symbol) { +Paddle create_new_paddle(vec2** buffer, int starting_array_index, int size, int row, char symbol) { Paddle paddle { size }; - paddle.m_nodes = new Point*[size]; + paddle.m_nodes = new vec2*[size]; for(int i = 0; i < size; i++) { - paddle.m_nodes[i] = new Point { row, ((COL / 2) - (size / 2)) + i, symbol }; + paddle.m_nodes[i] = new vec2 { row, ((COL / 2) - (size / 2)) + i, symbol }; buffer[i + starting_array_index] = paddle.m_nodes[i]; } return paddle; } -Ball create_new_ball(Point** buffer, int buffer_index, int default_vx, int default_vy, int row, int col, char symbol) { +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 Point { row, col, symbol }; + ball.m_origin = new vec2 { row, col, symbol }; buffer[buffer_index] = ball.m_origin; return ball; } -Block** create_block_buffer(int starting_array_index, int starting_symbol, int rows, int cols, int length) { +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; @@ -51,7 +51,7 @@ void cleanup(Block** block_buffer, int block_buffer_size) { delete[] block_buffer; } -void rasterize_buffer(Point** buffer, Block** block_buffer, int offset) { +void rasterize_buffer(vec2** buffer, Block** block_buffer, int offset) { for(int block_index = 0; block_index < 15; block_index++) { if(block_buffer[block_index] == nullptr) continue; for(int node_index = 0; node_index < block_buffer[block_index]->_size; node_index++) { @@ -61,13 +61,13 @@ void rasterize_buffer(Point** buffer, Block** block_buffer, int offset) { } } -void trim_block_buffer_on_collision(Point** buffer, int buffer_size, Block** block_buffer, int &block_buffer_size, Ball &ball) { +void trim_block_buffer_on_collision(vec2** buffer, const int buffer_size, Block** block_buffer, const int block_buffer_size, Ball &ball) { for(int i = 0; i < block_buffer_size; i++) { if(block_buffer[i] == nullptr) continue; if(block_buffer[i]->check_collision(ball)) { ball.change_velocity('y'); for(int a = 0; a < block_buffer[i]->_size; a++) { - Point* doomed = block_buffer[i]->m_nodes[a]; + vec2* doomed = block_buffer[i]->m_nodes[a]; for(int j = 0; j < buffer_size; j++) { if(buffer[j] == doomed) { buffer[j] = nullptr; @@ -91,17 +91,17 @@ Paddle::~Paddle() { } } -void Paddle::determine_new_position(Point* (*board)[COL]) { - if(m_direction == LEFT && m_nodes[0]->m_col - 1 >= 0) { - m_nodes[0]->m_col--; +void Paddle::determine_new_position(vec2* (*board)[COL]) { + if(m_direction == LEFT && m_nodes[0]->x - 1 >= 0) { + m_nodes[0]->x--; for(int i = 1; i < _size; i++) { - m_nodes[i]->m_col = m_nodes[0]->m_col + i; + m_nodes[i]->x = m_nodes[0]->x + i; } } - else if(m_direction == RIGHT && m_nodes[_size - 1]->m_col + 1 < ROW) { - m_nodes[_size - 1]->m_col++; + else if(m_direction == RIGHT && m_nodes[_size - 1]->x + 1 < ROW) { + m_nodes[_size - 1]->x++; for(int i = 1; i < _size; i++) { - m_nodes[_size - (i + 1)]->m_col = m_nodes[_size - 1]->m_col - i; + m_nodes[_size - (i + 1)]->x = m_nodes[_size - 1]->x - i; } } m_direction = NONE; @@ -109,8 +109,8 @@ void Paddle::determine_new_position(Point* (*board)[COL]) { void Paddle::check_collision(Ball &ball) { for(int i = 0; i < _size; i++) { - if(ball.m_origin->m_row != m_nodes[i]->m_row) continue; - if(ball.m_origin->m_col != m_nodes[i]->m_col) continue; + if(ball.m_origin->y != m_nodes[i]->y) continue; + if(ball.m_origin->x != m_nodes[i]->x) continue; ball.change_velocity('y'); } } @@ -131,21 +131,21 @@ void Ball::change_velocity(char d) { } void Ball::determine_new_position(int &paddle_lives, int reset_ball_x, int reset_ball_y) { - if(m_origin->m_row <= 0) { + if(m_origin->y <= 0) { vy = 1; - } else if(m_origin->m_row >= ROW - 1) { + } else if(m_origin->y >= ROW - 1) { paddle_lives--; - m_origin->m_row = reset_ball_y; - m_origin->m_col = reset_ball_x; + m_origin->y = reset_ball_y; + m_origin->x = reset_ball_x; } - if(m_origin->m_col <= 0) { + if(m_origin->x <= 0) { vx = 1; - } else if(m_origin->m_col >= COL - 1) { + } else if(m_origin->x >= COL - 1) { vx = -1; } - m_origin->m_col += vx; - m_origin->m_row += vy; + m_origin->x += vx; + m_origin->y += vy; } Block::~Block() { @@ -161,16 +161,16 @@ Block::~Block() { Block::Block(int size, int row, int col, char symbol) { _size = size; - m_nodes = new Point*[size]; + m_nodes = new vec2*[size]; for(int i = 0; i < size; i++) { - m_nodes[i] = new Point { row, col + i, symbol }; + m_nodes[i] = new vec2 { row, col + i, symbol }; } } bool Block::check_collision(Ball &ball) { for(int i = 0; i < _size; i++) { - if(m_nodes[i]->m_col != ball.m_origin->m_col) continue; - if(m_nodes[i]->m_row != ball.m_origin->m_row) continue; + if(m_nodes[i]->x != ball.m_origin->x) continue; + if(m_nodes[i]->y != ball.m_origin->y) continue; return true; } return false; diff --git a/src/main.cpp b/src/main.cpp index dade044..189f452 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,20 @@ #include #include +#include #include "globals.hpp" -#include "input.hpp" -#include "window.hpp" -#include "elements.hpp" +#include +#include int main() { - int buffer_size = 50, block_buffer_size = 15; + const int buffer_size = 50, block_buffer_size = 15; bool running = true; - Point* buffer[50] = {}; + vec2* buffer[buffer_size] = {}; Input input; Window window; - Paddle paddle = create_new_paddle(buffer, 1, 3, ROW - 2, '-'); Ball ball = create_new_ball(buffer, 0, 1, -1, (ROW - 5), (COL / 2), '*' ); - Block** block_buffer = create_block_buffer(4, '3', 3, 5, 3); + Paddle paddle = create_new_paddle(buffer, 1, 3, ROW - 2, '-'); + 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); } ); diff --git a/src/window.cpp b/src/window.cpp index a6d36d5..8fad8a6 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -11,10 +11,10 @@ void Window::clear_display() { } } -void Window::update_board(Point** buffer, int buffer_size) { +void Window::update_board(vec2** buffer, int buffer_size) { for(int i = buffer_size - 1; i >= 0; i--) { if(buffer[i] == nullptr) continue; - m_board[buffer[i]->m_row][buffer[i]->m_col] = buffer[i]; + m_board[buffer[i]->y][buffer[i]->x] = buffer[i]; } }