The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
Loading...
Searching...
No Matches
ball_base.hpp
Go to the documentation of this file.
1
8#ifndef BALL_BASE_HPP
9#define BALL_BASE_HPP
10
11#include <SDL.h>
12#include "user.hpp"
13
23{
24public:
29 BallBase(float size = 35.0f);
30
34 virtual ~BallBase() {};
35
48 virtual void update(float travel_time, class Paddle *paddle1, class Paddle *paddle2, User *player1, User *player2);
49
57 virtual void render_object(SDL_Renderer *renderer) = 0;
58
64 virtual void reset();
65
72
79 void set_position(float x, float y)
80 {
81 pos_x = x;
82 pos_y = y;
83 }
84
91 void set_velocity(float velX, float velY)
92 {
93 vel_x = velX;
94 vel_y = velY;
95 }
96
102 void set_color(const SDL_Color &new_color) { color = new_color; }
103
112 virtual SDL_Rect boundaries() const
113 {
114 return SDL_Rect{
115 static_cast<int>(pos_x - ball_size / 2.0f),
116 static_cast<int>(pos_y - ball_size / 2.0f),
117 static_cast<int>(ball_size),
118 static_cast<int>(ball_size)};
119 }
120
125 float get_vel_x() const { return vel_x; }
126
131 float get_vel_y() const { return vel_y; }
132
137 float get_pos_x() const { return pos_x; }
138
143 float get_pos_y() const { return pos_y; }
144
149 SDL_Color get_color() const { return color; }
150
151 void set_game_mode (int mode ) { game_mode = mode; }
152 int get_game_mode() const { return game_mode; }
153
154protected:
155 float pos_x;
156 float pos_y;
157 float vel_x;
158 float vel_y;
159 const float ball_size;
160 SDL_Color color;
161 int game_mode = -1;
162};
163
164#endif
SDL_Renderer * renderer
Definition ball_test.cpp:25
Abstract base class for all ball types in the game.
Definition ball_base.hpp:23
float get_vel_x() const
Gets the x-velocity component of the ball.
Definition ball_base.hpp:125
float vel_y
Definition ball_base.hpp:158
virtual void render_object(SDL_Renderer *renderer)=0
Pure virtual method to render the ball.
float get_pos_y() const
Gets the y-coordinate of the ball.
Definition ball_base.hpp:143
void set_game_mode(int mode)
Definition ball_base.hpp:151
float pos_x
Definition ball_base.hpp:155
float vel_x
Definition ball_base.hpp:157
SDL_Color color
Definition ball_base.hpp:160
virtual ~BallBase()
Virtual destructor for proper cleanup in derived classes.
Definition ball_base.hpp:34
void set_color(const SDL_Color &new_color)
Sets the color of the ball.
Definition ball_base.hpp:102
void set_position(float x, float y)
Sets the position of the ball.
Definition ball_base.hpp:79
void random_direction_angle()
Randomizes the direction of the ball.
Definition ball_base.cpp:37
virtual SDL_Rect boundaries() const
Gets the collision boundaries of the ball.
Definition ball_base.hpp:112
virtual void reset()
Resets the ball to the center of the screen.
Definition ball_base.cpp:131
int game_mode
Definition ball_base.hpp:161
BallBase(float size=35.0f)
Constructor for BallBase.
Definition ball_base.cpp:24
float pos_y
Definition ball_base.hpp:156
float get_vel_y() const
Gets the y-velocity component of the ball.
Definition ball_base.hpp:131
virtual void update(float travel_time, class Paddle *paddle1, class Paddle *paddle2, User *player1, User *player2)
Updates the ball's position and handles collisions.
Definition ball_base.cpp:63
const float ball_size
Definition ball_base.hpp:159
void set_velocity(float velX, float velY)
Sets the velocity of the ball.
Definition ball_base.hpp:91
SDL_Color get_color() const
Gets the color of the ball.
Definition ball_base.hpp:149
int get_game_mode() const
Definition ball_base.hpp:152
float get_pos_x() const
Gets the x-coordinate of the ball.
Definition ball_base.hpp:137
Represents a player paddle/racket in the game.
Definition paddle.hpp:20
Represents a player in the game with name and score tracking.
Definition user.hpp:23
Header defining the User class for player management.