HeadBall  1.0
A game
GameState.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <SFML/Graphics.hpp>
4 #include <box2d/box2d.h>
5 #include <memory>
6 
7 #include "State.hpp"
8 #include "Game.hpp"
9 #include "TimeManager.hpp"
10 #include "Ground.hpp"
11 #include "Ball.hpp"
12 #include "Uphill.hpp"
13 #include "Wall.hpp"
14 #include "Definition.hpp"
15 #include "GoalPost.hpp"
16 #include "Player.hpp"
17 
18 namespace HeadBall {
24  class GameState : public State {
25  public:
33  GameState (GameDataRef data, ScoreTimeRef scoretime, bool is2ndHalf = false);
34 
39  void init ( );
40 
45  void handleInput ( );
46 
51  void update ( );
52 
57  void draw ( );
58 
63  void pause ( );
64 
69  void resume ( );
70 
76  void animate (std::string player);
77 
83  void kick (std::string player);
84 
85 
86  private:
88 
91 
92  WorldRef _world = std::make_shared <b2World> (b2Vec2(WORLD_GRAVITY_X, WORLD_GRAVITY_Y));
93 
98 
100 
102 
103  bool _isPaused;
105 
106  sf::Sprite _pauseBtn;
107 
108  sf::Music _crowdCheerSfx;
109  sf::Sound _btnClickSfx;
110  sf::Sound _longWhistleSfx;
111  sf::Sound _shortWhistleSfx;
112  sf::Sound _playerKickSfx;
113 
116 
117  };
118 }
#define WORLD_GRAVITY_X
Definition: Definition.hpp:14
#define WORLD_GRAVITY_Y
Definition: Definition.hpp:15
Class for shape and movement of ball.
Definition: Ball.hpp:10
Derived class of State class with visibility mode public that includes main gameplay.
Definition: GameState.hpp:24
Wall _wall
The Wall objects.
Definition: GameState.hpp:96
GoalPost _rightPost
The GoalPost objects.
Definition: GameState.hpp:97
sf::Text _p2Score
The SFML text of Score and Time.
Definition: GameState.hpp:89
Player _p1
Definition: GameState.hpp:99
void kick(std::string player)
Kicks the ball when called by the player.
Definition: GameState.cpp:321
GameState(GameDataRef data, ScoreTimeRef scoretime, bool is2ndHalf=false)
Construct a new Game State object.
Definition: GameState.cpp:12
GameDataRef _data
The shared pointer of GameData.
Definition: GameState.hpp:87
void handleInput()
Handles all the inputs of Game State.
Definition: GameState.cpp:132
ScoreTimeRef _scoreTime
The shared pointer of ScoreTimeData.
Definition: GameState.hpp:90
WorldRef _world
The shared pointer of Box2d world.
Definition: GameState.hpp:92
bool _isPaused
The boolean variable to if the game is paused.
Definition: GameState.hpp:103
sf::Sound _playerKickSfx
Sound effect to play when the ball is kicked.
Definition: GameState.hpp:112
UpHill _rightUpHill
The Uphill objects.
Definition: GameState.hpp:95
void pause()
Pauses the game.
Definition: GameState.cpp:265
sf::Sprite _pauseBtn
Sprite for pause button.
Definition: GameState.hpp:106
void draw()
Draws all the SFML object in the rendering window.
Definition: GameState.cpp:246
bool _isSecondHalf
The boolean variable to check if the state is second half or not.
Definition: GameState.hpp:104
void update()
Updates the rendering window according to the provided input.
Definition: GameState.cpp:198
UpHill _leftUpHill
Definition: GameState.hpp:95
sf::Text _timeText
Definition: GameState.hpp:89
int _p2MoveCounter
The int variable to count Player2 movement.
Definition: GameState.hpp:115
int _p1MoveCounter
The int variable to count Player1 movement.
Definition: GameState.hpp:114
sf::Text _p1Score
Definition: GameState.hpp:89
GoalPost _leftPost
Definition: GameState.hpp:97
Ball _ball
The Ball objects.
Definition: GameState.hpp:101
sf::Sound _longWhistleSfx
Sound effect to play at the end of each half.
Definition: GameState.hpp:110
void resume()
Resumes the game.
Definition: GameState.cpp:270
sf::Sound _shortWhistleSfx
Sound effect to play at the start of every half and after every goal.
Definition: GameState.hpp:111
sf::Sound _btnClickSfx
Sound effect for button click.
Definition: GameState.hpp:109
void init()
Initialize a new GameSate Object.
Definition: GameState.cpp:16
sf::Music _crowdCheerSfx
Crowd cheer sound.
Definition: GameState.hpp:108
Ground _ground
The Ground object.
Definition: GameState.hpp:94
Player _p2
The Player objects.
Definition: GameState.hpp:99
The Goalpost to be displayed in GameState.
Definition: GoalPost.hpp:9
Class for defining the ground in the game world.
Definition: Ground.hpp:10
Class for shape and movement of player.
Definition: Player.hpp:9
Abstract based class which inherits all the states of the game.
Definition: State.hpp:8
virtual void animate()
Vitrual function for performing animations.
Definition: State.hpp:50
The Uphill part of the game field, below the goal post and above the ground.
Definition: Uphill.hpp:9
Class for invisible wall around the field and above the goalpost.
Definition: Wall.hpp:10
Custom namespace used throughout the project.
Definition: AboutState.cpp:6
std::shared_ptr< b2World > WorldRef
The Shared Pointer that points to the Box2D world.
Definition: Game.hpp:51
std::shared_ptr< ScoreTimeData > ScoreTimeRef
The Shared Pointer of ScoreTimeData struct.
Definition: Game.hpp:45
std::shared_ptr< GameData > GameDataRef
The Shared Pointer of GameData Struct.
Definition: Game.hpp:39