Coin Class Reference

#include <coin.hpp>

Inherits MovingSprite.

List of all members.

Public Member Functions

 Coin (const Vector &pos)
 Coin (const Vector &pos, TileMap *tilemap)
 Coin (const Reader &reader)
HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
void collect ()
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.

Private Attributes

boost::shared_ptr< Pathpath
boost::shared_ptr< PathWalkerwalker
Vector offset
bool from_tilemap


Detailed Description

Definition at line 26 of file coin.hpp.


Constructor & Destructor Documentation

Coin::Coin ( const Vector pos  ) 

Definition at line 28 of file coin.cpp.

References SoundManager::preload(), and sound_manager.

00029   : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
00030     path(),
00031     walker(),
00032     offset(),
00033     from_tilemap(false)
00034 {
00035   sound_manager->preload("sounds/coin.wav");
00036 }

Coin::Coin ( const Vector pos,
TileMap tilemap 
)

Definition at line 38 of file coin.cpp.

References offset, path, SoundManager::preload(), sound_manager, and walker.

00039   : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
00040     path(boost::shared_ptr<Path>(tilemap->get_path())),
00041     walker(boost::shared_ptr<PathWalker>(tilemap->get_walker())),
00042     offset(),
00043     from_tilemap(true)
00044 {
00045   if(walker.get()) {
00046     Vector v = path->get_base();
00047     offset = pos - v;
00048   }
00049 
00050   sound_manager->preload("sounds/coin.wav");
00051 }

Coin::Coin ( const Reader reader  ) 

Definition at line 53 of file coin.cpp.

References lisp::Lisp::get_lisp(), path, SoundManager::preload(), MovingObject::set_pos(), sound_manager, and walker.

00054   : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
00055     path(),
00056     walker(),
00057     offset(),
00058     from_tilemap(false)
00059 {
00060   const lisp::Lisp* pathLisp = reader.get_lisp("path");
00061   if (pathLisp) {
00062     path.reset(new Path());
00063     path->read(*pathLisp);
00064     walker.reset(new PathWalker(path.get()));
00065     Vector v = path->get_base();
00066     set_pos(v);
00067   }
00068 
00069   sound_manager->preload("sounds/coin.wav");
00070 }


Member Function Documentation

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

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

Implements MovingObject.

Definition at line 162 of file coin.cpp.

References ABORT_MOVE, and collect().

00163 {
00164   Player* player = dynamic_cast<Player*>(&other);
00165   if(player == 0)
00166     return ABORT_MOVE;
00167 
00168   collect();
00169   return ABORT_MOVE;
00170 }

void Coin::collect (  ) 

Definition at line 83 of file coin.cpp.

References PlayerStatus::add_coins(), Sector::add_object(), Statistics::coins, Sector::current(), Sector::get_level(), MovingObject::get_pos(), Player::get_status(), Sector::player, GameObject::remove_me(), and Level::stats.

Referenced by collision(), and Block::collision().

00084 {
00085   // TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
00086   /*
00087     static Timer sound_timer;
00088     static int pitch_one = 128;
00089     static float last_pitch = 1;
00090     float pitch = 1;
00091 
00092     int tile = static_cast<int>(get_pos().y / 32);
00093 
00094     if (!sound_timer.started()) {
00095     pitch_one = tile;
00096     pitch = 1;
00097     last_pitch = 1;
00098     }
00099     else if (sound_timer.get_timegone() < 0.02) {
00100     pitch = last_pitch;
00101     }
00102     else
00103     {
00104     switch ((pitch_one - tile) % 7) {
00105     case -6:
00106     pitch = 1.0/2;
00107     break;
00108     case -5:
00109     pitch = 5.0/8;
00110     break;
00111     case -4:
00112     pitch = 4.0/6;
00113     break;
00114     case -3:
00115     pitch = 3.0/4;
00116     break;
00117     case -2:
00118     pitch = 5.0/6;
00119     break;
00120     case -1:
00121     pitch = 9.0/10;
00122     break;
00123     case 0:
00124     pitch = 1.0;
00125     break;
00126     case 1:
00127     pitch = 9.0/8;
00128     break;
00129     case 2:
00130     pitch = 5.0/4;
00131     break;
00132     case 3:
00133     pitch = 4.0/3;
00134     break;
00135     case 4:
00136     pitch = 3.0/2;
00137     break;
00138     case 5:
00139     pitch = 5.0/3;
00140     break;
00141     case 6:
00142     pitch = 9.0/5;
00143     break;
00144     }
00145     last_pitch = pitch;
00146     }
00147     sound_timer.start(1);
00148 
00149     SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
00150     soundSource->set_position(get_pos());
00151     soundSource->set_pitch(pitch);
00152     soundSource->play();
00153     sound_manager->manage_source(soundSource);
00154   */
00155   Sector::current()->player->get_status()->add_coins(1);
00156   Sector::current()->add_object(new BouncyCoin(get_pos()));
00157   Sector::current()->get_level()->stats.coins++;
00158   remove_me();
00159 }

void Coin::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 73 of file coin.cpp.

References from_tilemap, MovingObject::get_pos(), MovingObject::movement, offset, and walker.

00074 {
00075   // if we have a path to follow, follow it
00076   if (walker.get()) {
00077     Vector v = from_tilemap ? offset + walker->get_pos() : walker->advance(elapsed_time);
00078     movement = v - get_pos();
00079   }
00080 }


Member Data Documentation

boost::shared_ptr<Path> Coin::path [private]

Definition at line 39 of file coin.hpp.

Referenced by Coin().

boost::shared_ptr<PathWalker> Coin::walker [private]

Definition at line 40 of file coin.hpp.

Referenced by Coin(), and update().

Vector Coin::offset [private]

Definition at line 41 of file coin.hpp.

Referenced by Coin(), and update().

bool Coin::from_tilemap [private]

Definition at line 42 of file coin.hpp.

Referenced by update().


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