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
17#ifndef HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP
18#define HEADER_SUPERTUX_OBJECT_BONUS_BLOCK_HPP
19
20#include "object/block.hpp"
21#include "supertux/direction.hpp"
22#include "supertux/player_status.hpp"
23
24class Player;
25
26class BonusBlock final : public Block
27{
28public:
29 enum class Content {
30 COIN,
31 FIREGROW,
32 ICEGROW,
33 AIRGROW,
34 EARTHGROW,
35 STAR,
36 ONEUP,
37 CUSTOM,
38 SCRIPT,
39 LIGHT,
40 TRAMPOLINE,
41 RAIN,
42 EXPLODE
43 };
44
45public:
46 BonusBlock(const Vector& pos, int tile_data);
47 BonusBlock(const ReaderMapping& mapping);
48 virtual ~BonusBlock();
49
50 virtual void hit(Player& player) override;
51 virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
52 virtual void draw(DrawingContext& context) override;
53
54 virtual std::string get_class() const override { return "bonusblock"; }
55 virtual std::string get_display_name() const override { return _("Bonus Block"); }
56
57 virtual ObjectSettings get_settings() override;
58
59 Content get_contents() const { return m_contents; }
60 int get_hit_counter() const { return m_hit_counter; }
61
62private:
63 void try_open(Player* player);
64 void try_drop(Player* player);
65
66 void preload_contents(int d);
67 void raise_growup_bonus(Player* player, const BonusType& bonus, const Direction& dir);
68 void drop_growup_bonus(const std::string& bonus_sprite_name, bool& countdown);
69
70 BonusBlock::Content get_content_by_data(int tile_data) const;
71 BonusBlock::Content get_content_from_string(const std::string& contentstring) const;
72 std::string contents_to_string(const BonusBlock::Content& content) const;
73
74private:
75 Content m_contents;
76 std::unique_ptr<MovingObject> m_object;
77 int m_hit_counter;
78 std::string m_script;
79 SurfacePtr m_lightsprite;
80 sexp::Value m_custom_sx;
81
82private:
83 BonusBlock(const BonusBlock&) = delete;
84 BonusBlock& operator=(const BonusBlock&) = delete;
85};
86
87#endif
88
89/* EOF */
90