restore trunk
[supertux.git] / src / object / block.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef __BLOCK_H__
21 #define __BLOCK_H__
22
23 #include "moving_object.hpp"
24 #include "lisp/lisp.hpp"
25
26 class Sprite;
27 class Player;
28
29 class Block : public MovingObject
30 {
31 public:
32   Block(Sprite* sprite = 0);
33   ~Block();
34
35   virtual HitResponse collision(GameObject& other, const CollisionHit& hit);
36   virtual void update(float elapsed_time);
37   virtual void draw(DrawingContext& context);
38
39 protected:
40   friend class FlipLevelTransformer;
41
42   virtual void hit(Player& player) = 0;
43   void start_bounce();
44   void start_break();
45   void break_me();
46
47   Sprite* sprite;
48   bool bouncing;
49   bool breaking;
50   float bounce_dir;
51   float bounce_offset;
52   float original_y;
53
54 };
55
56 class BonusBlock : public Block
57 {
58 public:
59   BonusBlock(const Vector& pos, int data);
60   BonusBlock(const lisp::Lisp& lisp);
61   virtual ~BonusBlock();
62   HitResponse collision(GameObject& other, const CollisionHit& hit);
63
64   void try_open();
65
66   enum Contents {
67     CONTENT_COIN,
68     CONTENT_FIREGROW,
69     CONTENT_ICEGROW,
70     CONTENT_STAR,
71     CONTENT_1UP,
72     CONTENT_CUSTOM
73   };
74
75   Contents contents;
76 protected:
77   virtual void hit(Player& player);
78
79 private:
80   MovingObject* object;
81 };
82
83 class Brick : public Block
84 {
85 public:
86   Brick(const Vector& pos, int data);
87
88   void try_break(bool playerhit = false);
89   HitResponse collision(GameObject& other, const CollisionHit& hit);
90
91 protected:
92   virtual void hit(Player& player);
93
94 private:
95   bool breakable;
96   int coin_counter;
97 };
98
99 #endif