SDL2.0.1 dep addition
[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.hpp"
21 #include "sprite/sprite_manager.hpp"
22
23 Flower::Flower(BonusType _type) :
24   type(_type),
25   sprite(),
26   drawing_effect(NO_EFFECT),
27   light(1.0f,1.0f,1.0f),
28   lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
29 {
30   bbox.set_size(32, 32);
31   lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
32
33   if(type == FIRE_BONUS) {
34     sprite = SpriteManager::current()->create("images/powerups/fireflower/fireflower.sprite");
35     SoundManager::current()->preload("sounds/fire-flower.wav");
36     lightsprite->set_color(Color(0.3f, 0.0f, 0.0f));
37   }
38   else if(type == ICE_BONUS) {
39     sprite = SpriteManager::current()->create("images/powerups/iceflower/iceflower.sprite");
40     SoundManager::current()->preload("sounds/fire-flower.wav");
41     lightsprite->set_color(Color(0.0f, 0.1f, 0.2f));
42   } else {
43     assert(false);
44   }
45
46   set_group(COLGROUP_TOUCHABLE);
47 }
48
49 Flower::~Flower()
50 {
51 }
52
53 void
54 Flower::update(float )
55 {
56 }
57
58 void
59 Flower::draw(DrawingContext& context)
60 {
61   //Draw the Sprite.
62   sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect);
63   //Draw the light when dark
64   context.get_light( get_bbox().get_middle(), &light );
65   if (light.red + light.green + light.blue < 3.0){
66     context.push_target();
67     context.set_target(DrawingContext::LIGHTMAP);
68     lightsprite->draw(context, get_bbox().get_middle(), 0);
69     context.pop_target();
70   }
71 }
72
73 HitResponse
74 Flower::collision(GameObject& other, const CollisionHit& )
75 {
76   Player* player = dynamic_cast<Player*>(&other);
77   if(!player)
78     return ABORT_MOVE;
79
80   if(!player->add_bonus(type, true))
81     return FORCE_MOVE;
82
83   SoundManager::current()->play("sounds/fire-flower.wav");
84   remove_me();
85   return ABORT_MOVE;
86 }
87
88 /* EOF */