coin.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_SUPERTUX_OBJECT_COIN_HPP
  17. #define HEADER_SUPERTUX_OBJECT_COIN_HPP
  18. #include "object/path_object.hpp"
  19. #include "object/moving_sprite.hpp"
  20. #include "supertux/physic.hpp"
  21. class Path;
  22. class PathWalker;
  23. class TileMap;
  24. class Coin : public MovingSprite,
  25. public PathObject
  26. {
  27. friend class HeavyCoin;
  28. public:
  29. Coin(const Vector& pos, bool count_stats = true,
  30. const std::string& sprite_path = "images/objects/coin/coin.sprite");
  31. Coin(const ReaderMapping& reader, bool count_stats = true);
  32. virtual void finish_construction() override;
  33. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  34. virtual void update(float dt_sec) override;
  35. static std::string class_name() { return "coin"; }
  36. virtual std::string get_class_name() const override { return class_name(); }
  37. static std::string display_name() { return _("Coin"); }
  38. virtual std::string get_display_name() const override { return display_name(); }
  39. virtual ObjectSettings get_settings() override;
  40. GameObjectTypes get_types() const override;
  41. std::string get_default_sprite_name() const override;
  42. virtual void after_editor_set() override;
  43. virtual void editor_update() override;
  44. void save_state() override;
  45. void check_state() override;
  46. virtual void move_to(const Vector& pos) override;
  47. virtual void on_flip(float height) override;
  48. void collect();
  49. private:
  50. enum Type {
  51. NORMAL,
  52. RETRO
  53. };
  54. private:
  55. Vector m_offset;
  56. bool m_from_tilemap;
  57. bool m_add_path;
  58. Physic m_physic;
  59. std::string m_collect_script;
  60. int m_starting_node;
  61. const bool m_count_stats;
  62. private:
  63. Coin(const Coin&) = delete;
  64. Coin& operator=(const Coin&) = delete;
  65. };
  66. class HeavyCoin final : public Coin
  67. {
  68. public:
  69. HeavyCoin(const Vector& pos, const Vector& init_velocity, bool count_stats = true,
  70. const std::string& sprite_path = "images/objects/coin/coin.sprite");
  71. HeavyCoin(const ReaderMapping& reader, bool count_stats = true);
  72. virtual void update(float dt_sec) override;
  73. virtual void collision_solid(const CollisionHit& hit) override;
  74. static std::string class_name() { return "heavycoin"; }
  75. virtual std::string get_class_name() const override { return class_name(); }
  76. static std::string display_name() { return _("Heavy Coin"); }
  77. virtual std::string get_display_name() const override { return display_name(); }
  78. virtual ObjectSettings get_settings() override;
  79. virtual void after_editor_set() override;
  80. virtual void on_flip(float height) override;
  81. private:
  82. Physic m_physic;
  83. CollisionHit m_last_hit;
  84. private:
  85. HeavyCoin(const HeavyCoin&) = delete;
  86. HeavyCoin& operator=(const HeavyCoin&) = delete;
  87. };
  88. #endif
  89. /* EOF */