From: Wolfgang Becker Date: Sat, 15 Jul 2006 00:06:34 +0000 (+0000) Subject: Trampoline. X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=6a38ca588956d34a22bda9ef1beb53582610b4b5;p=supertux.git Trampoline. SVN-Revision: 4012 --- diff --git a/data/images/objects/trampoline/trampoline_red.sprite b/data/images/objects/trampoline/trampoline_red.sprite new file mode 100644 index 000000000..948c47d25 --- /dev/null +++ b/data/images/objects/trampoline/trampoline_red.sprite @@ -0,0 +1,11 @@ +(supertux-sprite + (action + (name "normal") + (hitbox 0 0 0 0) + (images "trampoline2-0.png" + "trampoline2-1.png" + "trampoline2-2.png" + "trampoline2-3.png" + ) + ) +) diff --git a/data/levels/test/trampoline.stl b/data/levels/test/trampoline.stl new file mode 100644 index 000000000..23ccc543b --- /dev/null +++ b/data/levels/test/trampoline.stl @@ -0,0 +1,70 @@ +(supertux-level + (version 2) + (name (_ "Unnamed")) + (author "wolfgang") + (sector + (name "main") + (gradient + (top_color 0.108017 0.7639008 0.8920441) + (bottom_color 0.9094849 0.5871124 0.1132812) + ) + (tilemap + (z-pos -100) + (solid #f) + (speed 1) + (width 25) + (height 35) + (tiles 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) + ) + (camera + (mode "normal") + ) + (mrbomb + (direction "auto") + (x 608) + (y 1024) + (sprite "images/creatures/mr_bomb/mr_bomb.sprite") + ) + (spawnpoint + (name "main") + (x 128) + (y 992) + ) + (trampoline + (x 352) + (y 1056) + (sprite "") + ) + (trampoline + (x 320) + (y 1056) + (sprite "images/objects/trampoline/trampoline_red.sprite") + ) + (trampoline + (x 288) + (y 1056) + (sprite "") + ) + (trampoline + (x 256) + (y 1056) + (sprite "images/objects/trampoline/trampoline_red.sprite") + ) + ) +) diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp new file mode 100644 index 000000000..58f0cc34f --- /dev/null +++ b/src/object/trampoline.cpp @@ -0,0 +1,113 @@ +// $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 distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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 + +#include "trampoline.hpp" +#include "object_factory.hpp" +#include "player.hpp" +#include "audio/sound_manager.hpp" +#include "sprite/sprite_manager.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::Trampoline(const lisp::Lisp& lisp) + : MovingSprite(lisp, "images/objects/trampoline/trampoline.sprite" ) +{ + sound_manager->preload( TRAMPOLINE_SOUND ); + flags |= FLAG_PORTABLE; + physic.set_velocity_y(0); + physic.enable_gravity(true); + on_ground = false; + + //Check if we need another sprite + if( !lisp.get( "sprite", sprite_name ) ){ + return; + } + if( sprite_name == "" ){ + sprite_name = "images/objects/trampoline/trampoline.sprite"; + return; + } + //Replace sprite + sprite = sprite_manager->create( sprite_name ); + +} + +void +Trampoline::update( float elapsed_time ){ + if( !on_ground ){ + movement = physic.get_movement(elapsed_time); + } +} + +HitResponse +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; + } + if( vy > VY_INITIAL ){ + vy = VY_INITIAL; + } + player->physic.set_velocity_y( vy ); + //printf("nachher velocity y = %f\n", player->physic.get_velocity_y()); + sound_manager->play( TRAMPOLINE_SOUND ); + return SOLID; + } + } + + return SOLID; //TODO: Nobody should be able to walk through the trampoline. +} + +void +Trampoline::collision_solid( const CollisionHit& hit ){ + if( hit.bottom ){ + on_ground = true; + } +} + +void +Trampoline::grab( MovingObject&, const Vector& pos, Direction ){ + movement = pos - get_pos(); + set_group( COLGROUP_DISABLED ); + on_ground = true; +} + +void +Trampoline::ungrab(MovingObject& , Direction ){ + set_group( COLGROUP_MOVING ); + on_ground = false; + physic.set_velocity_y(0); +} + + +IMPLEMENT_FACTORY(Trampoline, "trampoline"); diff --git a/src/object/trampoline.hpp b/src/object/trampoline.hpp new file mode 100644 index 000000000..f856ca017 --- /dev/null +++ b/src/object/trampoline.hpp @@ -0,0 +1,51 @@ +// $Id$ +// +// SuperTux - Trampolin +// 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 distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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. + +#ifndef SUPERTUX_TRAMPOLINE_H +#define SUPERTUX_TRAMPOLINE_H + +#include "moving_sprite.hpp" +#include "lisp/lisp.hpp" +#include "object/portable.hpp" +#include "physic.hpp" + +/** + * Jumping on a trampolin makes tux jump higher. + */ +class Trampoline : public MovingSprite, + public Portable + +{ +public: + Trampoline(const lisp::Lisp& reader); + + HitResponse collision(GameObject& other, const CollisionHit& hit); + void collision_solid( const CollisionHit& hit ); + void update( float elapsed_time ); + + void grab( MovingObject&, const Vector& pos, Direction ); + void ungrab(MovingObject& , Direction ); + +private: + Physic physic; + bool on_ground; +}; + +#endif +