src/object/growup.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/growup.hpp"
00019 #include "object/player.hpp"
00020 
00021 GrowUp::GrowUp(Direction direction) :
00022   MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING),
00023   physic()
00024 {
00025   physic.enable_gravity(true);
00026   physic.set_velocity_x((direction == LEFT)?-100:100);
00027   sound_manager->preload("sounds/grow.ogg");
00028 }
00029 
00030 void
00031 GrowUp::update(float elapsed_time)
00032 {
00033   movement = physic.get_movement(elapsed_time);
00034 }
00035 
00036 void
00037 GrowUp::collision_solid(const CollisionHit& hit)
00038 {
00039   if(hit.top)
00040     physic.set_velocity_y(0);
00041   if(hit.bottom && physic.get_velocity_y() > 0)
00042     physic.set_velocity_y(0);
00043   if(hit.left || hit.right)
00044     physic.set_velocity_x(-physic.get_velocity_x());
00045 }
00046 
00047 HitResponse
00048 GrowUp::collision(GameObject& other, const CollisionHit& hit )
00049 {
00050   Player* player = dynamic_cast<Player*>(&other);
00051   if(player != 0) {
00052     if(!player->add_bonus(GROWUP_BONUS, true)){
00053       // Tux can't grow right now.
00054       collision_solid( hit );
00055       return ABORT_MOVE;
00056     }
00057 
00058     sound_manager->play("sounds/grow.ogg");
00059     remove_me();
00060 
00061     return ABORT_MOVE;
00062   }
00063 
00064   return FORCE_MOVE;
00065 }
00066 
00067 void
00068 GrowUp::do_jump()
00069 {
00070   physic.set_velocity_y(-300);
00071 }
00072 
00073 /* EOF */

Generated on Mon Apr 14 03:38:21 2014 for SuperTux by  doxygen 1.5.1