player_status.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #ifndef HEADER_SUPERTUX_SUPERTUX_PLAYER_STATUS_HPP
  18. #define HEADER_SUPERTUX_SUPERTUX_PLAYER_STATUS_HPP
  19. #include <algorithm>
  20. #include <memory>
  21. #include <string>
  22. #include <vector>
  23. class DrawingContext;
  24. class ReaderMapping;
  25. class Writer;
  26. static const float BORDER_X = 10;
  27. static const float BORDER_Y = 10;
  28. enum BonusType {
  29. NO_BONUS = 0, GROWUP_BONUS, FIRE_BONUS, ICE_BONUS, AIR_BONUS, EARTH_BONUS
  30. };
  31. /** This class keeps player status between different game sessions (for
  32. example when switching maps in the worldmap) */
  33. class PlayerStatus final
  34. {
  35. public:
  36. PlayerStatus(int num_players);
  37. void reset(int num_players);
  38. void add_coins(int count, bool play_sound = true);
  39. void take_checkpoint_coins();
  40. void write(Writer& writer);
  41. void read(const ReaderMapping& mapping);
  42. int get_max_coins() const;
  43. bool can_reach_checkpoint() const;
  44. bool respawns_at_checkpoint() const;
  45. std::string get_bonus_prefix(int player_id) const;/**Returns the prefix of the animations that should be displayed*/
  46. bool has_hat_sprite(int player_id) const { return bonus[player_id] > GROWUP_BONUS; }
  47. void add_player();
  48. void remove_player(int player_id);
  49. private:
  50. void parse_bonus_mapping(const ReaderMapping& map, int id);
  51. public:
  52. int m_num_players;
  53. int coins;
  54. std::vector<BonusType> bonus;
  55. std::vector<int> max_fire_bullets; /**< maximum number of fire bullets in play */
  56. std::vector<int> max_ice_bullets; /**< maximum number of ice bullets in play */
  57. std::vector<int> max_air_time; /**<determines maximum number of seconds player can float in air */
  58. std::vector<int> max_earth_time; /**< determines maximum number of seconds player can turn to stone */
  59. std::string worldmap_sprite; /**< the sprite of Tux that should be used in worldmap */
  60. std::string last_worldmap; /**< the last played worldmap */
  61. std::string title_level; /**< level to be used for the title screen, overrides the value of the same property for the world */
  62. private:
  63. PlayerStatus(const PlayerStatus&) = delete;
  64. PlayerStatus& operator=(const PlayerStatus&) = delete;
  65. };
  66. #endif
  67. /* EOF */