Bug 474: Flip bonus-block flowers and partial-size tilemaps properly.
[supertux.git] / src / object / flower.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/flower.hpp"
19 #include "object/player.hpp"
20 #include "sprite/sprite_manager.hpp"
21
22 Flower::Flower(BonusType _type) :
23   type(_type),
24   sprite(),
25   drawing_effect(NO_EFFECT)
26 {
27   bbox.set_size(32, 32);
28
29   if(type == FIRE_BONUS) {
30     sprite = sprite_manager->create("images/powerups/fireflower/fireflower.sprite");
31     sound_manager->preload("sounds/fire-flower.wav");
32   }
33   else if(type == ICE_BONUS) {
34     sprite = sprite_manager->create("images/powerups/iceflower/iceflower.sprite");
35     sound_manager->preload("sounds/fire-flower.wav");
36   } else {
37     assert(false);
38   }
39
40   set_group(COLGROUP_TOUCHABLE);
41 }
42
43 Flower::~Flower()
44 {
45 }
46
47 void
48 Flower::update(float )
49 {
50 }
51
52 void
53 Flower::draw(DrawingContext& context)
54 {
55   sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect);
56 }
57
58 HitResponse
59 Flower::collision(GameObject& other, const CollisionHit& )
60 {
61   Player* player = dynamic_cast<Player*>(&other);
62   if(!player)
63     return ABORT_MOVE;
64
65   if(!player->add_bonus(type, true))
66     return FORCE_MOVE;
67
68   sound_manager->play("sounds/fire-flower.wav");
69   remove_me();
70   return ABORT_MOVE;
71 }
72
73 /* EOF */