feat: Added ball and collision to paddles. Added a score system and timer for game. May be done in one day.

This commit is contained in:
DarthMooMancer
2025-08-30 22:41:39 -04:00
parent fe8e4346a2
commit fbdf7af31e
9 changed files with 138 additions and 44 deletions
+15 -6
View File
@@ -9,19 +9,28 @@ struct Point {
Point();
Point(int row, int col) : m_row(row), m_col(col) {};
void to_string();
void to_string(int index);
void clear(std::array<std::array<char, COL>, ROW> &m_board);
// void set_new_point(int row, int col);
void assign(int row, int col);
};
struct Ball {
Ball();
Point m_origin;
int m_vx = 1;
int m_vy = -1;
bool m_goal;
void get_new_pos();
void check_collision();
void change_direction(char d);
};
struct Paddle {
Paddle(int col);
int _size;
int m_score;
Point m_nodes[4];
void get_new_pos(int col);
};
struct Ball {
void check_collision(Ball &ball);
};
#endif
+1 -1
View File
@@ -2,6 +2,6 @@
#define GLOBALS_HPP
constexpr unsigned int ROW = 10;
constexpr unsigned int COL = 20;
constexpr unsigned int COL = 21;
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef TIMER_HPP
#define TIMER_HPP
struct Timer {
void decrement_time(int &time, bool &running, bool &timer_active);
};
#endif
+2 -4
View File
@@ -6,9 +6,7 @@
#include "elements.hpp"
struct Window {
// Window();
std::array<std::array<char, COL>, ROW> m_board;
// void update_display();
void update_display(Paddle &a, Paddle &b);
std::array<std::array<char, COL>, ROW> m_board = {};
void update_display(Paddle &left, Paddle &right, Ball &ball, int &time);
};
#endif