major refactor

This commit is contained in:
DarthMooMancer
2025-09-27 18:12:07 -04:00
parent efa2952ae2
commit 7c79f41b93
10 changed files with 156 additions and 138 deletions
+27 -16
View File
@@ -1,31 +1,42 @@
#ifndef ELEMENTS_HPP
#define ELEMENTS_HPP
struct Point {
Point();
int m_row;
int m_col;
void assign(int row, int col);
#include "globals.hpp"
enum Direction {
NONE = 0,
UP = -1,
DOWN = 1
};
struct Point {
Point() : m_row(0), m_col(0) {};
Point(int r, int c, char s) : m_row(r), m_col(c), m_symbol(s) {};
int m_row;
int m_col;
char m_symbol;
};
struct Ball {
Ball();
Point m_origin;
Ball() : m_vx(1), m_vy(-1) {};
Point* m_origin;
int m_vx;
int m_vy;
bool m_goal;
void get_new_pos();
void check_collision();
void change_direction(char d);
bool determine_next_valid_position(Point* (*board)[COL]);
};
struct Paddle {
Paddle(int col);
int _size;
Paddle() : m_score(0) {};
int m_score;
Point m_nodes[3];
void get_new_pos(int col);
void check_collision(Ball &ball);
int m_size;
Point** m_nodes;
enum Direction m_dir;
void determine_new_position(Point* (*board)[COL]);
};
void on_collision_with_ball(Point** segments, Ball &ball, int t_size);
Ball create_ball(Point** segments, int row, int col, char symbol, int t_size);
Paddle create_paddle(Point** segments, int starting_index, int ending_index, int column, char symbol);
#endif
+2 -2
View File
@@ -3,8 +3,8 @@
#include "elements.hpp"
struct Input {
char m_getch = ' ';
void get_input(bool &r, Paddle &a, Paddle &b);
int m_getch = 0;
void get_input(enum Direction &left, enum Direction &right, bool &running);
};
#endif // INPUT_HPP
+1 -1
View File
@@ -2,7 +2,7 @@
#define TIMER_HPP
struct Timer {
void decrement_time(int &time, bool &running, bool &timer_active);
void decrement_time(int &time, bool &running);
};
#endif
+4 -3
View File
@@ -1,12 +1,13 @@
#ifndef WINDOW_HPP
#define WINDOW_HPP
#include <array>
#include "globals.hpp"
#include "elements.hpp"
struct Window {
std::array<std::array<char, COL>, ROW> m_board = {};
void update_display(Paddle &left, Paddle &right, Ball &ball, int &time);
Point* m_board[ROW][COL] = {};
void clear_display();
void draw_display(int milliseconds);
void update_display(Point** segments);
};
#endif