SkullTile Class Reference

A tile that starts falling down if tux stands to long on it. More...

#include <skull_tile.hpp>

Inherits MovingSprite.

List of all members.

Public Member Functions

 SkullTile (const Reader &lisp)
HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.

Private Attributes

Physic physic
Timer timer
bool hit
bool falling


Detailed Description

A tile that starts falling down if tux stands to long on it.

Definition at line 25 of file skull_tile.hpp.


Constructor & Destructor Documentation

SkullTile::SkullTile ( const Reader lisp  ) 

Definition at line 27 of file skull_tile.cpp.

00027                                        :
00028   MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), 
00029   physic(),
00030   timer(),
00031   hit(false), 
00032   falling(false)
00033 {
00034 }


Member Function Documentation

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

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

Implements MovingObject.

Definition at line 37 of file skull_tile.cpp.

References FORCE_MOVE, and hit.

00038 {
00039   Player* player = dynamic_cast<Player*> (&other);
00040   if(player)
00041     hit = true;
00042 
00043   return FORCE_MOVE;
00044 }

void SkullTile::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 59 of file skull_tile.cpp.

References MovingObject::bbox, Timer::check(), Sector::current(), Physic::enable_gravity(), falling, FALLTIME, Physic::get_movement(), hit, MovingObject::movement, physic, GameObject::remove_me(), Timer::start(), Timer::started(), Timer::stop(), and timer.

00060 {
00061   if(falling) {
00062     movement = physic.get_movement(elapsed_time);
00063     if(!Sector::current()->inside(bbox)) {
00064       remove_me();
00065       return;
00066     }
00067   } else if(hit) {
00068     if(timer.check()) {
00069       falling = true;
00070       physic.enable_gravity(true);
00071       timer.stop();
00072     } else if(!timer.started()) {
00073       timer.start(FALLTIME);
00074     }
00075   } else {
00076     timer.stop();
00077   }
00078   hit = false;
00079 }

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

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

Reimplemented from MovingSprite.

Definition at line 47 of file skull_tile.cpp.

References CRACKTIME, MovingObject::get_pos(), Timer::get_timegone(), graphicsRandom, MovingSprite::layer, RandomGenerator::rand(), MovingSprite::sprite, timer, and Vector::x.

00048 {
00049   Vector pos = get_pos();
00050   // shaking
00051   if(timer.get_timegone() > CRACKTIME) {
00052     pos.x += graphicsRandom.rand(-3, 3);
00053   }
00054 
00055   sprite->draw(context, pos, layer);
00056 }


Member Data Documentation

Physic SkullTile::physic [private]

Definition at line 35 of file skull_tile.hpp.

Referenced by update().

Timer SkullTile::timer [private]

Definition at line 36 of file skull_tile.hpp.

Referenced by draw(), and update().

bool SkullTile::hit [private]

Definition at line 37 of file skull_tile.hpp.

Referenced by collision(), and update().

bool SkullTile::falling [private]

Definition at line 38 of file skull_tile.hpp.

Referenced by update().


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