fix cr/lfs and remove trailing whitespaces...
[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   HitResponse collision(GameObject& other, const CollisionHit& hit);
60
61   void try_open();
62
63 protected:
64   virtual void hit(Player& player);
65
66 private:
67   enum Contents {
68     CONTENT_COIN,
69     CONTENT_FIREGROW,
70     CONTENT_ICEGROW,
71     CONTENT_STAR,
72     CONTENT_1UP,
73     CONTENT_CUSTOM
74   };
75
76   Contents contents;
77   MovingObject* object;
78 };
79
80 class Brick : public Block
81 {
82 public:
83   Brick(const Vector& pos, int data);
84
85   void try_break(bool playerhit = false);
86   HitResponse collision(GameObject& other, const CollisionHit& hit);
87
88 protected:
89   virtual void hit(Player& player);
90
91 private:
92   bool breakable;
93   int coin_counter;
94 };
95
96 #endif