Rock Class Reference

#include <rock.hpp>

Inherits MovingSprite, and Portable.

Inherited by Lantern, and Trampoline.

List of all members.

Public Member Functions

 Rock (const Vector &pos, std::string spritename)
 Rock (const Reader &reader)
 Rock (const Reader &reader, std::string spritename)
void collision_solid (const CollisionHit &hit)
 this function is called when the object collided with something solid
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 grab (MovingObject &object, const Vector &pos, Direction dir)
 called each frame when the object has been grabbed.
void ungrab (MovingObject &object, Direction dir)

Protected Attributes

Physic physic
bool on_ground
bool grabbed
Vector last_movement


Detailed Description

Definition at line 26 of file rock.hpp.


Constructor & Destructor Documentation

Rock::Rock ( const Vector pos,
std::string  spritename 
)

Definition at line 26 of file rock.cpp.

References COLGROUP_MOVING_STATIC, grabbed, on_ground, SoundManager::preload(), ROCK_SOUND, MovingObject::set_group(), and sound_manager.

00026                                                   :
00027   MovingSprite(pos, spritename),
00028   physic(),
00029   on_ground(),
00030   grabbed(),
00031   last_movement()
00032 {
00033   sound_manager->preload(ROCK_SOUND);
00034   on_ground = false;
00035   grabbed = false;
00036   set_group(COLGROUP_MOVING_STATIC);
00037 }

Rock::Rock ( const Reader reader  ) 

Definition at line 39 of file rock.cpp.

References COLGROUP_MOVING_STATIC, grabbed, on_ground, SoundManager::preload(), ROCK_SOUND, MovingObject::set_group(), and sound_manager.

00039                                :
00040   MovingSprite(reader, "images/objects/rock/rock.sprite"),
00041   physic(),
00042   on_ground(),
00043   grabbed(),
00044   last_movement()
00045 {
00046   sound_manager->preload(ROCK_SOUND);
00047   on_ground = false;
00048   grabbed = false;
00049   set_group(COLGROUP_MOVING_STATIC);
00050 }

Rock::Rock ( const Reader reader,
std::string  spritename 
)

Definition at line 52 of file rock.cpp.

References COLGROUP_MOVING_STATIC, grabbed, on_ground, SoundManager::preload(), ROCK_SOUND, MovingObject::set_group(), and sound_manager.

00052                                                      :
00053   MovingSprite(reader, spritename),
00054   physic(),
00055   on_ground(),
00056   grabbed(),
00057   last_movement()
00058 {
00059   sound_manager->preload(ROCK_SOUND);
00060   on_ground = false;
00061   grabbed = false;
00062   set_group(COLGROUP_MOVING_STATIC);
00063 }


Member Function Documentation

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

this function is called when the object collided with something solid

Reimplemented from MovingObject.

Reimplemented in Trampoline.

Definition at line 77 of file rock.cpp.

References CollisionHit::bottom, CollisionHit::crush, MovingObject::get_pos(), grabbed, CollisionHit::left, on_ground, physic, SoundManager::play(), CollisionHit::right, ROCK_SOUND, Physic::set_velocity(), Physic::set_velocity_x(), Physic::set_velocity_y(), sound_manager, and CollisionHit::top.

Referenced by Trampoline::collision_solid().

00078 {
00079   if(grabbed) {
00080     return;
00081   }
00082   if(hit.top || hit.bottom)
00083     physic.set_velocity_y(0);
00084   if(hit.left || hit.right)
00085     physic.set_velocity_x(0);
00086   if(hit.crush)
00087     physic.set_velocity(0, 0);
00088 
00089   if(hit.bottom  && !on_ground && !grabbed) {
00090     sound_manager->play(ROCK_SOUND, get_pos());
00091     on_ground = true;
00092   }
00093 }

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

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

Implements MovingObject.

Reimplemented in Lantern, and Trampoline.

Definition at line 96 of file rock.cpp.

References ABORT_MOVE, CollisionHit::bottom, FORCE_MOVE, Physic::get_velocity_y(), grabbed, Tile::HURTS, on_ground, and physic.

Referenced by Trampoline::collision(), and Lantern::collision().

00097 {
00098   if(grabbed) {
00099     return ABORT_MOVE;
00100   }
00101   if(!on_ground) {
00102     if(hit.bottom && physic.get_velocity_y() > 200) {
00103       MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
00104       if(moving_object) {
00105         //Getting a rock on the head hurts. A lot.
00106         moving_object->collision_tile(Tile::HURTS);
00107       }
00108     }
00109     return FORCE_MOVE;
00110   }
00111 
00112   return FORCE_MOVE;
00113 }

void Rock::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.

Reimplemented in Trampoline.

Definition at line 66 of file rock.cpp.

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

Referenced by Trampoline::update().

00067 {
00068   if( grabbed )
00069     return;
00070 
00071   if (on_ground) physic.set_velocity_x(0);
00072 
00073   movement = physic.get_movement(elapsed_time);
00074 }

void Rock::grab ( MovingObject object,
const Vector pos,
Direction  dir 
) [virtual]

called each frame when the object has been grabbed.

Implements Portable.

Reimplemented in Lantern, and Trampoline.

Definition at line 116 of file rock.cpp.

References COLGROUP_TOUCHABLE, MovingObject::get_pos(), grabbed, last_movement, MovingObject::movement, on_ground, and MovingObject::set_group().

Referenced by Trampoline::grab(), and Lantern::grab().

00117 {
00118   movement = pos - get_pos();
00119   last_movement = movement;
00120   set_group(COLGROUP_TOUCHABLE); //needed for lanterns catching willowisps
00121   on_ground = false;
00122   grabbed = true;
00123 }

void Rock::ungrab ( MovingObject object,
Direction  dir 
) [virtual]

Reimplemented from Portable.

Reimplemented in Lantern, and Trampoline.

Definition at line 126 of file rock.cpp.

References COLGROUP_MOVING_STATIC, grabbed, last_movement, Vector::norm(), on_ground, physic, RIGHT, MovingObject::set_group(), Physic::set_velocity(), and UP.

Referenced by Trampoline::ungrab(), and Lantern::ungrab().

00127 {
00128   set_group(COLGROUP_MOVING_STATIC);
00129   on_ground = false;
00130   if(dir == UP) {
00131     physic.set_velocity(0, -500);
00132   } else if (last_movement.norm() > 1) {
00133     physic.set_velocity((dir == RIGHT) ? 200 : -200, -200);
00134   } else {
00135     physic.set_velocity(0, 0);
00136   }
00137   grabbed = false;
00138 }


Member Data Documentation

Physic Rock::physic [protected]

Definition at line 42 of file rock.hpp.

Referenced by collision(), collision_solid(), ungrab(), and update().

bool Rock::on_ground [protected]

Definition at line 43 of file rock.hpp.

Referenced by Trampoline::collision(), collision(), collision_solid(), grab(), Rock(), ungrab(), and update().

bool Rock::grabbed [protected]

Definition at line 44 of file rock.hpp.

Referenced by collision(), collision_solid(), grab(), Lantern::is_open(), Rock(), ungrab(), and update().

Vector Rock::last_movement [protected]

Definition at line 45 of file rock.hpp.

Referenced by grab(), and ungrab().


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