X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Ftrampoline.cpp;h=b8d20ad5ee57bfb0c391a1276da513ecc7261aa1;hb=9f40a73e89c17a2862a1213343589c19eff42199;hp=03ac4fc872391f1f4aa6c683f261aed4a92ad225;hpb=43bb80b09e1823710fa1a17dd5e00b074a218709;p=supertux.git diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index 03ac4fc87..b8d20ad5e 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux - Trampoline // Copyright (C) 2006 Wolfgang Becker -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,103 +12,125 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include +// along with this program. If not, see . -#include "trampoline.hpp" -#include "object_factory.hpp" -#include "player.hpp" #include "audio/sound_manager.hpp" +#include "badguy/walking_badguy.hpp" +#include "control/controller.hpp" +#include "object/player.hpp" +#include "object/trampoline.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" +#include "supertux/object_factory.hpp" +#include "util/reader.hpp" -/* Trampoline will accelerate player by VY_FACTOR (or to VY_INITIAL if - * that's faster) if he jumps on it. Acceleration is capped at VY_MIN. */ -namespace{ - static const std::string TRAMPOLINE_SOUND = "sounds/trampoline.wav"; - static const float VY_MIN = -1000; //negative, upwards - static const float VY_FACTOR = -1.5; - static const float VY_INITIAL = -500; +/* Trampoline will accelerate player to to VY_INITIAL, if + * he jumps on it to VY_MIN. */ +namespace { +const std::string TRAMPOLINE_SOUND = "sounds/trampoline.wav"; +const float VY_MIN = -900; //negative, upwards +const float VY_INITIAL = -500; } -Trampoline::Trampoline(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/trampoline/trampoline.sprite" ) +Trampoline::Trampoline(const Reader& lisp) : + Rock(lisp, "images/objects/trampoline/trampoline.sprite"), + portable(true) { - sound_manager->preload( TRAMPOLINE_SOUND ); - flags |= FLAG_PORTABLE; - physic.set_velocity_y(0); - physic.enable_gravity(true); - on_ground = false; - sprite->set_animation_loops( 0 ); + SoundManager::current()->preload(TRAMPOLINE_SOUND); - //Check if we need another sprite - if( !lisp.get( "sprite", sprite_name ) ){ - return; + //Check if this trampoline is not portable + if(lisp.get("portable", portable)) { + if(!portable) { + //we need another sprite + sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; + sprite = SpriteManager::current()->create(sprite_name); + sprite->set_action("normal"); + } } - if( sprite_name == "" ){ - sprite_name = "images/objects/trampoline/trampoline.sprite"; - return; +} + +Trampoline::Trampoline(const Vector& pos, bool port) : + Rock(pos, "images/objects/trampoline/trampoline.sprite"), + portable(port) +{ + SoundManager::current()->preload(TRAMPOLINE_SOUND); + if(!port) { + sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; + sprite = SpriteManager::current()->create(sprite_name); + sprite->set_action("normal"); } - //Replace sprite - sprite = sprite_manager->create( sprite_name ); - sprite->set_animation_loops( 0 ); } void -Trampoline::update( float elapsed_time ){ - if( !on_ground ){ - movement = physic.get_movement(elapsed_time); - } +Trampoline::update(float elapsed_time) +{ + if(sprite->animation_done()) { + sprite->set_action("normal"); + } + + Rock::update(elapsed_time); } HitResponse -Trampoline::collision(GameObject& other, const CollisionHit& hit ) +Trampoline::collision(GameObject& other, const CollisionHit& hit) { - Player* player = dynamic_cast (&other); - if ( player ) { - float vy = player->physic.get_velocity_y(); - //player is falling down on trampolin holding "jump" - if( hit.top && vy > 0 && player->get_controller()->hold( Controller::JUMP )){ - vy *= VY_FACTOR; - if( vy < VY_MIN ){ - vy = VY_MIN; + + //Tramponine has to be on ground to work. + if(on_ground) { + Player* player = dynamic_cast (&other); + //Trampoline works for player + if(player) { + float vy = player->get_physic().get_velocity_y(); + //player is falling down on trampoline + if(hit.top && vy >= 0) { + if (!(player->get_status()->bonus == AIR_BONUS)) + vy = player->get_controller()->hold(Controller::JUMP) ? VY_MIN : VY_INITIAL; + else + vy = player->get_controller()->hold(Controller::JUMP) ? VY_MIN - 300 : VY_INITIAL - 40; + player->get_physic().set_velocity_y(vy); + SoundManager::current()->play(TRAMPOLINE_SOUND); + sprite->set_action("swinging", 1); + return FORCE_MOVE; } - if( vy > VY_INITIAL ){ - vy = VY_INITIAL; + } + WalkingBadguy* walking_badguy = dynamic_cast (&other); + //Trampoline also works for WalkingBadguy + if(walking_badguy) { + float vy = walking_badguy->get_velocity_y(); + //walking_badguy is falling down on trampoline + if(hit.top && vy >= 0) { + vy = VY_INITIAL; + walking_badguy->set_velocity_y(vy); + SoundManager::current()->play(TRAMPOLINE_SOUND); + sprite->set_action("swinging", 1); + return FORCE_MOVE; } - player->physic.set_velocity_y( vy ); - //printf("nachher velocity y = %f\n", player->physic.get_velocity_y()); - sound_manager->play( TRAMPOLINE_SOUND ); - sprite->set_animation_loops( -1 ); //TODO: 2 is not working - return SOLID; } } - - return SOLID; //TODO: Nobody should be able to walk through the trampoline. + + return Rock::collision(other, hit); } -void -Trampoline::collision_solid( const CollisionHit& hit ){ - if( hit.bottom ){ - on_ground = true; - } -} +void +Trampoline::collision_solid(const CollisionHit& hit) { + Rock::collision_solid(hit); +} void -Trampoline::grab( MovingObject&, const Vector& pos, Direction ){ - movement = pos - get_pos(); - set_group( COLGROUP_DISABLED ); - on_ground = true; - sprite->set_animation_loops( 0 ); +Trampoline::grab(MovingObject& object, const Vector& pos, Direction dir) { + sprite->set_animation_loops(0); + Rock::grab(object, pos, dir); } void -Trampoline::ungrab(MovingObject& , Direction ){ - set_group( COLGROUP_MOVING ); - on_ground = false; - physic.set_velocity_y(0); +Trampoline::ungrab(MovingObject& object, Direction dir) { + Rock::ungrab(object, dir); } +bool +Trampoline::is_portable() const +{ + return Rock::is_portable() && portable; +} -IMPLEMENT_FACTORY(Trampoline, "trampoline"); +/* EOF */