Breakout
|
Represents Ball in the game. More...
#include <Ball.h>
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... | |
Represents Ball in the game.
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.
position | Vec2 object that holds the intital x and y position |
velocity | Vec2 object that holds the inital velocity of the ball in terms of x and y coordinates |
WINDOW_HEIGHT | The height of the window rendered |
WINDOW_WIDTH | The width of the window rendered |
ren | The pointer to the renderer of the game loop |
Contact Ball::CheckWallCollision | ( | ) |
This method wil check for collision with the wall and return which wall was hit.
This method wil check for collision with paddle and change the ball's position and velocity accordingly.
contact | The type of contact made by the ball |
This method wil check for collision with the wall and change the ball's position and velocity accordingly.
contact | The type of contact made by the ball |
void Ball::Draw | ( | ) |
This method will draw/ render the ball to the screen.
void Ball::Reset | ( | ) |
This method will reset the ball to it's original position.
void Ball::Update | ( | float | dt | ) |
This method will update the position of the ball based on the time passed i.e.
dt
dt | The amount of time passed between each frame |
Vec2 Ball::defaultPosition |
The Vec2 object to hold the initial position of the ball so we can use it to reset it.
Vec2 Ball::defaultVelocity |
The Vec2 object to hold the initial velocity of the ball so we can use it to reset it.
int Ball::height |
Variable to hold the height of the ball.
SDL_Rect Ball::rect {} |
The rect object to render the the ball on screnn.
SDL_Renderer* Ball::renderer |
The renderer object to store the pointer to the to actual renderer of the game loop.
ResourceManager Ball::resourceManager = ResourceManager::getInstance() |
The resource manager instance to load and unload resources.
SDL_Surface* Ball::spriteSheet |
The spritesheet of the Ball.
SDL_Texture* Ball::texture |
The texture of the ball.
int Ball::width |
The variable to hold the width of the ball.
int Ball::WINDOW_HEIGHT |
The height of the window.
int Ball::WINDOW_WIDTH |
The width of the window.