d31ba4d8c3606edd1d5ab3c7c35c83e750e76bc7
[supertux.git] / src / object / block.hpp
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 <memory>
21
22 #include "supertux/moving_object.hpp"
23 #include "util/reader_fwd.hpp"
24
25 class Sprite;
26 class Player;
27
28 class Block : public MovingObject
29 {
30 public:
31   Block(std::auto_ptr<Sprite> sprite);
32   ~Block();
33
34   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
35   virtual void update(float elapsed_time);
36   virtual void draw(DrawingContext& context);
37
38 protected:
39   friend class FlipLevelTransformer;
40
41   virtual void hit(Player& player) = 0;
42   void start_bounce(GameObject* hitter);
43   void start_break(GameObject* hitter);
44   void break_me();
45
46   std::auto_ptr<Sprite> sprite;
47   bool bouncing;
48   bool breaking;
49   float bounce_dir;
50   float bounce_offset;
51   float original_y;
52
53 private:
54   Block(const Block&);
55   Block& operator=(const Block&);
56 };
57
58 class BonusBlock : public Block
59 {
60 public:
61   BonusBlock(const Vector& pos, int data);
62   BonusBlock(const Reader& lisp);
63   virtual ~BonusBlock();
64   HitResponse collision(GameObject& other, const CollisionHit& hit);
65
66   void try_open();
67
68   enum Contents {
69     CONTENT_COIN,
70     CONTENT_FIREGROW,
71     CONTENT_ICEGROW,
72     CONTENT_STAR,
73     CONTENT_1UP,
74     CONTENT_CUSTOM
75   };
76
77 protected:
78   virtual void hit(Player& player);
79
80 public:
81   Contents contents;
82   MovingObject* object;
83
84 private:
85   BonusBlock(const BonusBlock&);
86   BonusBlock& operator=(const BonusBlock&);
87 };
88
89 class Brick : public Block
90 {
91 public:
92   Brick(const Vector& pos, int data);
93
94   void try_break(Player* player = false);
95   HitResponse collision(GameObject& other, const CollisionHit& hit);
96
97 protected:
98   virtual void hit(Player& player);
99
100 private:
101   bool breakable;
102   int coin_counter;
103 };
104
105 #endif
106
107 /* EOF */