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 "object/flower.hpp"
18
19#include "audio/sound_manager.hpp"
20#include "object/player.hpp"
21#include "sprite/sprite.hpp"
22#include "sprite/sprite_manager.hpp"
23
24Flower::Flower(BonusType _type) :
25 type(_type),
26 sprite(),
27 flip(NO_FLIP),
28 lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
29{
30 m_col.m_bbox.set_size(32, 32);
31 lightsprite->set_blend(Blend::ADD);
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
59void
60Flower::update(float )
61{
62}
63
64void
65Flower::draw(DrawingContext& context)
66{
67 sprite->draw(context.color(), get_pos(), LAYER_OBJECTS, flip);
68 lightsprite->draw(context.light(), m_col.m_bbox.get_middle(), 0);
69}
70
71HitResponse
72Flower::collision(GameObject& other, const CollisionHit& )
73{
74 Player* player = dynamic_cast<Player*>(&other);
75 if (!player)
76 return ABORT_MOVE;
77
78 if (!player->add_bonus(type, true))
79 return FORCE_MOVE;
80
81 SoundManager::current()->play("sounds/fire-flower.wav");
82 remove_me();
83 return ABORT_MOVE;
84}
85
86/* EOF */
87