Breakout
Public Member Functions | Public Attributes | List of all members
Ball Class Reference

Represents Ball in the game. More...

#include <Ball.h>

Collaboration diagram for Ball:
Collaboration graph
[legend]

Public Member Functions

 Ball (Vec2 position, Vec2 velocity, int WINDOW_HEIGHT, int WINDOW_WIDTH, SDL_Renderer *ren)
 The constructor of ball class that will take in the initial ball position, velocity along with window height and window width and also the renderer. More...
 
void Draw ()
 This method will draw/ render the ball to the screen. More...
 
void Update (float dt)
 This method will update the position of the ball based on the time passed i.e. More...
 
void CollideWithPaddle (Contact const &contact)
 This method wil check for collision with paddle and change the ball's position and velocity accordingly. More...
 
void CollideWithWall (Contact const &contact)
 This method wil check for collision with the wall and change the ball's position and velocity accordingly. More...
 
Contact CheckWallCollision ()
 This method wil check for collision with the wall and return which wall was hit. More...
 
void Reset ()
 This method will reset the ball to it's original position. More...
 
void FlipDirectionX ()
 This method will change the Ball's x direction direction. More...
 
void FlipDirectionY ()
 This method will change the Ball's y direction direction. More...
 

Public Attributes

ResourceManager resourceManager = ResourceManager::getInstance()
 The resource manager instance to load and unload resources. More...
 
Vec2 position
 The Vec2 object to hold the position for the ball. More...
 
Vec2 velocity
 The Vec2 object to hold the velocity of the ball. More...
 
Vec2 defaultPosition
 The Vec2 object to hold the initial position of the ball so we can use it to reset it. More...
 
Vec2 defaultVelocity
 The Vec2 object to hold the initial velocity of the ball so we can use it to reset it. More...
 
int height
 Variable to hold the height of the ball. More...
 
int width
 The variable to hold the width of the ball. More...
 
SDL_Rect rect {}
 The rect object to render the the ball on screnn. More...
 
int WINDOW_HEIGHT
 The height of the window. More...
 
int WINDOW_WIDTH
 The width of the window. More...
 
SDL_Renderer * renderer
 The renderer object to store the pointer to the to actual renderer of the game loop. More...
 
SDL_Surface * spriteSheet
 The spritesheet of the Ball. More...
 
SDL_Texture * texture
 The texture of the ball. More...
 

Detailed Description

Represents Ball in the game.

Constructor & Destructor Documentation

◆ Ball()

Ball::Ball ( Vec2  position,
Vec2  velocity,
int  WINDOW_HEIGHT,
int  WINDOW_WIDTH,
SDL_Renderer *  ren 
)

The constructor of ball class that will take in the initial ball position, velocity along with window height and window width and also the renderer.

Parameters
positionVec2 object that holds the intital x and y position
velocityVec2 object that holds the inital velocity of the ball in terms of x and y coordinates
WINDOW_HEIGHTThe height of the window rendered
WINDOW_WIDTHThe width of the window rendered
renThe pointer to the renderer of the game loop

Member Function Documentation

◆ CheckWallCollision()

Contact Ball::CheckWallCollision ( )

This method wil check for collision with the wall and return which wall was hit.

Returns
The type of contact made by the ball i.e. which wall was hit by the ball

◆ CollideWithPaddle()

void Ball::CollideWithPaddle ( Contact const &  contact)

This method wil check for collision with paddle and change the ball's position and velocity accordingly.

Parameters
contactThe type of contact made by the ball

◆ CollideWithWall()

void Ball::CollideWithWall ( Contact const &  contact)

This method wil check for collision with the wall and change the ball's position and velocity accordingly.

Parameters
contactThe type of contact made by the ball

◆ Draw()

void Ball::Draw ( )

This method will draw/ render the ball to the screen.

◆ FlipDirectionX()

void Ball::FlipDirectionX ( )

This method will change the Ball's x direction direction.

◆ FlipDirectionY()

void Ball::FlipDirectionY ( )

This method will change the Ball's y direction direction.

◆ Reset()

void Ball::Reset ( )

This method will reset the ball to it's original position.

◆ Update()

void Ball::Update ( float  dt)

This method will update the position of the ball based on the time passed i.e.

dt

Parameters
dtThe amount of time passed between each frame

Member Data Documentation

◆ defaultPosition

Vec2 Ball::defaultPosition

The Vec2 object to hold the initial position of the ball so we can use it to reset it.

◆ defaultVelocity

Vec2 Ball::defaultVelocity

The Vec2 object to hold the initial velocity of the ball so we can use it to reset it.

◆ height

int Ball::height

Variable to hold the height of the ball.

◆ position

Vec2 Ball::position

The Vec2 object to hold the position for the ball.

◆ rect

SDL_Rect Ball::rect {}

The rect object to render the the ball on screnn.

◆ renderer

SDL_Renderer* Ball::renderer

The renderer object to store the pointer to the to actual renderer of the game loop.

◆ resourceManager

ResourceManager Ball::resourceManager = ResourceManager::getInstance()

The resource manager instance to load and unload resources.

◆ spriteSheet

SDL_Surface* Ball::spriteSheet

The spritesheet of the Ball.

◆ texture

SDL_Texture* Ball::texture

The texture of the ball.

◆ velocity

Vec2 Ball::velocity

The Vec2 object to hold the velocity of the ball.

◆ width

int Ball::width

The variable to hold the width of the ball.

◆ WINDOW_HEIGHT

int Ball::WINDOW_HEIGHT

The height of the window.

◆ WINDOW_WIDTH

int Ball::WINDOW_WIDTH

The width of the window.


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