Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[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   Contents contents;
78 protected:
79   virtual void hit(Player& player);
80
81 private:
82   MovingObject* object;
83 };
84
85 class Brick : public Block
86 {
87 public:
88   Brick(const Vector& pos, int data);
89
90   void try_break(Player* player = false);
91   HitResponse collision(GameObject& other, const CollisionHit& hit);
92
93 protected:
94   virtual void hit(Player& player);
95
96 private:
97   bool breakable;
98   int coin_counter;
99 };
100
101 #endif
102
103 /* EOF */