src/object/invisible_block.cpp

Go to the documentation of this file.
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/invisible_block.hpp"
00019 #include "object/player.hpp"
00020 #include "sprite/sprite.hpp"
00021 #include "sprite/sprite_manager.hpp"
00022 #include "supertux/constants.hpp"
00023 
00024 InvisibleBlock::InvisibleBlock(const Vector& pos) :
00025    Block(sprite_manager->create("images/objects/bonus_block/invisibleblock.sprite")), 
00026    visible(false)
00027 {
00028   bbox.set_pos(pos);
00029   sound_manager->preload("sounds/brick.wav");
00030 }
00031 
00032 void
00033 InvisibleBlock::draw(DrawingContext& context)
00034 {
00035   if(visible)
00036     sprite->draw(context, get_pos(), LAYER_OBJECTS);
00037 }
00038 
00039 bool
00040 InvisibleBlock::collides(GameObject& other, const CollisionHit& )
00041 {
00042   if(visible)
00043     return true;
00044 
00045   // if we're not visible, only register a collision if this will make us visible
00046   Player* player = dynamic_cast<Player*> (&other);
00047   if ((player) 
00048       && (player->get_movement().y <= 0)
00049       && (player->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA)) {
00050     return true;
00051   }
00052 
00053   return false;
00054 }
00055 
00056 HitResponse
00057 InvisibleBlock::collision(GameObject& other, const CollisionHit& hit)
00058 {
00059   return Block::collision(other, hit);
00060 }
00061 
00062 void
00063 InvisibleBlock::hit(Player& player)
00064 {
00065   sound_manager->play("sounds/brick.wav");
00066 
00067   if(visible)
00068     return;
00069 
00070   sprite->set_action("empty");
00071   start_bounce(&player);
00072   set_group(COLGROUP_STATIC);
00073   visible = true;
00074 }
00075 
00076 //IMPLEMENT_FACTORY(InvisibleBlock, "invisible_block");
00077 
00078 /* EOF */

Generated on Mon Jun 9 03:38:19 2014 for SuperTux by  doxygen 1.5.1