supertux
player_status.hpp
1 // SuperTux
2 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
3 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_SUPERTUX_PLAYER_STATUS_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_PLAYER_STATUS_HPP
20 
21 #include <algorithm>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 class DrawingContext;
27 class ReaderMapping;
28 class Writer;
29 
30 static const float BORDER_X = 10;
31 static const float BORDER_Y = 10;
32 
33 enum BonusType {
34  NO_BONUS = 0, GROWUP_BONUS, FIRE_BONUS, ICE_BONUS, AIR_BONUS, EARTH_BONUS
35 };
36 
39 class PlayerStatus final
40 {
41 public:
42  PlayerStatus(int num_players);
43  void reset(int num_players);
44  void add_coins(int count, bool play_sound = true);
45  void take_checkpoint_coins();
46 
47  void write(Writer& writer);
48  void read(const ReaderMapping& mapping);
49 
50  int get_max_coins() const;
51  bool can_reach_checkpoint() const;
52  bool respawns_at_checkpoint() const;
53  std::string get_bonus_prefix(int player_id) const;
54  bool has_hat_sprite(int player_id) const { return bonus[player_id] > GROWUP_BONUS; }
55 
56  void add_player();
57  void remove_player(int player_id);
58 
59 private:
60  void parse_bonus_mapping(const ReaderMapping& map, int id);
61 
62 public:
63  int m_num_players;
64 
65  int coins;
66  std::vector<BonusType> bonus;
67  std::vector<int> max_fire_bullets;
68  std::vector<int> max_ice_bullets;
69  std::vector<int> max_air_time;
70  std::vector<int> max_earth_time;
72  std::string worldmap_sprite;
73  std::string last_worldmap;
74  std::string title_level;
76 private:
77  PlayerStatus(const PlayerStatus&) = delete;
78  PlayerStatus& operator=(const PlayerStatus&) = delete;
79 };
80 
81 #endif
82 
83 /* EOF */
This class keeps player status between different game sessions (for example when switching maps in th...
Definition: player_status.hpp:39
std::string title_level
level to be used for the title screen, overrides the value of the same property for the world ...
Definition: player_status.hpp:74
bool has_hat_sprite(int player_id) const
Returns the prefix of the animations that should be displayed.
Definition: player_status.hpp:54
std::vector< int > max_earth_time
determines maximum number of seconds player can turn to stone
Definition: player_status.hpp:70
std::string last_worldmap
the last played worldmap
Definition: player_status.hpp:73
std::vector< int > max_air_time
determines maximum number of seconds player can float in air
Definition: player_status.hpp:69
std::string worldmap_sprite
the sprite of Tux that should be used in worldmap
Definition: player_status.hpp:72
std::vector< int > max_ice_bullets
maximum number of ice bullets in play
Definition: player_status.hpp:68
Definition: reader_mapping.hpp:32
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Definition: writer.cpp:23
std::vector< int > max_fire_bullets
maximum number of fire bullets in play
Definition: player_status.hpp:67