00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #include "audio/sound_manager.hpp" 00018 #include "object/flower.hpp" 00019 #include "object/player.hpp" 00020 #include "sprite/sprite_manager.hpp" 00021 00022 Flower::Flower(BonusType _type) : 00023 type(_type), 00024 sprite(), 00025 drawing_effect(NO_EFFECT) 00026 { 00027 bbox.set_size(32, 32); 00028 00029 if(type == FIRE_BONUS) { 00030 sprite = sprite_manager->create("images/powerups/fireflower/fireflower.sprite"); 00031 sound_manager->preload("sounds/fire-flower.wav"); 00032 } 00033 else if(type == ICE_BONUS) { 00034 sprite = sprite_manager->create("images/powerups/iceflower/iceflower.sprite"); 00035 sound_manager->preload("sounds/fire-flower.wav"); 00036 } else { 00037 assert(false); 00038 } 00039 00040 set_group(COLGROUP_TOUCHABLE); 00041 } 00042 00043 Flower::~Flower() 00044 { 00045 } 00046 00047 void 00048 Flower::update(float ) 00049 { 00050 } 00051 00052 void 00053 Flower::draw(DrawingContext& context) 00054 { 00055 sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect); 00056 } 00057 00058 HitResponse 00059 Flower::collision(GameObject& other, const CollisionHit& ) 00060 { 00061 Player* player = dynamic_cast<Player*>(&other); 00062 if(!player) 00063 return ABORT_MOVE; 00064 00065 if(!player->add_bonus(type, true)) 00066 return FORCE_MOVE; 00067 00068 sound_manager->play("sounds/fire-flower.wav"); 00069 remove_me(); 00070 return ABORT_MOVE; 00071 } 00072 00073 /* EOF */