The NEW Pong Game  V13.2.1
An interesting implemnettaion of the pong game
game.hpp
Go to the documentation of this file.
1 // #############################################################################
2 // # File game.hpp
3 // # Project in C++ - Polytech Sorbonne - 2024/2025 - S8
4 // # Authors: Yanis Sadoun, Vasileios Filippos Skarleas, Dounia Bakalem - All rights reserved.
5 // #############################################################################
6 
7 #ifndef GAME_HPP
8 #define GAME_HPP
9 
10 #include <SDL.h>
11 #include <SDL_ttf.h>
12 #include <SDL_mixer.h>
13 
14 #include "paddle.hpp"
15 #include "ball_base.hpp"
16 
17 #include "page_3b.hpp"
18 #include "page_3b_0t.hpp"
19 #include "page_3b_1t.hpp"
20 #include "page_4b_1t.hpp"
21 #include "page_2b_1t.hpp"
22 
23 #include "game_over.hpp"
24 
25 #include "ai.hpp"
26 #include "user.hpp"
27 #include "network.hpp"
28 
29 #include "power.hpp"
30 #include "invisible_power.hpp"
31 #include "inverse_power.hpp"
32 
33 #include "gui.hpp"
34 #include "letter.hpp"
35 
36 enum class game_state
37 {
39  Menu,
41  Choose_Mode, // this is used as our main menu where players can choose what they want to do
42  AI_playing,
46  Playing, // playing classic with two players (first implementation with high score [the goal])
47  Paused,
48  GameOver,
49  Set_up
50 };
51 
52 class Game
53 {
54 public:
55  Game();
56  ~Game();
57  bool initialise();
58  void loop();
59  void close();
60 
61  static Mix_Chunk *racket_hit_sound;
62  static Mix_Chunk *mWallHitSound;
63  static Mix_Chunk *mScoreSound;
64 
65 private:
66  void game_logic();
67  void game();
68  void output();
69  void ball_creation(int type);
71 
72  // SDL objects for the game window and renderer
73  SDL_Window *mWindow;
74  SDL_Renderer *renderer;
75 
76  // Game loop variable allowing to control either if we stay on the modes loop or not
77  bool mIsRunning;
78 
79  // This is used to track the time since the last frame was drawn
80  /* We need that to calculate velocities and position */
81  Uint32 mTicksCount;
82 
83  // Every game needs two paddles and one ball as expected
87 
88  AI *mAI; // the AI player
89 
90  // The scores of the two players
91  // int mScore1;
92  // int mScore2;
93 
94  // The font used on the whole game
95  TTF_Font *police;
96 
97  // Adding the different page structures on the app
103 
104  // Network game
105  NetworkManager *network; // NOT USED YET
107 
108  GameOver *mGameOver; // This is used when the game is over
109 
110  // This allows us to control on which state we are and make the appropriate UI and action decisons
112 
113  // For the background music
114  Mix_Music *mBackgroundMusic;
115  Mix_Chunk *mNewRoundSound;
116  Mix_Chunk *mGameOverSound;
117  Mix_Music *mPauseMusic;
118  Mix_Music *mOnHoldMusic;
119 
120  // Background color for the two sides
123 
124  // The pause button object declared here
126  bool pause_button();
127 
130  std::string winner; // To store winner's name
131 
133  char last_highscore_name[20]; // To store the name of the last high score player
134 
139 };
140 
141 #endif
Header defining the AI class for computer-controlled paddle.
Base class for all ball types in the game.
Artificial Intelligence for controlling a paddle.
Definition: ai.hpp:22
Abstract base class for all ball types in the game.
Definition: ball_base.hpp:23
Definition: game_over.hpp:24
Definition: game.hpp:53
InversiblePower * minverse
Definition: game.hpp:138
TTF_Font * police
Definition: game.hpp:95
void ball_creation(int type)
Definition: game.cpp:1333
GameOver * mGameOver
Definition: game.hpp:108
Mix_Music * mOnHoldMusic
Definition: game.hpp:118
game_state mGameState
Definition: game.hpp:111
bool is_network_game
Definition: game.hpp:106
static Mix_Chunk * mScoreSound
Definition: game.hpp:63
page_3b_0t * mMenu
Definition: game.hpp:99
bool mIsRunning
Definition: game.hpp:77
SDL_Rect mPauseButtonRect
Definition: game.hpp:125
int last_highscore
Definition: game.hpp:132
Mix_Chunk * mNewRoundSound
Definition: game.hpp:115
AI * mAI
Definition: game.hpp:88
page_3b * mPauseMenu
Definition: game.hpp:100
Paddle * racket2
Definition: game.hpp:85
Uint32 mTicksCount
Definition: game.hpp:81
SDL_Color background_color_left
Definition: game.hpp:121
InvisiblePower * minvisible
Definition: game.hpp:137
SDL_Color background_color_right
Definition: game.hpp:122
Letter * mletter
Definition: game.hpp:135
void loop()
Definition: game.cpp:435
Mix_Music * mPauseMusic
Definition: game.hpp:117
bool pause_button()
Definition: game.cpp:228
bool initialise()
Definition: game.cpp:258
BallBase * mBall
Definition: game.hpp:86
Paddle * racket1
Definition: game.hpp:84
void game_logic()
Definition: game.cpp:445
User * player1
Definition: game.hpp:128
static Mix_Chunk * mWallHitSound
Definition: game.hpp:62
page_4b_1t * mModeMenu
Definition: game.hpp:102
void update_background_color()
Definition: game.cpp:1150
User * player2
Definition: game.hpp:129
void output()
Definition: game.cpp:1197
void game()
Definition: game.cpp:975
SDL_Window * mWindow
Definition: game.hpp:73
void close()
Definition: game.cpp:1354
Game()
Definition: game.cpp:23
page_3b_1t * mMiddleMenu
Definition: game.hpp:101
~Game()
Definition: game.cpp:74
SDL_Renderer * renderer
Definition: game.hpp:74
Mix_Chunk * mGameOverSound
Definition: game.hpp:116
page_2b_1t * mNoticeMenu
Definition: game.hpp:98
Mix_Music * mBackgroundMusic
Definition: game.hpp:114
std::string winner
Definition: game.hpp:130
char last_highscore_name[20]
Definition: game.hpp:133
NetworkManager * network
Definition: game.hpp:105
static Mix_Chunk * racket_hit_sound
Definition: game.hpp:61
Power * mpower
Definition: game.hpp:136
Power-up that inverts paddle controls temporarily.
Definition: inverse_power.hpp:22
Power-up that makes the ball temporarily invisible.
Definition: invisible_power.hpp:27
Represents a letter in the storytime game mode.
Definition: letter.hpp:28
Definition: network.hpp:13
Represents a player paddle/racket in the game.
Definition: paddle.hpp:20
Class representing power-up items that affect gameplay.
Definition: power.hpp:27
Represents a player in the game with name and score tracking.
Definition: user.hpp:23
Notice screen with 2 buttons and 1 title.
Definition: page_2b_1t.hpp:23
Main menu class with 3 buttons and no title.
Definition: page_3b_0t.hpp:28
Middle menu class with 3 buttons and 1 title.
Definition: page_3b_1t.hpp:26
Pause menu with 3 buttons.
Definition: page_3b.hpp:23
Defines the mode selection menu with 4 buttons and 1 title.
Definition: page_4b_1t.hpp:24
game_state
Definition: game.hpp:37
Header defining the game_over screen class.
Header defining the GUI utility class for game interface.
Implementation of the InversiblePower class.
Header defining the InvisiblePower class for ball visibility effects.
Header defining the Letter class for story mode.
Header defining the Paddle class for the game.
Header defining the notice screen page_2b_1t class.
Header defining the pause menu page_3b class.
Header defining the main menu class with 3 buttons and no title of the page_3b_0t class.
Header defining the middle menu class with 3 buttons and 1 title of page_3b_1t class.
Header defining the mode selection menu page_4b_1t class.
Header defining the Power class for special game effects.
Header defining the User class for player management.