The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
Loading...
Searching...
No Matches
Power Class Reference

Class representing power-up items that affect gameplay. More...

#include <power.hpp>

+ Inheritance diagram for Power:

Public Member Functions

bool collision (BallBase *ball_type) const
 Checks for collision between the power and the ball.
 
 Power (int screen_width, int screen_height)
 Constructor for the Power class.
 
virtual void render (SDL_Renderer *renderer)
 Renders the power on screen.
 
virtual void reset (int screen_width)
 Resets the power-up to a new random position.
 
void set_effect_is_active (bool active)
 
void set_is_active (bool active)
 Sets the active state of the power-up.
 
virtual void update (float time, Paddle *racket1, Paddle *racket2, SDL_Renderer *renderer, BallBase *ball)
 Updates the power's position and effect.
 

Protected Attributes

SDL_Color color
 
float duration_effect = 0.0f
 
bool effect_is_active = false
 
int height
 
bool is_active = false
 
bool play = true
 
SDL_Texture * power_texture = nullptr
 
float speed
 
int width
 
float x = 0
 
float y = 0
 

Detailed Description

Class representing power-up items that affect gameplay.

This class defines powerups that can be collected during gameplay to modify game elements like paddle size.

Constructor & Destructor Documentation

◆ Power()

Power::Power ( int screen_width,
int screen_height )

Constructor for the Power class.

Parameters
screen_widthThe width of the game screen
screen_heightThe height of the game screen

Initializes the power with random size and position

Parameters
screen_widthThe width of the game screen
screen_heightThe height of the game screen

Member Function Documentation

◆ collision()

bool Power::collision ( BallBase * ball_type) const

Checks for collision between the power and the ball.

Parameters
ball_typeThe ball object
Returns
true if collision detected, false otherwise
Parameters
ball_typePointer to the ball object
Returns
true if collision detected, false otherwise

◆ render()

void Power::render ( SDL_Renderer * renderer)
virtual

Renders the power on screen.

Parameters
rendererSDL renderer for drawing

Draws a colored rectangle representing the power if it's active

Parameters
rendererSDL renderer for drawing

Reimplemented in InversiblePower, and InvisiblePower.

◆ reset()

void Power::reset ( int screen_width)
virtual

Resets the power-up to a new random position.

Resets the power to a new random position.

Parameters
screen_widthThe width of the game screen

Reimplemented in InversiblePower, and InvisiblePower.

◆ set_effect_is_active()

void Power::set_effect_is_active ( bool active)

◆ set_is_active()

void Power::set_is_active ( bool active)

Sets the active state of the power-up.

Parameters
activeThe new active state

◆ update()

void Power::update ( float time,
Paddle * racket1,
Paddle * racket2,
SDL_Renderer * renderer,
BallBase * ball )
virtual

Updates the power's position and effect.

Updates the power's position and checks for collision with the ball.

Virtual method that updates the game's parameters based on power effects

Parameters
timeTime delta since last update
racket1Pointer to first paddle
racket2Pointer to second paddle
ball_pos_xBall's X position
ball_pos_yBall's Y position
ball_radiusBall's radius
rendererSDL renderer for drawing

Handles power movement, collision detection, and effect application/duration

Parameters
timeTime delta since last update
racket1Pointer to first paddle
racket2Pointer to second paddle
ballThe ball object
rendererSDL renderer for drawing

Reimplemented in InversiblePower.

Member Data Documentation

◆ color

SDL_Color Power::color
protected

Color of the power-up

◆ duration_effect

float Power::duration_effect = 0.0f
protected

Time remaining until effect ends

◆ effect_is_active

bool Power::effect_is_active = false
protected

Whether the power's effect is currently active

◆ height

int Power::height
protected

Dimensions of the power-up

◆ is_active

bool Power::is_active = false
protected

Used to determine if the power is currently visible and active

◆ play

bool Power::play = true
protected

Flag to determine which player gets the effect. It is used only on power.cpp but not on the herited classes

◆ power_texture

SDL_Texture* Power::power_texture = nullptr
protected

Texture of the power-up as an image

◆ speed

float Power::speed
protected

Movement speed

◆ width

int Power::width
protected

◆ x

float Power::x = 0
protected

X position of the power-up

◆ y

float Power::y = 0
protected

Y position of the power-up


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