1// SuperTux - PneumaticPlatform
2// Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.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
17#ifndef HEADER_SUPERTUX_OBJECT_PNEUMATIC_PLATFORM_HPP
18#define HEADER_SUPERTUX_OBJECT_PNEUMATIC_PLATFORM_HPP
19
20#include "object/moving_sprite.hpp"
21
22class PneumaticPlatform;
23
24class PneumaticPlatformChild final : public MovingSprite
25{
26 friend class PneumaticPlatform;
27
28public:
29 PneumaticPlatformChild(const ReaderMapping& reader, bool left, PneumaticPlatform& parent);
30 virtual ~PneumaticPlatformChild();
31
32 virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
33 virtual void update(float dt_sec) override;
34 virtual bool is_saveable() const override { return false; }
35
36 virtual void editor_delete() override;
37
38protected:
39 PneumaticPlatform& m_parent;
40 bool m_left;
41 std::set<GameObject*> m_contacts; /**< objects that are currently pushing on the platform */
42
43private:
44 PneumaticPlatformChild(const PneumaticPlatformChild&) = delete;
45 PneumaticPlatformChild& operator=(const PneumaticPlatformChild&) = delete;
46};
47
48/** Used to construct a pair of pneumatic platforms: If one is pushed
49 down, the other one rises */
50class PneumaticPlatform final : public GameObject
51{
52 friend class PneumaticPlatformChild;
53
54public:
55 PneumaticPlatform(const ReaderMapping& mapping);
56 virtual ~PneumaticPlatform();
57
58 virtual void draw(DrawingContext& context) override;
59 virtual void update(float dt_sec) override;
60
61 virtual std::string get_class() const override { return "pneumatic-platform"; }
62 virtual std::string get_display_name() const override { return _("Pneumatic Platform"); }
63
64 virtual ObjectSettings get_settings() override;
65 virtual void after_editor_set() override;
66 virtual void editor_delete() override;
67
68private:
69 Vector m_pos;
70 std::string m_sprite_name;
71 float m_start_y; /**< vertical start position */
72 float m_speed_y; /**< vertical speed */
73 float m_offset_y; /**< vertical offset from the start position in px */
74 std::vector<PneumaticPlatformChild*> m_children;
75
76private:
77 PneumaticPlatform(const PneumaticPlatform&) = delete;
78 PneumaticPlatform& operator=(const PneumaticPlatform&) = delete;
79};
80
81#endif
82
83/* EOF */
84