The NEW Pong Game  V13.2.1
An interesting implemnettaion of the pong game
power.hpp
Go to the documentation of this file.
1 
8 #ifndef POWER_HPP
9 #define POWER_HPP
10 
11 #include <SDL.h>
12 #include <cstdlib>
13 #include <ctime>
14 
15 #include "paddle.hpp"
16 #include "macros.hpp"
17 #include "ball_base.hpp"
18 
26 class Power
27 {
28 public:
34  Power(int screen_width, int screen_height);
35 
49  virtual void update(float time, Paddle *racket1, Paddle *racket2, SDL_Renderer *renderer, BallBase *ball);
50 
55  virtual void render(SDL_Renderer *renderer);
56 
63  bool collision(BallBase *ball_type) const;
64 
69  virtual void reset(int screen_width);
70 
75  void set_is_active(bool active) { is_active = active; }
76 
81  void set_effect_is_active(bool active) { effect_is_active = active; }
82 
83 
84 protected:
85  float x = 0;
86  float y = 0;
87  bool play = true;
88  int width, height;
89  float speed;
90  float duration_effect = 0.0f;
91  bool effect_is_active = false;
92  SDL_Color color;
93  bool is_active = false;
94  SDL_Texture* power_texture = nullptr;
95 };
96 
97 #endif
Base class for all ball types in the game.
SDL_Renderer * renderer
Definition: ball_test.cpp:25
Abstract base class for all ball types in the game.
Definition: ball_base.hpp:23
Represents a player paddle/racket in the game.
Definition: paddle.hpp:20
Class representing power-up items that affect gameplay.
Definition: power.hpp:27
int height
Definition: power.hpp:88
bool effect_is_active
Definition: power.hpp:91
int width
Definition: power.hpp:88
virtual void update(float time, Paddle *racket1, Paddle *racket2, SDL_Renderer *renderer, BallBase *ball)
Updates the power's position and effect.
Definition: power.cpp:42
Power(int screen_width, int screen_height)
Constructor for the Power class.
Definition: power.cpp:21
float duration_effect
Definition: power.hpp:90
void set_effect_is_active(bool active)
Definition: power.hpp:81
virtual void reset(int screen_width)
Resets the power-up to a new random position.
Definition: power.cpp:174
float y
Definition: power.hpp:86
virtual void render(SDL_Renderer *renderer)
Renders the power on screen.
Definition: power.cpp:110
bool play
Definition: power.hpp:87
SDL_Texture * power_texture
Definition: power.hpp:94
void set_is_active(bool active)
Sets the active state of the power-up.
Definition: power.hpp:75
float speed
Definition: power.hpp:89
float x
Definition: power.hpp:85
SDL_Color color
Definition: power.hpp:92
bool collision(BallBase *ball_type) const
Checks for collision between the power and the ball.
Definition: power.cpp:153
bool is_active
Definition: power.hpp:93
Defines macros and constants used throughout the project.
Header defining the Paddle class for the game.