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

Power-up that inverts paddle controls temporarily. More...

#include <inverse_power.hpp>

+ Inheritance diagram for InversiblePower:

Public Member Functions

 InversiblePower (int screen_width, int screen_height)
 Constructor for InversiblePower.
 
void render (SDL_Renderer *renderer) override
 Renders the power-up on screen.
 
void reset (int screen_width) override
 Resets the power-up position.
 
void update (float time, Paddle *racket1, Paddle *racket2, SDL_Renderer *renderer, BallBase *ball) override
 Updates the power-up state.
 
- Public Member Functions inherited from Power
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.
 
void set_effect_is_active (bool active)
 
void set_is_active (bool active)
 Sets the active state of the power-up.
 

Private Attributes

bool inverse_paddle = false
 
float repeat
 

Additional Inherited Members

- Protected Attributes inherited from Power
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

Power-up that inverts paddle controls temporarily.

This power-up appears as an arrow on screen. When a player hits it with the ball, that player's paddle controls are inverted (up becomes down and vice versa) for a short period of time.

Constructor & Destructor Documentation

◆ InversiblePower()

InversiblePower::InversiblePower ( int screen_width,
int screen_height )

Constructor for InversiblePower.

Constructs an InversiblePower object.

Parameters
screen_widthWidth of the game screen
screen_heightHeight of the game screen
screen_widthWidth of the game screen
screen_heightHeight of the game screen

Initializes the power-up and sets it to active state.

Member Function Documentation

◆ render()

void InversiblePower::render ( SDL_Renderer * renderer)
overridevirtual

Renders the power-up on screen.

Renders the power-up on screen as an arrow.

Parameters
rendererSDL renderer to draw the power-up

Draws the power-up as a red arrow pointing downward when active. The arrow indicates that this power-up has a negative effect.

Parameters
rendererSDL renderer to draw the power-up

Reimplemented from Power.

◆ reset()

void InversiblePower::reset ( int screen_width)
overridevirtual

Resets the power-up position.

Resets the power-up to a new random position.

Parameters
screen_widthWidth of the game screen for positioning

Places the power-up at a random horizontal position at the top of the screen and assigns it a random color.

Parameters
screen_widthWidth of the game screen for positioning

Reimplemented from Power.

◆ update()

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

Updates the power-up state.

Updates the power-up's state based on game events.

Parameters
timeDelta time since last update
racket1Pointer to the first paddle
racket2Pointer to the second paddle
rendererSDL renderer to draw effects
ballPointer to the game ball

Handles the power-up movement, collision detection with the ball, activation of control inversion effect, and timing for effect duration. When the ball collides with this power-up, the controls for the player who last hit the ball are inverted for 3 seconds.

Parameters
timeDelta time since last frame
racket1First player's paddle
racket2Second player's paddle
rendererSDL renderer (unused in this method)
ballThe game ball for collision detection

Reimplemented from Power.

Member Data Documentation

◆ inverse_paddle

bool InversiblePower::inverse_paddle = false
private

Whether the power is currently active for a specific paddle

◆ repeat

float InversiblePower::repeat
private

Timer for power-up respawn


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