Trampoline Class Reference

Jumping on a trampoline makes tux jump higher. More...

#include <trampoline.hpp>

Inherits Rock.

List of all members.

Public Member Functions

 Trampoline (const Reader &reader)
HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
void collision_solid (const CollisionHit &hit)
 this function is called when the object collided with something solid
void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
void grab (MovingObject &, const Vector &pos, Direction)
 called each frame when the object has been grabbed.
void ungrab (MovingObject &, Direction)
bool is_portable () const

Private Attributes

bool portable


Detailed Description

Jumping on a trampoline makes tux jump higher.

Definition at line 25 of file trampoline.hpp.


Constructor & Destructor Documentation

Trampoline::Trampoline ( const Reader reader  ) 

Definition at line 35 of file trampoline.cpp.

References SpriteManager::create(), lisp::Lisp::get(), portable, SoundManager::preload(), sound_manager, MovingSprite::sprite, sprite_manager, MovingSprite::sprite_name, and TRAMPOLINE_SOUND.

00035                                          :
00036   Rock(lisp, "images/objects/trampoline/trampoline.sprite"),
00037   portable(true)
00038 {
00039   sound_manager->preload(TRAMPOLINE_SOUND);
00040 
00041   //Check if this trampoline is not portable
00042   if(lisp.get("portable", portable)) {
00043     if(!portable) {
00044       //we need another sprite
00045       sprite_name = "images/objects/trampoline/trampoline_fix.sprite";
00046       sprite = sprite_manager->create(sprite_name);
00047       sprite->set_action("normal");
00048     }
00049   }
00050 }


Member Function Documentation

HitResponse Trampoline::collision ( GameObject other,
const CollisionHit hit 
) [virtual]

this function is called when the object collided with any other object

Reimplemented from Rock.

Definition at line 63 of file trampoline.cpp.

References Rock::collision(), FORCE_MOVE, Player::get_controller(), Player::get_physic(), WalkingBadguy::get_velocity_y(), Physic::get_velocity_y(), Controller::hold(), Controller::JUMP, Rock::on_ground, SoundManager::play(), WalkingBadguy::set_velocity_y(), Physic::set_velocity_y(), sound_manager, MovingSprite::sprite, CollisionHit::top, TRAMPOLINE_SOUND, VY_INITIAL, and VY_MIN.

00064 {
00065 
00066   //Tramponine has to be on ground to work.
00067   if(on_ground) {
00068     Player* player = dynamic_cast<Player*> (&other);
00069     //Trampoline works for player
00070     if(player) {
00071       float vy = player->get_physic().get_velocity_y();
00072       //player is falling down on trampoline
00073       if(hit.top && vy >= 0) {
00074         if(player->get_controller()->hold(Controller::JUMP)) {
00075           vy = VY_MIN;
00076         } else {
00077           vy = VY_INITIAL;
00078         }
00079         player->get_physic().set_velocity_y(vy);
00080         sound_manager->play(TRAMPOLINE_SOUND);
00081         sprite->set_action("swinging", 1);
00082         return FORCE_MOVE;
00083       }
00084     }
00085     WalkingBadguy* walking_badguy = dynamic_cast<WalkingBadguy*> (&other);
00086     //Trampoline also works for WalkingBadguy
00087     if(walking_badguy) {
00088       float vy = walking_badguy->get_velocity_y();
00089       //walking_badguy is falling down on trampoline
00090       if(hit.top && vy >= 0) {
00091         vy = VY_INITIAL;
00092         walking_badguy->set_velocity_y(vy);
00093         sound_manager->play(TRAMPOLINE_SOUND);
00094         sprite->set_action("swinging", 1);
00095         return FORCE_MOVE;
00096       }
00097     }
00098   }
00099 
00100   return Rock::collision(other, hit);
00101 }

void Trampoline::collision_solid ( const CollisionHit hit  )  [virtual]

this function is called when the object collided with something solid

Reimplemented from Rock.

Definition at line 104 of file trampoline.cpp.

References Rock::collision_solid().

00104                                                    {
00105   Rock::collision_solid(hit);
00106 }

void Trampoline::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Reimplemented from Rock.

Definition at line 53 of file trampoline.cpp.

References MovingSprite::sprite, and Rock::update().

00054 {
00055   if(sprite->animation_done()) {
00056     sprite->set_action("normal");
00057   }
00058 
00059   Rock::update(elapsed_time);
00060 }

void Trampoline::grab ( MovingObject ,
const Vector pos,
Direction   
) [virtual]

called each frame when the object has been grabbed.

Reimplemented from Rock.

Definition at line 109 of file trampoline.cpp.

References Rock::grab(), and MovingSprite::sprite.

00109                                                                        {
00110   sprite->set_animation_loops(0);
00111   Rock::grab(object, pos, dir);
00112 }

void Trampoline::ungrab ( MovingObject ,
Direction   
) [virtual]

Reimplemented from Rock.

Definition at line 115 of file trampoline.cpp.

References Rock::ungrab().

00115                                                       {
00116   Rock::ungrab(object, dir);
00117 }

bool Trampoline::is_portable (  )  const [virtual]

Reimplemented from Portable.

Definition at line 120 of file trampoline.cpp.

References Portable::is_portable(), and portable.

00121 {
00122   return Rock::is_portable() && portable;
00123 }


Member Data Documentation

bool Trampoline::portable [private]

Definition at line 39 of file trampoline.hpp.

Referenced by is_portable(), and Trampoline().


The documentation for this class was generated from the following files:
Generated on Mon Apr 14 03:38:47 2014 for SuperTux by  doxygen 1.5.1