casse-brick
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
Ball Class Reference

The Ball class represents a ball object in the game. More...

#include <Ball.h>

Inheritance diagram for Ball:
MovingObject CollidingObject

Public Member Functions

 Ball (int x, int y, int radius, const SDL_Color &color, const std::string &id)
 Constructs a new Ball object.
 
void render (std::shared_ptr< SDL_Renderer > renderer, SDL_Color color1, SDL_Color color2) override
 Renders the ball on the screen.
 
void move () override
 Moves the ball according to its velocity.
 
void setVelocity (float dx, float dy)
 Sets the velocity of the ball.
 
void handleCollisions (point collision) override
 Handles collisions with other objects.
 
void handleCollision (point vect)
 Handles collision with a single object.
 
- Public Member Functions inherited from MovingObject
 MovingObject (int x, int y, int radius, const std::string &id)
 Constructs a new MovingObject with a circular collider.
 
 MovingObject (int x, int y, int width, int height, const std::string &id)
 Constructs a new MovingObject with a rectangular collider.
 
virtual void move ()=0
 Moves the object.
 
- Public Member Functions inherited from CollidingObject
 CollidingObject (int x, int y, int radius, const std::string &id)
 Constructs a new CollidingObject with a circular collider.
 
 CollidingObject (int x, int y, int width, int height, const std::string &id)
 Constructs a new CollidingObject with a rectangular collider.
 
 CollidingObject (int x, int y, int width, int height, bool isTop, const std::string &id)
 Constructs a new CollidingObject with a triangular collider.
 
 CollidingObject (int x, int y, int width, int height, int edges, const std::string &id)
 Constructs a new CollidingObject with a hexagonal collider.
 
std::shared_ptr< CollidergetCollider ()
 Gets the collider associated with the object.
 
virtual void handleCollisions (point collision)=0
 Handles collisions with other objects.
 
virtual void render (std::shared_ptr< SDL_Renderer > renderer, SDL_Color color1, SDL_Color color2)=0
 Renders the object on the screen.
 

Data Fields

point Velocity
 
int bounce_number
 
- Data Fields inherited from MovingObject
point Velocity
 The velocity of the object.
 

Additional Inherited Members

- Protected Attributes inherited from CollidingObject
std::shared_ptr< Collidercollider
 The collider associated with the object.
 

Detailed Description

The Ball class represents a ball object in the game.

The Ball class inherits from the MovingObject class and represents a ball that moves within the game environment.

Definition at line 20 of file Ball.h.

Constructor & Destructor Documentation

◆ Ball()

Ball::Ball ( int  x,
int  y,
int  radius,
const SDL_Color &  color,
const std::string &  id 
)

Constructs a new Ball object.

Parameters
xThe x-coordinate of the ball's initial position.
yThe y-coordinate of the ball's initial position.
radiusThe radius of the ball.
colorThe color of the ball.
idThe unique identifier of the ball.

Definition at line 7 of file Ball.cpp.

Member Function Documentation

◆ handleCollision()

void Ball::handleCollision ( point  vect)

Handles collision with a single object.

Parameters
vectThe vector representing the collision.

Definition at line 46 of file Ball.cpp.

◆ handleCollisions()

void Ball::handleCollisions ( point  collision)
overridevirtual

Handles collisions with other objects.

Parameters
collisionThe point of collision.

Implements CollidingObject.

Definition at line 25 of file Ball.cpp.

◆ move()

void Ball::move ( )
overridevirtual

Moves the ball according to its velocity.

Implements MovingObject.

Definition at line 17 of file Ball.cpp.

◆ render()

void Ball::render ( std::shared_ptr< SDL_Renderer >  renderer,
SDL_Color  color1,
SDL_Color  color2 
)
overridevirtual

Renders the ball on the screen.

Parameters
rendererA shared pointer to the SDL renderer used for rendering.
color1The primary color of the ball.
color2The secondary color of the ball.

Implements CollidingObject.

Definition at line 13 of file Ball.cpp.

◆ setVelocity()

void Ball::setVelocity ( float  dx,
float  dy 
)

Sets the velocity of the ball.

Parameters
dxThe velocity component in the x-direction.
dyThe velocity component in the y-direction.

Definition at line 21 of file Ball.cpp.

Field Documentation

◆ bounce_number

int Ball::bounce_number

Definition at line 23 of file Ball.h.

◆ Velocity

point Ball::Velocity

Definition at line 22 of file Ball.h.


The documentation for this class was generated from the following files: