-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_sfml.h
130 lines (95 loc) · 3.18 KB
/
game_sfml.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef GAME_SFML_H
#define GAME_SFML_H
/// Functions and/or classes to display the 'game' class
/// using SFML
#include <SFML/Graphics.hpp>
#include <vector>
#include "bullet.h"
#include "game.h"
#include "player.h"
#include "program_state.h"
#include "sprites_sfml.h"
#include "winner_screen_sfml.h"
class game_sfml
{
public:
///Starts the music
///@param n_players the initial number of players suggested
game_sfml(
sf::RenderWindow& window,
game g,
Sprites_sfml& sprites
);
///Stops the music
~game_sfml();
///Runs the battle, which is handling input and displayal.
///Closes when the user wants to quit
///or continue to winner screen when a player has won.
///This can be done by using the get_state member function
void execute();
///Read the game logic
const auto& get_game() const noexcept { return m_game; }
auto& get_game() noexcept { return m_game; }
const Sprites_sfml get_sprites() const noexcept { return m_sprites; }
const sf::RenderWindow& get_window() const noexcept { return m_window; }
///Handle input and show this screen once, to be used in testing only
void tick();
private:
///The logic behind the battle
game m_game;
///The range in which a player can be hit by a bullet
std::vector<sf::CircleShape> m_hit_ranges;
///Life bars of all players
std::vector<sf::RectangleShape> m_life_bars;
///Music played, starts at constructor, ends at destructor
sf::Music m_music;
///The sprites, cannot be const as the sprites are modified in-place
Sprites_sfml& m_sprites;
///Window used for displayal
sf::RenderWindow& m_window;
///Check if one of the players is hit by a bullet
void resize_life_bars();
///Show this menu on the screen
void display();
///Process a single event
void process_event(sf::Event event);
};
std::vector<double> collect_hit_points(const game_sfml& g);
void draw_game_components(
sf::RenderWindow &w,
std::vector<sf::RectangleShape> life_bars,
std::vector<sf::CircleShape> hit_ranges,
std::vector<bullet> bullets
);
const game& get_game(const game_sfml& g);
const std::vector<bullet>& get_bullets(const game_sfml& g);
std::vector<bullet>& get_bullets(game_sfml& g);
bool get_is_profile_run(const game_sfml& g);
std::vector<sf::Vector2f> get_life_bar_positions();
const std::vector<player>& get_players(const game_sfml& g);
std::vector<player>& get_players(game_sfml& g);
const Sprites_sfml get_sprites(const game_sfml& g);
std::vector<sf::Vector2f> get_start_positions();
program_state get_state(const game_sfml& g);
const sf::RenderWindow& get_window(const game_sfml& g);
///Get the winner. Returns
/// * -1: everyone died
/// * 0: at least two players are alive
/// * 1: player 1 has won
/// * 2: player 2 has won
/// * 3: player 3 has won
/// * 4: player 4 has won
int get_winner(const game_sfml& g);
void process_event_game(
sf::Event event,
std::vector<bullet> &bullets
);
std::vector<sf::CircleShape> set_hit_ranges(
std::vector<player> ps,
std::vector<sf::Vector2f> start_positions);
std::vector<sf::RectangleShape> set_life_bars(
int player_amount,
std::vector<sf::Vector2f> life_bar_positions
);
void set_state(game_sfml& g, program_state p);
#endif // GAME_SFML_H