Graphics for powerups: airflower and earthflower
[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   }
43   else if(type == AIR_BONUS) {
44     sprite = SpriteManager::current()->create("images/powerups/airflower/airflower.sprite");
45     SoundManager::current()->preload("sounds/fire-flower.wav");
46     lightsprite->set_color(Color(0.15f, 0.0f, 0.15f));
47   }
48   else if(type == EARTH_BONUS) {
49     sprite = SpriteManager::current()->create("images/powerups/earthflower/earthflower.sprite");
50     SoundManager::current()->preload("sounds/fire-flower.wav");
51     lightsprite->set_color(Color(0.0f, 0.3f, 0.0f));
52   } else {
53     assert(false);
54   }
55
56   set_group(COLGROUP_TOUCHABLE);
57 }
58
59 Flower::~Flower()
60 {
61 }
62
63 void
64 Flower::update(float )
65 {
66 }
67
68 void
69 Flower::draw(DrawingContext& context)
70 {
71   //Draw the Sprite.
72   sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect);
73   //Draw the light when dark
74   context.get_light( get_bbox().get_middle(), &light );
75   if (light.red + light.green + light.blue < 3.0){
76     context.push_target();
77     context.set_target(DrawingContext::LIGHTMAP);
78     lightsprite->draw(context, get_bbox().get_middle(), 0);
79     context.pop_target();
80   }
81 }
82
83 HitResponse
84 Flower::collision(GameObject& other, const CollisionHit& )
85 {
86   Player* player = dynamic_cast<Player*>(&other);
87   if(!player)
88     return ABORT_MOVE;
89
90   if(!player->add_bonus(type, true))
91     return FORCE_MOVE;
92
93   SoundManager::current()->play("sounds/fire-flower.wav");
94   remove_me();
95   return ABORT_MOVE;
96 }
97
98 /* EOF */