2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
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"
23 Flower::Flower(BonusType _type) :
26 drawing_effect(NO_EFFECT),
27 light(1.0f,1.0f,1.0f),
28 lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
30 bbox.set_size(32, 32);
31 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
33 if(type == FIRE_BONUS) {
34 sprite = sprite_manager->create("images/powerups/fireflower/fireflower.sprite");
35 sound_manager->preload("sounds/fire-flower.wav");
36 lightsprite->set_color(Color(0.3f, 0.0f, 0.0f));
38 else if(type == ICE_BONUS) {
39 sprite = sprite_manager->create("images/powerups/iceflower/iceflower.sprite");
40 sound_manager->preload("sounds/fire-flower.wav");
41 lightsprite->set_color(Color(0.0f, 0.1f, 0.2f));
46 set_group(COLGROUP_TOUCHABLE);
54 Flower::update(float )
59 Flower::draw(DrawingContext& context)
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);
74 Flower::collision(GameObject& other, const CollisionHit& )
76 Player* player = dynamic_cast<Player*>(&other);
80 if(!player->add_bonus(type, true))
83 sound_manager->play("sounds/fire-flower.wav");