PowerUp Class Reference

#include <powerup.hpp>

Inherits MovingSprite.

List of all members.

Public Member Functions

 PowerUp (const Reader &lisp)
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

Private Attributes

Physic physic
std::string script
bool no_physics


Detailed Description

Definition at line 22 of file powerup.hpp.


Constructor & Destructor Documentation

PowerUp::PowerUp ( const Reader lisp  ) 

Definition at line 26 of file powerup.cpp.

References Physic::enable_gravity(), lisp::Lisp::get(), no_physics, physic, SoundManager::preload(), script, and sound_manager.

00026                                    :
00027   MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING),
00028   physic(),
00029   script(),
00030   no_physics()
00031 {
00032   lisp.get("script", script);
00033   no_physics = false;
00034   lisp.get("disable-physics", no_physics);
00035   physic.enable_gravity(true);
00036   sound_manager->preload("sounds/grow.ogg");
00037   sound_manager->preload("sounds/fire-flower.wav");
00038 }


Member Function Documentation

void PowerUp::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 85 of file powerup.cpp.

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

00086 {
00087   if (!no_physics)
00088     movement = physic.get_movement(elapsed_time);
00089 }

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

this function is called when the object collided with something solid

Reimplemented from MovingObject.

Definition at line 41 of file powerup.cpp.

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

00042 {
00043   if(hit.bottom) {
00044     physic.set_velocity_y(0);
00045   }
00046   if(hit.right || hit.left) {
00047     physic.set_velocity_x(-physic.get_velocity_x());
00048   }
00049 }

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

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

Implements MovingObject.

Definition at line 52 of file powerup.cpp.

References ABORT_MOVE, Player::add_bonus(), PlayerStatus::add_coins(), Sector::current(), FIRE_BONUS, FORCE_MOVE, Player::get_status(), GROWUP_BONUS, Player::make_invincible(), SoundManager::play(), GameObject::remove_me(), Sector::run_script(), script, sound_manager, and MovingSprite::sprite_name.

00053 {
00054   Player* player = dynamic_cast<Player*>(&other);
00055   if(player == 0)
00056     return FORCE_MOVE;
00057 
00058   if (script != "") {
00059     std::istringstream stream(script);
00060     Sector::current()->run_script(stream, "powerup-script");
00061     remove_me();
00062     return ABORT_MOVE;
00063   }
00064 
00065   // some defaults if no script has been set
00066   if (sprite_name == "images/powerups/egg/egg.sprite") {
00067     if(!player->add_bonus(GROWUP_BONUS, true))
00068       return FORCE_MOVE;
00069     sound_manager->play("sounds/grow.ogg");
00070   } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") {
00071     if(!player->add_bonus(FIRE_BONUS, true))
00072       return FORCE_MOVE;
00073     sound_manager->play("sounds/fire-flower.wav");
00074   } else if (sprite_name == "images/powerups/star/star.sprite") {
00075     player->make_invincible();
00076   } else if (sprite_name == "images/powerups/1up/1up.sprite") {
00077     player->get_status()->add_coins(100);
00078   }
00079 
00080   remove_me();
00081   return ABORT_MOVE;
00082 }


Member Data Documentation

Physic PowerUp::physic [private]

Definition at line 32 of file powerup.hpp.

Referenced by collision_solid(), PowerUp(), and update().

std::string PowerUp::script [private]

Definition at line 33 of file powerup.hpp.

Referenced by collision(), and PowerUp().

bool PowerUp::no_physics [private]

Definition at line 34 of file powerup.hpp.

Referenced by PowerUp(), and update().


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