![]() |
The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
|
Abstract base class for all ball types in the game. More...
#include <ball_base.hpp>
Public Member Functions | |
BallBase (float size=35.0f) | |
Constructor for BallBase. | |
virtual SDL_Rect | boundaries () const |
Gets the collision boundaries of the ball. | |
SDL_Color | get_color () const |
Gets the color of the ball. | |
int | get_game_mode () const |
float | get_pos_x () const |
Gets the x-coordinate of the ball. | |
float | get_pos_y () const |
Gets the y-coordinate of the ball. | |
float | get_vel_x () const |
Gets the x-velocity component of the ball. | |
float | get_vel_y () const |
Gets the y-velocity component of the ball. | |
void | random_direction_angle () |
Randomizes the direction of the ball. | |
virtual void | render_object (SDL_Renderer *renderer)=0 |
Pure virtual method to render the ball. | |
virtual void | reset () |
Resets the ball to the center of the screen. | |
void | set_color (const SDL_Color &new_color) |
Sets the color of the ball. | |
void | set_game_mode (int mode) |
void | set_position (float x, float y) |
Sets the position of the ball. | |
void | set_velocity (float velX, float velY) |
Sets the velocity of the ball. | |
virtual void | update (float travel_time, class Paddle *paddle1, class Paddle *paddle2, User *player1, User *player2) |
Updates the ball's position and handles collisions. | |
virtual | ~BallBase () |
Virtual destructor for proper cleanup in derived classes. | |
Protected Attributes | |
const float | ball_size |
SDL_Color | color |
int | game_mode = -1 |
float | pos_x |
float | pos_y |
float | vel_x |
float | vel_y |
Abstract base class for all ball types in the game.
This class defines the common interface and functionality for all types of balls in the game. It handles movement, collision detection, and score updates.
BallBase::BallBase | ( | float | size = 35.0f | ) |
Constructor for BallBase.
size | The size (diameter) of the ball, defaults to 15.0f |
Initializes the ball at the center of the screen with a specified size and randomizes its initial direction
size | The size (diameter) of the ball |
|
virtual |
Virtual destructor for proper cleanup in derived classes.
|
virtual |
Gets the collision boundaries of the ball.
Returns a rectangle representing the ball's position and size for collision detection purposes.
SDL_Color BallBase::get_color | ( | ) | const |
Gets the color of the ball.
int BallBase::get_game_mode | ( | ) | const |
float BallBase::get_pos_x | ( | ) | const |
Gets the x-coordinate of the ball.
float BallBase::get_pos_y | ( | ) | const |
Gets the y-coordinate of the ball.
float BallBase::get_vel_x | ( | ) | const |
Gets the x-velocity component of the ball.
float BallBase::get_vel_y | ( | ) | const |
Gets the y-velocity component of the ball.
void BallBase::random_direction_angle | ( | ) |
Randomizes the direction of the ball.
Changes the ball's velocity to move in a random direction
Sets the ball's velocity to move in a random direction with a random angle between -45 and 45 degrees
|
pure virtual |
Pure virtual method to render the ball.
Must be implemented by derived classes to draw their specific ball shape
renderer | The SDL renderer to use for drawing |
Implemented in ClassicBall, SquareBall, and TriangleBall.
|
virtual |
Resets the ball to the center of the screen.
Repositions the ball and randomizes its direction
Repositions the ball to the center and randomizes its direction
void BallBase::set_color | ( | const SDL_Color & | new_color | ) |
Sets the color of the ball.
new_color | The new color as an SDL_Color |
void BallBase::set_game_mode | ( | int | mode | ) |
void BallBase::set_position | ( | float | x, |
float | y ) |
Sets the position of the ball.
x | The new x-coordinate |
y | The new y-coordinate |
void BallBase::set_velocity | ( | float | velX, |
float | velY ) |
Sets the velocity of the ball.
velX | The new x-velocity component |
velY | The new y-velocity component |
|
virtual |
Updates the ball's position and handles collisions.
Moves the ball according to its velocity, checks for collisions with walls and paddles, and updates player scores when necessary.
travel_time | Time delta since last update (in seconds) |
paddle1 | Pointer to the first paddle |
paddle2 | Pointer to the second paddle |
player1 | Pointer to the first player's data |
player2 | Pointer to the second player's data |
|
protected |
Ball's size (diameter by default)
|
protected |
Ball's color
|
protected |
|
protected |
Ball's x position
|
protected |
Ball's y position
|
protected |
Ball's x velocity
|
protected |
Ball's y velocity