Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / object / invisible_block.cpp
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 #include "audio/sound_manager.hpp"
18 #include "object/invisible_block.hpp"
19 #include "object/player.hpp"
20 #include "sprite/sprite.hpp"
21 #include "sprite/sprite_manager.hpp"
22 #include "supertux/constants.hpp"
23
24 InvisibleBlock::InvisibleBlock(const Vector& pos) :
25    Block(sprite_manager->create("images/objects/bonus_block/invisibleblock.sprite")), 
26    visible(false)
27 {
28   bbox.set_pos(pos);
29   sound_manager->preload("sounds/brick.wav");
30 }
31
32 void
33 InvisibleBlock::draw(DrawingContext& context)
34 {
35   if(visible)
36     sprite->draw(context, get_pos(), LAYER_OBJECTS);
37 }
38
39 bool
40 InvisibleBlock::collides(GameObject& other, const CollisionHit& )
41 {
42   if(visible)
43     return true;
44
45   // if we're not visible, only register a collision if this will make us visible
46   Player* player = dynamic_cast<Player*> (&other);
47   if ((player) 
48       && (player->get_movement().y <= 0)
49       && (player->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA)) {
50     return true;
51   }
52
53   return false;
54 }
55
56 HitResponse
57 InvisibleBlock::collision(GameObject& other, const CollisionHit& hit)
58 {
59   return Block::collision(other, hit);
60 }
61
62 void
63 InvisibleBlock::hit(Player& player)
64 {
65   sound_manager->play("sounds/brick.wav");
66
67   if(visible)
68     return;
69
70   sprite->set_action("empty");
71   start_bounce(&player);
72   set_group(COLGROUP_STATIC);
73   visible = true;
74 }
75
76 //IMPLEMENT_FACTORY(InvisibleBlock, "invisible_block");
77
78 /* EOF */