Climbable Class Reference

#include <climbable.hpp>

Inherits TriggerBase.

List of all members.

Public Member Functions

 Climbable (const Reader &reader)
 Climbable (const Rectf &area)
 ~Climbable ()
void event (Player &player, EventType type)
 Receive trigger events.
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.
bool may_climb (Player &player)
 returns true if the player is within bounds of the Climbable

Protected Attributes

Playerclimbed_by
 set to player who's currently climbing us, null if nobody is
Timer activate_try_timer
 try to correct mis-alignment while this timer runs

Private Member Functions

 Climbable (const Climbable &)
Climbableoperator= (const Climbable &)

Static Private Attributes

static Color text_color


Detailed Description

Definition at line 28 of file climbable.hpp.


Constructor & Destructor Documentation

Climbable::Climbable ( const Reader reader  ) 

Definition at line 33 of file climbable.cpp.

References MovingObject::bbox, lisp::Lisp::get(), Rectf::p1, Rectf::set_size(), Vector::x, and Vector::y.

00033                                          :
00034   climbed_by(0),
00035   activate_try_timer()
00036 {
00037   reader.get("x", bbox.p1.x);
00038   reader.get("y", bbox.p1.y);
00039   float w = 32, h = 32;
00040   reader.get("width", w);
00041   reader.get("height", h);
00042   bbox.set_size(w, h);
00043 }

Climbable::Climbable ( const Rectf area  ) 

Definition at line 45 of file climbable.cpp.

References MovingObject::bbox.

00045                                       :
00046   climbed_by(0),
00047   activate_try_timer()
00048 {
00049   bbox = area;
00050 }

Climbable::~Climbable (  ) 

Definition at line 52 of file climbable.cpp.

References climbed_by, and Player::stop_climbing().

00053 {
00054   if (climbed_by) {
00055     climbed_by->stop_climbing(*this);
00056     climbed_by = 0;
00057   }
00058 }

Climbable::Climbable ( const Climbable  )  [private]


Member Function Documentation

void Climbable::event ( Player player,
EventType  type 
) [virtual]

Receive trigger events.

Implements TriggerBase.

Definition at line 84 of file climbable.cpp.

References ACTIVATE_TRY_FOR, activate_try_timer, climbed_by, TriggerBase::EVENT_ACTIVATE, TriggerBase::EVENT_LOSETOUCH, MovingObject::get_bbox(), Player::get_grabbed_object(), GRACE_DX, GRACE_DY, may_climb(), Rectf::p1, Rectf::p2, POSITION_FIX_AX, POSITION_FIX_AY, Timer::start(), Player::start_climbing(), Timer::started(), Timer::stop(), Player::stop_climbing(), Vector::x, and Vector::y.

00085 {
00086   if ((type == EVENT_ACTIVATE) || (activate_try_timer.started())) {
00087     if(player.get_grabbed_object() == NULL){
00088       if(may_climb(player)) {
00089         climbed_by = &player;
00090         player.start_climbing(*this);
00091         activate_try_timer.stop();
00092       } else {
00093         if (type == EVENT_ACTIVATE) activate_try_timer.start(ACTIVATE_TRY_FOR);
00094         if (player.get_bbox().p1.x < get_bbox().p1.x - GRACE_DX) player.add_velocity(Vector(POSITION_FIX_AX,0));
00095         if (player.get_bbox().p2.x > get_bbox().p2.x + GRACE_DX) player.add_velocity(Vector(-POSITION_FIX_AX,0));
00096         if (player.get_bbox().p1.y < get_bbox().p1.y - GRACE_DY) player.add_velocity(Vector(0,POSITION_FIX_AY));
00097         if (player.get_bbox().p2.y > get_bbox().p2.y + GRACE_DY) player.add_velocity(Vector(0,-POSITION_FIX_AY));
00098       }
00099     }
00100   }
00101   if(type == EVENT_LOSETOUCH) {
00102     player.stop_climbing(*this);
00103     climbed_by = 0;
00104   }
00105 }

void Climbable::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 TriggerBase.

Definition at line 61 of file climbable.cpp.

References climbed_by, may_climb(), and Player::stop_climbing().

00062 {
00063   if (!climbed_by) return;
00064 
00065   if (!may_climb(*climbed_by)) {
00066     climbed_by->stop_climbing(*this);
00067     climbed_by = 0;
00068   }
00069 }

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

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

Reimplemented from TriggerBase.

Definition at line 72 of file climbable.cpp.

References _(), climbed_by, DrawingContext::draw_center_text(), LAYER_HUD, Resources::normal_font, DrawingContext::pop_transform(), DrawingContext::push_transform(), SCREEN_HEIGHT, DrawingContext::set_translation(), and text_color.

00073 {
00074   if (climbed_by) {
00075     context.push_transform();
00076     context.set_translation(Vector(0, 0));
00077     Vector pos = Vector(0, SCREEN_HEIGHT/2 - Resources::normal_font->get_height()/2);
00078     context.draw_center_text(Resources::normal_font, _("Up we go..."), pos, LAYER_HUD, Climbable::text_color);
00079     context.pop_transform();
00080   }
00081 }

bool Climbable::may_climb ( Player player  ) 

returns true if the player is within bounds of the Climbable

Definition at line 108 of file climbable.cpp.

References MovingObject::get_bbox(), GRACE_DX, GRACE_DY, Rectf::p1, Rectf::p2, Vector::x, and Vector::y.

Referenced by event(), and update().

00109 {
00110   if (player.get_bbox().p1.x < get_bbox().p1.x - GRACE_DX) return false;
00111   if (player.get_bbox().p2.x > get_bbox().p2.x + GRACE_DX) return false;
00112   if (player.get_bbox().p1.y < get_bbox().p1.y - GRACE_DY) return false;
00113   if (player.get_bbox().p2.y > get_bbox().p2.y + GRACE_DY) return false;
00114   return true;
00115 }

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


Member Data Documentation

Color Climbable::text_color [static, private]

Definition at line 30 of file climbable.hpp.

Referenced by draw().

Player* Climbable::climbed_by [protected]

set to player who's currently climbing us, null if nobody is

Definition at line 46 of file climbable.hpp.

Referenced by draw(), event(), update(), and ~Climbable().

Timer Climbable::activate_try_timer [protected]

try to correct mis-alignment while this timer runs

Definition at line 47 of file climbable.hpp.

Referenced by event().


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