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 
17 #ifndef HEADER_SUPERTUX_OBJECT_BLOCK_HPP
18 #define HEADER_SUPERTUX_OBJECT_BLOCK_HPP
19 
20 #include "sprite/sprite.hpp"
21 #include "sprite/sprite_ptr.hpp"
22 #include "supertux/moving_object.hpp"
23 
24 class Player;
25 class ReaderMapping;
26 
27 class Block : public MovingObject
28 {
29   friend class FlipLevelTransformer;
30 
31 public:
32   Block(SpritePtr sprite);
33   Block(const ReaderMapping& mapping, const std::string& sprite_file);
34 
35   virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
36   virtual void update(float dt_sec) override;
37   virtual void draw(DrawingContext& context) override;
38 
get_default_sprite_name() const39   virtual std::string get_default_sprite_name() const { return m_default_sprite_name; }
40 
41   virtual ObjectSettings get_settings() override;
42   virtual void after_editor_set() override;
43 
44   virtual void on_flip(float height) override;
45 
get_layer() const46   virtual int get_layer() const override { return LAYER_OBJECTS + 1; }
47 
48 protected:
49   virtual void hit(Player& player) = 0;
50 
51   void start_bounce(GameObject* hitter);
52   void start_break(GameObject* hitter);
53   void break_me();
54 
55 protected:
56   SpritePtr m_sprite;
57   std::string m_sprite_name;
58   std::string m_default_sprite_name;
59   bool m_bouncing;
60   bool m_breaking;
61   float m_bounce_dir;
62   float m_bounce_offset;
63   float m_original_y;
64 
65 private:
66   Block(const Block&) = delete;
67   Block& operator=(const Block&) = delete;
68 };
69 
70 #endif
71 
72 /* EOF */
73