BouncyCoin Class Reference

#include <bouncy_coin.hpp>

Inherits GameObject.

List of all members.

Public Member Functions

 BouncyCoin (const Vector &pos, bool emerge=false)
 ~BouncyCoin ()
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.

Private Member Functions

 BouncyCoin (const BouncyCoin &)
BouncyCoinoperator= (const BouncyCoin &)

Private Attributes

SpritePtr sprite
Vector position
Timer timer
float emerge_distance


Detailed Description

Definition at line 30 of file bouncy_coin.hpp.


Constructor & Destructor Documentation

BouncyCoin::BouncyCoin ( const Vector pos,
bool  emerge = false 
)

Definition at line 27 of file bouncy_coin.cpp.

References SpriteManager::create(), emerge_distance, LIFE_TIME, sprite, sprite_manager, Timer::start(), and timer.

00027                                                      :
00028   sprite(),
00029   position(pos), 
00030   timer(),
00031   emerge_distance(0)
00032 {
00033   timer.start(LIFE_TIME);
00034   sprite = sprite_manager->create("images/objects/coin/coin.sprite");
00035 
00036   if(emerge) {
00037     emerge_distance = sprite->get_height();
00038   }
00039 }

BouncyCoin::~BouncyCoin (  ) 

Definition at line 41 of file bouncy_coin.cpp.

00042 {
00043 }

BouncyCoin::BouncyCoin ( const BouncyCoin  )  [private]


Member Function Documentation

void BouncyCoin::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)

Implements GameObject.

Definition at line 46 of file bouncy_coin.cpp.

References Timer::check(), emerge_distance, position, GameObject::remove_me(), timer, and Vector::y.

00047 {
00048   float dist = -200 * elapsed_time;
00049   position.y += dist;
00050   emerge_distance += dist;
00051 
00052   if(timer.check())
00053     remove_me();
00054 }

void BouncyCoin::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 57 of file bouncy_coin.cpp.

References emerge_distance, FADE_TIME, Timer::get_timeleft(), LAYER_OBJECTS, DrawingContext::pop_transform(), position, DrawingContext::push_transform(), DrawingContext::set_alpha(), sprite, and timer.

00058 {
00059   float time_left = timer.get_timeleft();
00060   bool fading = time_left < FADE_TIME;
00061   if(fading) {
00062     float alpha = time_left/FADE_TIME;
00063     context.push_transform();
00064     context.set_alpha(alpha);
00065   }
00066 
00067   int layer;
00068   if(emerge_distance > 0) {
00069     layer = LAYER_OBJECTS - 5;
00070   } else {
00071     layer = LAYER_OBJECTS + 5;
00072   }
00073   sprite->draw(context, position, layer);
00074 
00075   if(fading) {
00076     context.pop_transform();
00077   }
00078 }

BouncyCoin& BouncyCoin::operator= ( const BouncyCoin  )  [private]


Member Data Documentation

SpritePtr BouncyCoin::sprite [private]

Definition at line 39 of file bouncy_coin.hpp.

Referenced by BouncyCoin(), and draw().

Vector BouncyCoin::position [private]

Definition at line 40 of file bouncy_coin.hpp.

Referenced by draw(), and update().

Timer BouncyCoin::timer [private]

Definition at line 41 of file bouncy_coin.hpp.

Referenced by BouncyCoin(), draw(), and update().

float BouncyCoin::emerge_distance [private]

Definition at line 42 of file bouncy_coin.hpp.

Referenced by BouncyCoin(), draw(), and update().


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