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 <memory>
22 #include <string>
23 #include <algorithm>
24 
25 class DrawingContext;
26 class ReaderMapping;
27 class Writer;
28 
29 static const float BORDER_X = 10;
30 static const float BORDER_Y = 10;
31 
32 enum BonusType {
33  NO_BONUS = 0, GROWUP_BONUS, FIRE_BONUS, ICE_BONUS, AIR_BONUS, EARTH_BONUS
34 };
35 
38 class PlayerStatus final
39 {
40 public:
41  PlayerStatus();
42  void reset();
43  void add_coins(int count, bool play_sound = true);
44  void take_checkpoint_coins() { coins -= std::max(coins / 10, 25); }
45 
46  void write(Writer& writer);
47  void read(const ReaderMapping& mapping);
48 
49  int get_max_coins() const;
50  bool can_reach_checkpoint() const;
51  std::string get_bonus_prefix() const;
52  bool has_hat_sprite() const { return bonus > GROWUP_BONUS; }
53 
54 public:
55  int coins;
56  BonusType bonus;
62  std::string worldmap_sprite;
63  std::string last_worldmap;
65 private:
66  PlayerStatus(const PlayerStatus&) = delete;
67  PlayerStatus& operator=(const PlayerStatus&) = delete;
68 };
69 
70 #endif
71 
72 /* EOF */
This class keeps player status between different game sessions (for example when switching maps in th...
Definition: player_status.hpp:38
bool has_hat_sprite() const
Returns the prefix of the animations that should be displayed.
Definition: player_status.hpp:52
Definition: writer.hpp:27
std::string last_worldmap
the last played worldmap
Definition: player_status.hpp:63
std::string worldmap_sprite
the sprite of Tux that should be used in worldmap
Definition: player_status.hpp:62
int max_fire_bullets
maximum number of fire bullets in play
Definition: player_status.hpp:57
int max_earth_time
determines maximum number of seconds player can turn to stone
Definition: player_status.hpp:60
Definition: reader_mapping.hpp:31
int max_air_time
determines maximum number of seconds player can float in air
Definition: player_status.hpp:59
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
int max_ice_bullets
maximum number of ice bullets in play
Definition: player_status.hpp:58