FlipLevelTransformer takes care of (Bonus)Blocks that move
[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
45   Sprite* sprite;
46   bool bouncing;
47   float bounce_dir;
48   float bounce_offset;
49   float original_y;
50
51 };
52
53 class BonusBlock : public Block
54 {
55 public:
56   BonusBlock(const Vector& pos, int data);
57   BonusBlock(const lisp::Lisp& lisp);
58   virtual ~BonusBlock();
59
60   void try_open();
61
62 protected:
63   virtual void hit(Player& player);
64
65 private:
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   MovingObject* object;
77 };
78
79 class Brick : public Block
80 {
81 public:
82   Brick(const Vector& pos, int data);
83
84   void try_break(bool playerhit = false);
85
86 protected:
87   virtual void hit(Player& player);
88
89 private:
90   bool breakable;
91   int coin_counter;
92 };
93
94 #endif
95