GrowUp Class Reference

#include <growup.hpp>

Inherits MovingSprite.

List of all members.

Public Member Functions

 GrowUp (Direction direction=RIGHT)
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void collision_solid (const CollisionHit &hit)
 this function is called when the object collided with something solid
virtual HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
void do_jump ()

Private Attributes

Physic physic


Detailed Description

Definition at line 24 of file growup.hpp.


Constructor & Destructor Documentation

GrowUp::GrowUp ( Direction  direction = RIGHT  ) 

Definition at line 21 of file growup.cpp.

References Physic::enable_gravity(), LEFT, physic, SoundManager::preload(), Physic::set_velocity_x(), and sound_manager.

00021                                   :
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 }


Member Function Documentation

void GrowUp::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 MovingSprite.

Definition at line 31 of file growup.cpp.

References Physic::get_movement(), MovingObject::movement, and physic.

00032 {
00033   movement = physic.get_movement(elapsed_time);
00034 }

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

this function is called when the object collided with something solid

Reimplemented from MovingObject.

Definition at line 37 of file growup.cpp.

References CollisionHit::bottom, Physic::get_velocity_x(), Physic::get_velocity_y(), CollisionHit::left, physic, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), and CollisionHit::top.

Referenced by collision().

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 }

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

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

Implements MovingObject.

Definition at line 48 of file growup.cpp.

References ABORT_MOVE, Player::add_bonus(), collision_solid(), FORCE_MOVE, GROWUP_BONUS, SoundManager::play(), GameObject::remove_me(), and sound_manager.

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 }

void GrowUp::do_jump (  ) 

Definition at line 68 of file growup.cpp.

References physic, and Physic::set_velocity_y().

Referenced by Block::collision().

00069 {
00070   physic.set_velocity_y(-300);
00071 }


Member Data Documentation

Physic GrowUp::physic [private]

Definition at line 35 of file growup.hpp.

Referenced by collision_solid(), do_jump(), GrowUp(), and update().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:31 2014 for SuperTux by  doxygen 1.5.1