fix cr/lfs and remove trailing whitespaces...
[supertux.git] / src / object / invisible_block.cpp
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 #include <config.h>
21
22 #include "invisible_block.hpp"
23 #include "resources.hpp"
24 #include "sprite/sprite.hpp"
25 #include "sprite/sprite_manager.hpp"
26 #include "video/drawing_context.hpp"
27 #include "audio/sound_manager.hpp"
28 #include "object_factory.hpp"
29 #include "object/player.hpp"
30
31 InvisibleBlock::InvisibleBlock(const Vector& pos)
32   : Block(sprite_manager->create("images/objects/bonus_block/invisibleblock.sprite")), visible(false)
33 {
34   bbox.set_pos(pos);
35   sound_manager->preload("sounds/brick.wav");
36   sound_manager->preload("sounds/brick.wav");
37 }
38
39 void
40 InvisibleBlock::draw(DrawingContext& context)
41 {
42   if(visible)
43     sprite->draw(context, get_pos(), LAYER_OBJECTS);
44 }
45
46 HitResponse
47 InvisibleBlock::collision(GameObject& other, const CollisionHit& hit)
48 {
49   if(!visible) {
50     Player* player = dynamic_cast<Player*> (&other);
51     if(player) {
52       if(player->get_movement().y > 0 ||
53           player->get_bbox().get_top() <= get_bbox().get_bottom() - 7.0) {
54         return PASSTHROUGH;
55       }
56     }
57   }
58
59   return Block::collision(other, hit);
60 }
61
62 void
63 InvisibleBlock::hit(Player& )
64 {
65   sound_manager->play("sounds/brick.wav");
66
67   if(visible)
68     return;
69
70   sprite->set_action("empty");
71   start_bounce();
72   flags |= FLAG_SOLID;
73   set_group(COLGROUP_STATIC);
74   visible = true;
75 }
76
77 //IMPLEMENT_FACTORY(InvisibleBlock, "invisible_block");