bonus_block.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // SuperTux
  2. // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
  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_BONUS_BLOCK_HPP
  17. #define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP
  18. #include "object/block.hpp"
  19. #include "supertux/direction.hpp"
  20. #include "supertux/player_status.hpp"
  21. class Player;
  22. class BonusBlock final : public Block
  23. {
  24. public:
  25. enum class Content {
  26. COIN,
  27. FIREGROW,
  28. ICEGROW,
  29. AIRGROW,
  30. EARTHGROW,
  31. RETROGROW,
  32. STAR,
  33. RETROSTAR,
  34. ONEUP,
  35. CUSTOM,
  36. SCRIPT,
  37. LIGHT,
  38. LIGHT_ON,
  39. TRAMPOLINE,
  40. PORTABLE_TRAMPOLINE,
  41. RAIN,
  42. EXPLODE,
  43. ROCK,
  44. POTION
  45. };
  46. public:
  47. BonusBlock(const Vector& pos, int tile_data);
  48. BonusBlock(const ReaderMapping& mapping);
  49. virtual void hit(Player& player) override;
  50. virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
  51. virtual void draw(DrawingContext& context) override;
  52. static std::string class_name() { return "bonusblock"; }
  53. virtual std::string get_class_name() const override { return class_name(); }
  54. static std::string display_name() { return _("Bonus Block"); }
  55. virtual std::string get_display_name() const override { return display_name(); }
  56. virtual ObjectSettings get_settings() override;
  57. GameObjectTypes get_types() const override;
  58. std::string get_default_sprite_name() const override;
  59. Content get_contents() const { return m_contents; }
  60. int get_hit_counter() const { return m_hit_counter; }
  61. void try_open(Player* player);
  62. private:
  63. void add_object(std::unique_ptr<GameObject> object);
  64. void set_object(std::unique_ptr<GameObject> object);
  65. void on_type_change(int old_type) override;
  66. int get_default_hit_counter() const;
  67. std::string get_default_coin_sprite() const;
  68. void try_drop(Player* player);
  69. void preload_contents(int d);
  70. void raise_growup_bonus(Player* player, const BonusType& bonus, const Direction& dir,
  71. const std::string& growup_sprite = "", const std::string& flower_sprite = "");
  72. void drop_growup_bonus(Player* player, int type, const Direction& dir, bool& countdown,
  73. const std::string& growup_sprite = "");
  74. BonusBlock::Content get_content_by_data(int tile_data) const;
  75. BonusBlock::Content get_content_from_string(const std::string& contentstring) const;
  76. private:
  77. enum Type {
  78. BLUE,
  79. ORANGE,
  80. PURPLE,
  81. RETRO
  82. };
  83. private:
  84. Content m_contents;
  85. /** As of now, BonusBlock only supports one custom object.
  86. This vector is needed for the object selection functionality in the editor.
  87. `m_object` points to the only object in the vector. */
  88. std::vector<std::unique_ptr<GameObject>> m_objects;
  89. GameObject* m_object;
  90. int m_hit_counter;
  91. std::string m_script;
  92. SurfacePtr m_lightsprite;
  93. std::string m_coin_sprite;
  94. private:
  95. BonusBlock(const BonusBlock&) = delete;
  96. BonusBlock& operator=(const BonusBlock&) = delete;
  97. };
  98. #endif
  99. /* EOF */