Player Class Reference

#include <player.hpp>

Inherits MovingObject, scripting::Player, and ScriptInterface.

List of all members.

Public Types

enum  FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }

Public Member Functions

void set_speedlimit (float newlimit)
float get_speedlimit ()
 Player (PlayerStatus *player_status, const std::string &name)
virtual ~Player ()
virtual void expose (HSQUIRRELVM vm, SQInteger table_idx)
virtual void unexpose (HSQUIRRELVM vm, SQInteger table_idx)
void set_controller (Controller *controller)
void set_winning ()
bool is_winning ()
Controllerget_controller ()
void use_scripting_controller (bool use_or_release)
 Uses a scriptable controller for all user input (or restores controls).
void do_scripting_controller (std::string control, bool pressed)
 Instructs the scriptable controller to press or release a button.
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.
virtual void collision_solid (const CollisionHit &hit)
 this function is called when the object collided with something solid
virtual HitResponse collision (GameObject &other, const CollisionHit &hit)
 this function is called when the object collided with any other object
virtual void collision_tile (uint32_t tile_attributes)
 called when tiles with special attributes have been touched
void make_invincible ()
 Make tux invincible for a short amount of time.
bool is_invincible () const
bool is_dying () const
Direction peeking_direction_x () const
Direction peeking_direction_y () const
void kill (bool completely)
 Hurts a player, if completely=true then the player will be killed even if he had grow or fireflower bonus.
void check_bounds ()
void move (const Vector &vector)
virtual bool add_bonus (const std::string &bonus)
 Set tux bonus.
virtual void add_coins (int count)
 Give tux more coins.
virtual int get_coins ()
bool add_bonus (BonusType type, bool animate=false)
 picks up a bonus, taking care not to pick up lesser bonus items than we already have
bool set_bonus (BonusType type, bool animate=false)
 like add_bonus, but can also downgrade the bonus items carried
PlayerStatusget_status ()
void kick ()
void do_cheer ()
 play cheer animation.
void do_duck ()
 duck down if possible.
void do_standup ()
 stand back up if possible.
void do_backflip ()
 do a backflip if possible.
void do_jump (float yspeed)
 jump in the air if possible sensible values for yspeed are negative - unless we want to jump into the ground of course
void add_velocity (const Vector &velocity)
 Adds velocity to the player (be careful when using this).
void add_velocity (const Vector &velocity, const Vector &end_speed)
 Adds velocity to the player until given end speed is reached.
Vector get_velocity ()
 Returns the current velocity of the player.
void bounce (BadGuy &badguy)
bool is_dead () const
bool is_big ()
void set_visible (bool visible)
 Set player visible or invisible.
bool get_visible ()
 returns true if the player is currently visible (that is he was not set invisible by the set_visible method)
bool on_ground ()
Portableget_grabbed_object () const
void stop_grabbing ()
void set_ghost_mode (bool enable)
 Switches ghost mode on/off.
void set_edit_mode (bool enable)
 Switches edit mode on/off.
bool get_ghost_mode ()
 Returns whether ghost mode is currently enabled.
bool adjust_height (float new_height)
 Changes height of bounding box.
void trigger_sequence (std::string sequence_name)
 Orders the current GameSession to start a sequence.
void start_climbing (Climbable &climbable)
 Requests that the player start climbing the given Climbable.
void stop_climbing (Climbable &climbable)
 Requests that the player stop climbing the given Climbable.
Physicget_physic ()
void position_grabbed_object ()
void try_grab ()

Public Attributes

Direction dir
Direction old_dir
float last_ground_y
FallMode fall_mode
bool on_ground_flag
bool jumping
bool can_jump
Timer jump_button_timer
 started when player presses the jump button; runs until Tux jumps or JUMP_GRACE_TIME runs out
bool wants_buttjump
bool does_buttjump
Timer invincible_timer
Timer skidding_timer
Timer safe_timer
Timer kick_timer
Timer shooting_timer
Timer dying_timer
bool growing
Timer backflip_timer
Physic physic
bool visible
Portablegrabbed_object
SpritePtr sprite
 The main sprite representing Tux.
SurfacePtr airarrow
 arrow indicating Tux' position when he's above the camera
Vector floor_normal
bool ghost_mode
 indicates if Tux should float around and through solid objects
bool edit_mode
 indicates if Tux should switch to ghost mode rather than dying
Timer unduck_hurt_timer
 if Tux wants to stand up again after ducking and cannot, this timer is started
Timer idle_timer
unsigned int idle_stage
Climbableclimbing
 Climbable object we are currently climbing, null if none.

Private Member Functions

void handle_input ()
void handle_input_ghost ()
 input handling while in ghost mode
void handle_input_climbing ()
 input handling while climbing
void init ()
void handle_horizontal_input ()
void handle_vertical_input ()
void activate ()
 Give control back to user/scripting.
void deactivate ()
 Deactivate user/scripting input for Tux.
void walk (float speed)
 Make Tux walk.
void do_jump_apex ()
void early_jump_apex ()
void apply_friction ()
 slows Tux down a little, based on where he's standing
 Player (const Player &)
Playeroperator= (const Player &)

Private Attributes

bool deactivated
Controllercontroller
std::auto_ptr< CodeControllerscripting_controller
 This controller is used when the Player is controlled via scripting.
PlayerStatusplayer_status
bool duck
bool dead
bool dying
bool winning
bool backflipping
int backflip_direction
Direction peekingX
Direction peekingY
bool swimming
float speedlimit
Controllerscripting_controller_old
 Saves the old controller while the scripting_controller is used.
bool jump_early_apex
bool on_ice
bool ice_this_frame


Detailed Description

Definition at line 47 of file player.hpp.


Member Enumeration Documentation

enum Player::FallMode

Enumerator:
ON_GROUND 
JUMPING 
TRAMPOLINE_JUMP 
FALLING 

Definition at line 52 of file player.hpp.


Constructor & Destructor Documentation

Player::Player ( PlayerStatus player_status,
const std::string &  name 
)

Definition at line 112 of file player.cpp.

References airarrow, controller, Surface::create(), SpriteManager::create(), g_jk_controller, JoystickKeyboardController::get_main_controller(), IDLE_TIME, idle_timer, init(), SoundManager::preload(), scripting_controller, sound_manager, sprite, sprite_manager, and Timer::start().

00112                                                                   :
00113   deactivated(),
00114   controller(),
00115   scripting_controller(0), 
00116   player_status(_player_status), 
00117   duck(),
00118   dead(),
00119   dying(),
00120   backflipping(),
00121   backflip_direction(),
00122   peekingX(),
00123   peekingY(),
00124   swimming(),
00125   speedlimit(),
00126   scripting_controller_old(0),
00127   jump_early_apex(),
00128   on_ice(),
00129   ice_this_frame(),
00130   dir(),
00131   old_dir(),
00132   last_ground_y(),
00133   fall_mode(),
00134   on_ground_flag(),
00135   jumping(),
00136   can_jump(),
00137   jump_button_timer(), 
00138   wants_buttjump(),
00139   does_buttjump(),
00140   invincible_timer(),
00141   skidding_timer(),
00142   safe_timer(),
00143   kick_timer(),
00144   shooting_timer(),
00145   dying_timer(),
00146   growing(),
00147   backflip_timer(),
00148   physic(),
00149   visible(),
00150   grabbed_object(NULL), 
00151   sprite(),
00152   airarrow(),
00153   floor_normal(),
00154   ghost_mode(false), 
00155   edit_mode(false), 
00156   unduck_hurt_timer(),
00157   idle_timer(),
00158   idle_stage(0),
00159   climbing(0)
00160 {
00161   this->name = name;
00162   controller = g_jk_controller->get_main_controller();
00163   scripting_controller.reset(new CodeController());
00164   // if/when we have complete penny gfx, we can
00165   // load those instead of Tux's sprite in the
00166   // constructor
00167   sprite = sprite_manager->create("images/creatures/tux/tux.sprite");
00168   airarrow = Surface::create("images/engine/hud/airarrow.png");
00169   idle_timer.start(IDLE_TIME[0]/1000.0f);
00170 
00171   sound_manager->preload("sounds/bigjump.wav");
00172   sound_manager->preload("sounds/jump.wav");
00173   sound_manager->preload("sounds/hurt.wav");
00174   sound_manager->preload("sounds/kill.wav");
00175   sound_manager->preload("sounds/skid.wav");
00176   sound_manager->preload("sounds/flip.wav");
00177   sound_manager->preload("sounds/invincible_start.ogg");
00178   sound_manager->preload("sounds/splash.ogg");
00179 
00180   init();
00181 }

Player::~Player (  )  [virtual]

Reimplemented from scripting::Player.

Definition at line 183 of file player.cpp.

References climbing, and stop_climbing().

00184 {
00185   if (climbing) stop_climbing(*climbing);
00186 }

Player::Player ( const Player  )  [private]


Member Function Documentation

void Player::set_speedlimit ( float  newlimit  ) 

Definition at line 255 of file player.cpp.

References speedlimit.

Referenced by EndSequence::start(), and TitleScreen::TitleScreen().

00256 {
00257   speedlimit=newlimit;
00258 }

float Player::get_speedlimit (  ) 

Definition at line 249 of file player.cpp.

References speedlimit.

00250 {
00251   return speedlimit;
00252 }

void Player::expose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 231 of file player.cpp.

References scripting::expose_object(), and GameObject::name.

00232 {
00233   if (name.empty())
00234     return;
00235 
00236   scripting::expose_object(vm, table_idx, dynamic_cast<scripting::Player *>(this), name, false);
00237 }

void Player::unexpose ( HSQUIRRELVM  vm,
SQInteger  table_idx 
) [virtual]

Implements ScriptInterface.

Definition at line 240 of file player.cpp.

References GameObject::name, and scripting::unexpose_object().

00241 {
00242   if (name.empty())
00243     return;
00244 
00245   scripting::unexpose_object(vm, table_idx, name);
00246 }

void Player::set_controller ( Controller controller  ) 

Definition at line 261 of file player.cpp.

References controller.

Referenced by EndSequence::start(), TitleScreen::TitleScreen(), and use_scripting_controller().

00262 {
00263   this->controller = controller;
00264 }

void Player::set_winning (  ) 

Definition at line 267 of file player.cpp.

References invincible_timer, is_winning(), Timer::start(), and winning.

Referenced by GameSession::start_sequence().

00268 {
00269   if( ! is_winning() ){
00270     winning = true;
00271     invincible_timer.start(10000.0f);
00272   }
00273 }

bool Player::is_winning (  )  [inline]

Definition at line 69 of file player.hpp.

References winning.

Referenced by kill(), and set_winning().

00070   {
00071     return winning;
00072   }

Controller* Player::get_controller (  )  [inline]

Definition at line 74 of file player.hpp.

References controller.

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

00075   {
00076     return controller;
00077   }

void Player::use_scripting_controller ( bool  use_or_release  )  [virtual]

Uses a scriptable controller for all user input (or restores controls).

Implements scripting::Player.

Definition at line 276 of file player.cpp.

References controller, get_controller(), scripting_controller, scripting_controller_old, and set_controller().

00277 {
00278   if ((use_or_release == true) && (controller != scripting_controller.get())) {
00279     scripting_controller_old = get_controller();
00280     set_controller(scripting_controller.get());
00281   }
00282   if ((use_or_release == false) && (controller == scripting_controller.get())) {
00283     set_controller(scripting_controller_old);
00284     scripting_controller_old = 0;
00285   }
00286 }

void Player::do_scripting_controller ( std::string  control,
bool  pressed 
) [virtual]

Instructs the scriptable controller to press or release a button.

Implements scripting::Player.

Definition at line 289 of file player.cpp.

References Controller::controlNames, and scripting_controller.

00290 {
00291   for(int i = 0; Controller::controlNames[i] != 0; ++i) {
00292     if(control == std::string(Controller::controlNames[i])) {
00293       scripting_controller->press(Controller::Control(i), pressed);
00294     }
00295   }
00296 }

void Player::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 330 of file player.cpp.

References Sector::add_object(), ANCHOR_MIDDLE, apply_friction(), backflip_direction, backflip_timer, backflipping, MovingObject::bbox, Timer::check(), Sector::current(), deactivated, dead, dir, do_standup(), dying, dying_timer, fall_mode, FALLING, floor_normal, game_time, Physic::get_movement(), MovingObject::get_pos(), Timer::get_timeleft(), Physic::get_velocity_x(), grabbed_object, graphicsRandom, growing, handle_input(), ice_this_frame, invincible_timer, jumping, JUMPING, last_ground_y, LAYER_OBJECTS, LEFT, MAX_WALK_XM, MovingObject::movement, no_water, ON_GROUND, on_ground(), on_ground_flag, on_ice, Rectf::p1, Rectf::p2, physic, position_grabbed_object(), RandomGenerator::rand(), RandomGenerator::randf(), RIGHT, RUNNING_TUX_WIDTH, Physic::set_velocity_x(), Physic::set_velocity_y(), MovingObject::set_width(), sprite, Timer::started(), swimming, TUX_INVINCIBLE_TIME_WARNING, TUX_WIDTH, Portable::ungrab(), Vector::x, and Vector::y.

00331 {
00332   if( no_water ){
00333     swimming = false;
00334   }
00335   no_water = true;
00336 
00337   if(dying && dying_timer.check()) {
00338     dead = true;
00339     return;
00340   }
00341 
00342   if(!dying && !deactivated)
00343     handle_input();
00344 
00345   // handle_input() calls apply_friction() when Tux is not walking, so we'll have to do this ourselves
00346   if (deactivated)
00347     apply_friction();
00348 
00349   // extend/shrink tux collision rectangle so that we fall through/walk over 1
00350   // tile holes
00351   if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) {
00352     set_width(RUNNING_TUX_WIDTH);
00353   } else {
00354     set_width(TUX_WIDTH);
00355   }
00356 
00357   // on downward slopes, adjust vertical velocity so tux walks smoothly down
00358   if (on_ground()) {
00359     if(floor_normal.y != 0) {
00360       if ((floor_normal.x * physic.get_velocity_x()) >= 0) {
00361         physic.set_velocity_y(250);
00362       }
00363     }
00364   }
00365 
00366   // handle backflipping
00367   if (backflipping) {
00368     //prevent player from changing direction when backflipping
00369     dir = (backflip_direction == 1) ? LEFT : RIGHT;
00370     if (backflip_timer.started()) physic.set_velocity_x(100 * backflip_direction);
00371   }
00372 
00373   // set fall mode...
00374   if(on_ground()) {
00375     fall_mode = ON_GROUND;
00376     last_ground_y = get_pos().y;
00377   } else {
00378     if(get_pos().y > last_ground_y)
00379       fall_mode = FALLING;
00380     else if(fall_mode == ON_GROUND)
00381       fall_mode = JUMPING;
00382   }
00383 
00384   // check if we landed
00385   if(on_ground()) {
00386     jumping = false;
00387     if (backflipping && (!backflip_timer.started())) {
00388       backflipping = false;
00389       backflip_direction = 0;
00390 
00391       // if controls are currently deactivated, we take care of standing up ourselves
00392       if (deactivated)
00393         do_standup();
00394     }
00395   }
00396 
00397   // calculate movement for this frame
00398   movement = physic.get_movement(elapsed_time);
00399 
00400   if(grabbed_object != NULL && !dying) {
00401     position_grabbed_object();
00402   }
00403 
00404   if(grabbed_object != NULL && dying){
00405     grabbed_object->ungrab(*this, dir);
00406     grabbed_object = NULL;
00407   }
00408 
00409   if(!ice_this_frame && on_ground())
00410     on_ice = false;
00411 
00412   on_ground_flag = false;
00413   ice_this_frame = false;
00414 
00415   // when invincible, spawn particles
00416   if (invincible_timer.started())
00417   {
00418     if (graphicsRandom.rand(0, 2) == 0) {
00419       float px = graphicsRandom.randf(bbox.p1.x+0, bbox.p2.x-0);
00420       float py = graphicsRandom.randf(bbox.p1.y+0, bbox.p2.y-0);
00421       Vector ppos = Vector(px, py);
00422       Vector pspeed = Vector(0, 0);
00423       Vector paccel = Vector(0, 0);
00424       Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", 
00425                                                        // draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
00426                                                        (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) ?
00427                                                        // make every other a longer sparkle to make trail a bit fuzzy
00428                                                        (size_t(game_time*20)%2) ? "small" : "medium"
00429                                                        :
00430                                                        "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
00431     }
00432   }
00433 
00434   if (growing) {
00435     if (sprite->animation_done()) growing = false;
00436   }
00437 
00438 }

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

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

Implements GameObject.

Definition at line 1035 of file player.cpp.

References airarrow, backflipping, PlayerStatus::bonus, Sector::camera, scripting::camera(), Timer::check(), climbing, Sector::current(), dir, does_buttjump, DrawingContext::draw_surface(), duck, dying, FIRE_BONUS, game_time, MovingObject::get_bbox(), MovingObject::get_pos(), Camera::get_translation(), Physic::get_velocity_x(), growing, GROWUP_BONUS, ICE_BONUS, idle_stage, IDLE_STAGE_COUNT, IDLE_STAGES, IDLE_TIME, idle_timer, is_big(), kick_timer, LAYER_HUD, LAYER_OBJECTS, LEFT, on_ground(), Rectf::p1, Rectf::p2, physic, player_status, safe_timer, skidding_timer, sprite, Timer::start(), Timer::started(), visible, wants_buttjump, Vector::x, and Vector::y.

01036 {
01037   if(!visible)
01038     return;
01039 
01040   // if Tux is above camera, draw little "air arrow" to show where he is x-wise
01041   if (Sector::current() && Sector::current()->camera && (get_bbox().p2.y - 16 < Sector::current()->camera->get_translation().y)) {
01042     float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
01043     float py = Sector::current()->camera->get_translation().y;
01044     py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
01045     context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
01046   }
01047 
01048   std::string sa_prefix = "";
01049   std::string sa_postfix = "";
01050 
01051   if (player_status->bonus == GROWUP_BONUS)
01052     sa_prefix = "big";
01053   else if (player_status->bonus == FIRE_BONUS)
01054     sa_prefix = "fire";
01055   else if (player_status->bonus == ICE_BONUS)
01056     sa_prefix = "ice";
01057   else
01058     sa_prefix = "small";
01059 
01060   if(dir == LEFT)
01061     sa_postfix = "-left";
01062   else
01063     sa_postfix = "-right";
01064 
01065   /* Set Tux sprite action */
01066   if(dying) {
01067     sprite->set_action("gameover");
01068   }
01069   else if (growing) {
01070     sprite->set_action_continued("grow"+sa_postfix);
01071     // while growing, do not change action
01072     // do_duck() will take care of cancelling growing manually
01073     // update() will take care of cancelling when growing completed
01074   }
01075   else if (climbing) {
01076     sprite->set_action(sa_prefix+"-skid"+sa_postfix);
01077   }
01078   else if (backflipping) {
01079     sprite->set_action(sa_prefix+"-backflip"+sa_postfix);
01080   }
01081   else if (duck && is_big()) {
01082     sprite->set_action(sa_prefix+"-duck"+sa_postfix);
01083   }
01084   else if (skidding_timer.started() && !skidding_timer.check()) {
01085     sprite->set_action(sa_prefix+"-skid"+sa_postfix);
01086   }
01087   else if (kick_timer.started() && !kick_timer.check()) {
01088     sprite->set_action(sa_prefix+"-kick"+sa_postfix);
01089   }
01090   else if ((wants_buttjump || does_buttjump) && is_big()) {
01091     sprite->set_action(sa_prefix+"-buttjump"+sa_postfix);
01092   }
01093   else if (!on_ground()) {
01094     sprite->set_action(sa_prefix+"-jump"+sa_postfix);
01095   }
01096   else {
01097     if (fabsf(physic.get_velocity_x()) < 1.0f) {
01098       // Determine which idle stage we're at
01099       if (sprite->get_action().find("-stand-") == std::string::npos && sprite->get_action().find("-idle-") == std::string::npos) {
01100         idle_stage = 0;
01101         idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);
01102 
01103         sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
01104       }
01105       else if (idle_timer.check() || (IDLE_TIME[idle_stage] == 0 && sprite->animation_done())) {
01106         idle_stage++;
01107         if (idle_stage >= IDLE_STAGE_COUNT)
01108           idle_stage = 1;
01109 
01110         idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);
01111 
01112         if (IDLE_TIME[idle_stage] == 0)
01113           sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix, 1);
01114         else
01115           sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
01116       }
01117       else {
01118         sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
01119       }
01120     }
01121     else {
01122       sprite->set_action(sa_prefix+"-walk"+sa_postfix);
01123     }
01124   }
01125 
01126   /*
01127   // Tux is holding something
01128   if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
01129   (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) {
01130   if (duck) {
01131   } else {
01132   }
01133   }
01134   */
01135 
01136   /* Draw Tux */
01137   if (safe_timer.started() && size_t(game_time*40)%2)
01138     ;  // don't draw Tux
01139   else {
01140     sprite->draw(context, get_pos(), LAYER_OBJECTS + 1);
01141   }
01142 
01143 }

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

this function is called when the object collided with something solid

Reimplemented from MovingObject.

Definition at line 1174 of file player.cpp.

References Sector::add_object(), CollisionHit::bottom, Sector::camera, CollisionHit::crush, Sector::current(), does_buttjump, floor_normal, MovingObject::get_bbox(), Physic::get_velocity_y(), kill(), LAYER_OBJECTS, CollisionHit::left, on_ground_flag, physic, CollisionHit::right, Physic::set_velocity_x(), Physic::set_velocity_y(), Camera::shake(), CollisionHit::slope_normal, and CollisionHit::top.

01175 {
01176   if(hit.bottom) {
01177     if(physic.get_velocity_y() > 0)
01178       physic.set_velocity_y(0);
01179 
01180     on_ground_flag = true;
01181     floor_normal = hit.slope_normal;
01182 
01183     // Butt Jump landed    
01184     if (does_buttjump) {
01185       does_buttjump = false;
01186       physic.set_velocity_y(-300);
01187       on_ground_flag = false;
01188       Sector::current()->add_object(new Particles(
01189                                       Vector(get_bbox().p2.x, get_bbox().p2.y),
01190                                       270+20, 270+40,
01191                                       Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
01192                                       LAYER_OBJECTS+1));
01193       Sector::current()->add_object(new Particles(
01194                                       Vector(get_bbox().p1.x, get_bbox().p2.y),
01195                                       90-40, 90-20,
01196                                       Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
01197                                       LAYER_OBJECTS+1));
01198       Sector::current()->camera->shake(.1f, 0, 5);
01199     }
01200 
01201   } else if(hit.top) {
01202     if(physic.get_velocity_y() < 0)
01203       physic.set_velocity_y(.2f);
01204   }
01205 
01206   if(hit.left || hit.right) {
01207     physic.set_velocity_x(0);
01208   }
01209 
01210   // crushed?
01211   if(hit.crush) {
01212     if(hit.left || hit.right) {
01213       kill(true);
01214     } else if(hit.top || hit.bottom) {
01215       kill(false);
01216     }
01217   }
01218 }

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

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

Implements MovingObject.

Definition at line 1221 of file player.cpp.

References ABORT_MOVE, COLGROUP_TOUCHABLE, CONTINUE, controller, TriggerBase::EVENT_ACTIVATE, FORCE_MOVE, MovingObject::get_group(), invincible_timer, CollisionHit::left, Controller::pressed(), CollisionHit::right, safe_timer, Timer::started(), try_grab(), and Controller::UP.

01222 {
01223   Bullet* bullet = dynamic_cast<Bullet*> (&other);
01224   if(bullet) {
01225     return FORCE_MOVE;
01226   }
01227 
01228   Player* player = dynamic_cast<Player*> (&other);
01229   if(player) {
01230     return ABORT_MOVE;
01231   }
01232 
01233   if(hit.left || hit.right) {
01234     try_grab(); //grab objects right now, in update it will be too late
01235   }
01236   assert(dynamic_cast<MovingObject*> (&other) != NULL);
01237   MovingObject* moving_object = static_cast<MovingObject*> (&other);
01238   if(moving_object->get_group() == COLGROUP_TOUCHABLE) {
01239     TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other);
01240     if(trigger) {
01241       if(controller->pressed(Controller::UP))
01242         trigger->event(*this, TriggerBase::EVENT_ACTIVATE);
01243     }
01244 
01245     return FORCE_MOVE;
01246   }
01247 
01248   BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
01249   if(badguy != NULL) {
01250     if(safe_timer.started() || invincible_timer.started())
01251       return FORCE_MOVE;
01252 
01253     return CONTINUE;
01254   }
01255 
01256   return CONTINUE;
01257 }

void Player::collision_tile ( uint32_t  tile_attributes  )  [virtual]

called when tiles with special attributes have been touched

Reimplemented from MovingObject.

Definition at line 1146 of file player.cpp.

References Tile::HURTS, Tile::ICE, ice_this_frame, kill(), no_water, on_ice, SoundManager::play(), sound_manager, swimming, and Tile::WATER.

01147 {
01148   if(tile_attributes & Tile::HURTS)
01149     kill(false);
01150 
01151 #ifdef SWIMMING
01152   if( swimming ){
01153     if( tile_attributes & Tile::WATER ){
01154       no_water = false;
01155     } else {
01156       swimming = false;
01157     }
01158   } else {
01159     if( tile_attributes & Tile::WATER ){
01160       swimming = true;
01161       no_water = false;
01162       sound_manager->play( "sounds/splash.ogg" );
01163     }
01164   }
01165 #endif
01166 
01167   if(tile_attributes & Tile::ICE) {
01168     ice_this_frame = true;
01169     on_ice = true;
01170   }
01171 }

void Player::make_invincible (  )  [virtual]

Make tux invincible for a short amount of time.

Implements scripting::Player.

Definition at line 1260 of file player.cpp.

References Sector::current(), HERRING_MUSIC, invincible_timer, SoundManager::play(), Sector::play_music(), sound_manager, Timer::start(), and TUX_INVINCIBLE_TIME.

Referenced by Star::collision(), and PowerUp::collision().

01261 {
01262   sound_manager->play("sounds/invincible_start.ogg");
01263   invincible_timer.start(TUX_INVINCIBLE_TIME);
01264   Sector::current()->play_music(HERRING_MUSIC);
01265 }

bool Player::is_invincible (  )  const [inline]

Definition at line 89 of file player.hpp.

References invincible_timer, and Timer::started().

Referenced by IceCrusher::collision(), HurtingPlatform::collision(), WillOWisp::collision_player(), Kugelblitz::collision_player(), BadGuy::collision_player(), Snail::collision_squished(), MrIceBlock::collision_squished(), MrBomb::collision_squished(), and Haywire::collision_squished().

00090   {
00091     return invincible_timer.started();
00092   }

bool Player::is_dying (  )  const [inline]

Definition at line 93 of file player.hpp.

References dying.

Referenced by GameSession::on_escape_press(), Camera::update_scroll_autoscroll(), and Camera::update_scroll_normal().

00094   {
00095     return dying;
00096   }

Direction Player::peeking_direction_x (  )  const [inline]

Definition at line 97 of file player.hpp.

References peekingX.

Referenced by Camera::update_scroll_normal().

00098   {
00099     return peekingX;
00100   }

Direction Player::peeking_direction_y (  )  const [inline]

Definition at line 102 of file player.hpp.

References peekingY.

Referenced by Camera::update_scroll_normal().

00103   {
00104     return peekingY;
00105   }

void Player::kill ( bool  completely  )  [virtual]

Hurts a player, if completely=true then the player will be killed even if he had grow or fireflower bonus.

Implements scripting::Player.

Definition at line 1269 of file player.cpp.

References adjust_height(), backflipping, PlayerStatus::bonus, climbing, COLGROUP_DISABLED, Sector::current(), deactivated, duck, dying, dying_timer, edit_mode, Sector::effect, Physic::enable_gravity(), DisplayEffect::fade_out(), FIRE_BONUS, growing, GROWUP_BONUS, ICE_BONUS, invincible_timer, is_big(), is_winning(), NO_BONUS, physic, SoundManager::play(), player_status, safe_timer, Physic::set_acceleration(), set_bonus(), set_ghost_mode(), Physic::set_gravity_modifier(), MovingObject::set_group(), Physic::set_velocity(), Physic::set_velocity_x(), SMALL_TUX_HEIGHT, sound_manager, Timer::start(), Timer::started(), Timer::stop(), stop_climbing(), SoundManager::stop_music(), and TUX_SAFE_TIME.

Referenced by check_bounds(), IceCrusher::collision(), HurtingPlatform::collision(), Explosion::collision(), GhostTree::collision(), Stalactite::collision_player(), Kugelblitz::collision_player(), BadGuy::collision_player(), collision_solid(), collision_tile(), do_standup(), and LevelTime::update().

01270 {
01271   if(dying || deactivated || is_winning() )
01272     return;
01273 
01274   if(!completely && (safe_timer.started() || invincible_timer.started()))
01275     return;
01276 
01277   growing = false;
01278 
01279   if (climbing) stop_climbing(*climbing);
01280 
01281   physic.set_velocity_x(0);
01282 
01283   if(!completely && is_big()) {
01284     sound_manager->play("sounds/hurt.wav");
01285 
01286     if(player_status->bonus == FIRE_BONUS
01287        || player_status->bonus == ICE_BONUS) {
01288       safe_timer.start(TUX_SAFE_TIME);
01289       set_bonus(GROWUP_BONUS, true);
01290     } else if(player_status->bonus == GROWUP_BONUS) {
01291       safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
01292       adjust_height(SMALL_TUX_HEIGHT);
01293       duck = false;
01294       backflipping = false;
01295       set_bonus(NO_BONUS, true);
01296     } else if(player_status->bonus == NO_BONUS) {
01297       safe_timer.start(TUX_SAFE_TIME);
01298       adjust_height(SMALL_TUX_HEIGHT);
01299       duck = false;
01300     }
01301   } else {
01302     sound_manager->play("sounds/kill.wav");
01303 
01304     // do not die when in edit mode
01305     if (edit_mode) {
01306       set_ghost_mode(true);
01307       return;
01308     }
01309 
01310     physic.enable_gravity(true);
01311     physic.set_gravity_modifier(1.0f); // Undo jump_early_apex
01312     safe_timer.stop();
01313     invincible_timer.stop();
01314     physic.set_acceleration(0, 0);
01315     physic.set_velocity(0, -700);
01316     set_bonus(NO_BONUS, true);
01317     dying = true;
01318     dying_timer.start(3.0);
01319     set_group(COLGROUP_DISABLED);
01320 
01321     // TODO: need nice way to handle players dying in co-op mode
01322     Sector::current()->effect->fade_out(3.0);
01323     sound_manager->stop_music(3.0);
01324   }
01325 }

void Player::check_bounds (  ) 

Definition at line 1346 of file player.cpp.

References Sector::current(), MovingObject::get_bbox(), MovingObject::get_pos(), ghost_mode, kill(), and MovingObject::set_pos().

Referenced by Sector::update().

01347 {
01348   /* Keep tux in sector bounds: */
01349   if (get_pos().x < 0) {
01350     // Lock Tux to the size of the level, so that he doesn't fall off
01351     // the left side
01352     set_pos(Vector(0, get_pos().y));
01353   }
01354 
01355   if (get_bbox().get_right() > Sector::current()->get_width()) {
01356     // Lock Tux to the size of the level, so that he doesn't fall off
01357     // the right side
01358     set_pos(Vector(Sector::current()->get_width() - get_bbox().get_width(), get_pos().y));
01359   }
01360 
01361   /* fallen out of the level? */
01362   if ((get_pos().y > Sector::current()->get_height()) && (!ghost_mode)) {
01363     kill(true);
01364     return;
01365   }
01366 }

void Player::move ( const Vector vector  ) 

Definition at line 1328 of file player.cpp.

References backflipping, BIG_TUX_HEIGHT, climbing, duck, is_big(), last_ground_y, physic, Physic::reset(), MovingObject::set_pos(), MovingObject::set_size(), SMALL_TUX_HEIGHT, stop_climbing(), TUX_WIDTH, and Vector::y.

Referenced by FlipLevelTransformer::transform_sector().

01329 {
01330   set_pos(vector);
01331 
01332   // Reset size to get correct hitbox if Tux was eg. ducked before moving
01333   if(is_big())
01334     set_size(TUX_WIDTH, BIG_TUX_HEIGHT);
01335   else
01336     set_size(TUX_WIDTH, SMALL_TUX_HEIGHT);
01337   duck = false;
01338   backflipping = false;
01339   last_ground_y = vector.y;
01340   if (climbing) stop_climbing(*climbing);
01341 
01342   physic.reset();
01343 }

bool Player::add_bonus ( const std::string &  bonus  )  [virtual]

Set tux bonus.

This can be "grow", "fireflower" or "iceflower" at the moment

Implements scripting::Player.

Definition at line 922 of file player.cpp.

References FIRE_BONUS, GROWUP_BONUS, ICE_BONUS, and NO_BONUS.

Referenced by PowerUp::collision(), GrowUp::collision(), and Flower::collision().

00923 {
00924   BonusType type = NO_BONUS;
00925 
00926   if(bonustype == "grow") {
00927     type = GROWUP_BONUS;
00928   } else if(bonustype == "fireflower") {
00929     type = FIRE_BONUS;
00930   } else if(bonustype == "iceflower") {
00931     type = ICE_BONUS;
00932   } else if(bonustype == "none") {
00933     type = NO_BONUS;
00934   } else {
00935     std::ostringstream msg;
00936     msg << "Unknown bonus type "  << bonustype;
00937     throw std::runtime_error(msg.str());
00938   }
00939 
00940   return add_bonus(type);
00941 }

void Player::add_coins ( int  count  )  [virtual]

Give tux more coins.

Implements scripting::Player.

Definition at line 910 of file player.cpp.

References PlayerStatus::add_coins(), and player_status.

Referenced by LevelTime::update().

00911 {
00912   player_status->add_coins(count);
00913 }

int Player::get_coins (  )  [virtual]

Definition at line 916 of file player.cpp.

References PlayerStatus::coins, and player_status.

00917 {
00918   return player_status->coins;
00919 }

bool Player::add_bonus ( BonusType  type,
bool  animate = false 
)

picks up a bonus, taking care not to pick up lesser bonus items than we already have

Returns:
true if the bonus has been set (or was already good enough) false if the bonus could not be set (for example no space for big tux)

Definition at line 944 of file player.cpp.

References PlayerStatus::bonus, FIRE_BONUS, GROWUP_BONUS, ICE_BONUS, NO_BONUS, player_status, and set_bonus().

00945 {
00946   // always ignore NO_BONUS
00947   if (type == NO_BONUS) {
00948     return true;
00949   }
00950 
00951   // ignore GROWUP_BONUS if we're already big
00952   if (type == GROWUP_BONUS) {
00953     if (player_status->bonus == GROWUP_BONUS)
00954       return true;
00955     if (player_status->bonus == FIRE_BONUS)
00956       return true;
00957     if (player_status->bonus == ICE_BONUS)
00958       return true;
00959   }
00960 
00961   return set_bonus(type, animate);
00962 }

bool Player::set_bonus ( BonusType  type,
bool  animate = false 
)

like add_bonus, but can also downgrade the bonus items carried

Definition at line 965 of file player.cpp.

References Sector::add_object(), adjust_height(), ANCHOR_TOP, MovingObject::bbox, BIG_TUX_HEIGHT, PlayerStatus::bonus, climbing, Sector::current(), dir, does_buttjump, FIRE_BONUS, growing, GROWUP_BONUS, ICE_BONUS, LAYER_OBJECTS, LEFT, PlayerStatus::max_fire_bullets, PlayerStatus::max_ice_bullets, NO_BONUS, Rectf::p1, Rectf::p2, player_status, sprite, stop_climbing(), Vector::x, and Vector::y.

Referenced by add_bonus(), and kill().

00966 {
00967   if((player_status->bonus == NO_BONUS) && (type != NO_BONUS)) {
00968     if (!adjust_height(BIG_TUX_HEIGHT)) {
00969       printf("can't adjust\n");
00970       return false;
00971     }
00972     if(animate) {
00973       growing = true;
00974       sprite->set_action((dir == LEFT)?"grow-left":"grow-right", 1);
00975     }
00976     if (climbing) stop_climbing(*climbing);
00977   }
00978 
00979   if (type == NO_BONUS) {
00980     if (does_buttjump) does_buttjump = false;
00981   }
00982 
00983   if ((type == NO_BONUS) || (type == GROWUP_BONUS)) {
00984     if ((player_status->bonus == FIRE_BONUS) && (animate)) {
00985       // visually lose helmet
00986       Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
00987       Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
00988       Vector paccel = Vector(0, 1000);
00989       std::string action = (dir==LEFT)?"left":"right";
00990       Sector::current()->add_object(new SpriteParticle("images/objects/particles/firetux-helmet.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
00991       if (climbing) stop_climbing(*climbing);
00992     }
00993     if ((player_status->bonus == ICE_BONUS) && (animate)) {
00994       // visually lose cap
00995       Vector ppos = Vector((bbox.p1.x + bbox.p2.x) / 2, bbox.p1.y);
00996       Vector pspeed = Vector(((dir==LEFT) ? +100 : -100), -300);
00997       Vector paccel = Vector(0, 1000);
00998       std::string action = (dir==LEFT)?"left":"right";
00999       Sector::current()->add_object(new SpriteParticle("images/objects/particles/icetux-cap.sprite", action, ppos, ANCHOR_TOP, pspeed, paccel, LAYER_OBJECTS-1));
01000       if (climbing) stop_climbing(*climbing);
01001     }
01002     player_status->max_fire_bullets = 0;
01003     player_status->max_ice_bullets = 0;
01004   }
01005   if (type == FIRE_BONUS) player_status->max_fire_bullets++;
01006   if (type == ICE_BONUS) player_status->max_ice_bullets++;
01007 
01008   player_status->bonus = type;
01009   return true;
01010 }

PlayerStatus* Player::get_status (  )  [inline]

Definition at line 127 of file player.hpp.

References player_status.

Referenced by Coin::collect(), PowerUp::collision(), OneUp::collision(), Brick::try_break(), and BonusBlock::try_open().

00128   {
00129     return player_status;
00130   }

void Player::kick (  ) 

Definition at line 1029 of file player.cpp.

References KICK_TIME, kick_timer, and Timer::start().

Referenced by Snail::collision_player(), and MrIceBlock::collision_player().

01030 {
01031   kick_timer.start(KICK_TIME);
01032 }

void Player::do_cheer (  )  [virtual]

play cheer animation.

This might need some space and behave in an unpredictable way. Best to use this at level end.

Implements scripting::Player.

Definition at line 566 of file player.cpp.

References do_backflip(), do_duck(), and do_standup().

00567 {
00568   do_duck();
00569   do_backflip();
00570   do_standup();
00571 }

void Player::do_duck (  )  [virtual]

duck down if possible.

this won't last long as long as input is enabled.

Implements scripting::Player.

Definition at line 574 of file player.cpp.

References adjust_height(), does_buttjump, duck, DUCKED_TUX_HEIGHT, Physic::get_velocity_y(), growing, is_big(), on_ground(), physic, Timer::stop(), and unduck_hurt_timer.

Referenced by do_cheer(), and handle_input().

00574                 {
00575   if (duck)
00576     return;
00577   if (!is_big())
00578     return;
00579 
00580   if (physic.get_velocity_y() != 0)
00581     return;
00582   if (!on_ground())
00583     return;
00584   if (does_buttjump)
00585     return;
00586 
00587   if (adjust_height(DUCKED_TUX_HEIGHT)) {
00588     duck = true;
00589     growing = false;
00590     unduck_hurt_timer.stop();
00591   } else {
00592     // FIXME: what now?
00593   }
00594 }

void Player::do_standup (  )  [virtual]

stand back up if possible.

Implements scripting::Player.

Definition at line 597 of file player.cpp.

References adjust_height(), backflipping, BIG_TUX_HEIGHT, Timer::check(), duck, Timer::get_period(), is_big(), kill(), Timer::start(), Timer::stop(), UNDUCK_HURT_TIME, and unduck_hurt_timer.

Referenced by do_cheer(), handle_input(), and update().

00597                    {
00598   if (!duck)
00599     return;
00600   if (!is_big())
00601     return;
00602   if (backflipping)
00603     return;
00604 
00605   if (adjust_height(BIG_TUX_HEIGHT)) {
00606     duck = false;
00607     unduck_hurt_timer.stop();
00608   } else {
00609     // if timer is not already running, start it.
00610     if (unduck_hurt_timer.get_period() == 0) {
00611       unduck_hurt_timer.start(UNDUCK_HURT_TIME);
00612     }
00613     else if (unduck_hurt_timer.check()) {
00614       kill(false);
00615     }
00616   }
00617 
00618 }

void Player::do_backflip (  )  [virtual]

do a backflip if possible.

Implements scripting::Player.

Definition at line 621 of file player.cpp.

References backflip_direction, backflip_timer, backflipping, dir, do_jump(), duck, LEFT, on_ground(), SoundManager::play(), sound_manager, and Timer::start().

Referenced by do_cheer(), and handle_vertical_input().

00621                     {
00622   if (!duck)
00623     return;
00624   if (!on_ground())
00625     return;
00626 
00627   backflip_direction = (dir == LEFT)?(+1):(-1);
00628   backflipping = true;
00629   do_jump(-580);
00630   sound_manager->play("sounds/flip.wav");
00631   backflip_timer.start(0.15f);
00632 }

void Player::do_jump ( float  yspeed  )  [virtual]

jump in the air if possible sensible values for yspeed are negative - unless we want to jump into the ground of course

Implements scripting::Player.

Definition at line 635 of file player.cpp.

References can_jump, is_big(), jumping, on_ground(), on_ground_flag, physic, SoundManager::play(), Physic::set_velocity_y(), and sound_manager.

Referenced by do_backflip(), handle_vertical_input(), and stop_climbing().

00635                             {
00636   if (!on_ground())
00637     return;
00638 
00639   physic.set_velocity_y(yspeed);
00640   //bbox.move(Vector(0, -1));
00641   jumping = true;
00642   on_ground_flag = false;
00643   can_jump = false;
00644 
00645   // play sound
00646   if (is_big()) {
00647     sound_manager->play("sounds/bigjump.wav");
00648   } else {
00649     sound_manager->play("sounds/jump.wav");
00650   }
00651 }

void Player::add_velocity ( const Vector velocity  ) 

Adds velocity to the player (be careful when using this).

Definition at line 1369 of file player.cpp.

References Physic::get_velocity(), physic, and Physic::set_velocity().

Referenced by Wind::collision(), and Explosion::explode().

01370 {
01371   physic.set_velocity(physic.get_velocity() + velocity);
01372 }

void Player::add_velocity ( const Vector velocity,
const Vector end_speed 
)

Adds velocity to the player until given end speed is reached.

Definition at line 1375 of file player.cpp.

References Physic::get_velocity_x(), Physic::get_velocity_y(), physic, Physic::set_velocity_x(), Physic::set_velocity_y(), Vector::x, and Vector::y.

01376 {
01377   if (end_speed.x > 0)
01378     physic.set_velocity_x(std::min(physic.get_velocity_x() + velocity.x, end_speed.x));
01379   if (end_speed.x < 0)
01380     physic.set_velocity_x(std::max(physic.get_velocity_x() + velocity.x, end_speed.x));
01381   if (end_speed.y > 0)
01382     physic.set_velocity_y(std::min(physic.get_velocity_y() + velocity.y, end_speed.y));
01383   if (end_speed.y < 0)
01384     physic.set_velocity_y(std::max(physic.get_velocity_y() + velocity.y, end_speed.y));
01385 }

Vector Player::get_velocity (  ) 

Returns the current velocity of the player.

Definition at line 1388 of file player.cpp.

References Physic::get_velocity(), and physic.

01389 {
01390   return physic.get_velocity();
01391 }

void Player::bounce ( BadGuy badguy  ) 

Definition at line 1394 of file player.cpp.

References controller, Controller::hold(), Controller::JUMP, physic, and Physic::set_velocity_y().

Referenced by ShortFuse::collision_player(), Totem::collision_squished(), Stumpy::collision_squished(), Snowman::collision_squished(), Snail::collision_squished(), SkyDive::collision_squished(), ShortFuse::collision_squished(), Owl::collision_squished(), MrTree::collision_squished(), MrIceBlock::collision_squished(), MrBomb::collision_squished(), Haywire::collision_squished(), Dispenser::collision_squished(), Yeti::kill_squished(), and BadGuy::kill_squished().

01395 {
01396   if(controller->hold(Controller::JUMP))
01397     physic.set_velocity_y(-520);
01398   else
01399     physic.set_velocity_y(-300);
01400 }

bool Player::is_dead (  )  const [inline]

Definition at line 179 of file player.hpp.

References dead.

Referenced by GameSession::check_end_conditions().

00180   { return dead; }

bool Player::is_big (  ) 

Definition at line 447 of file player.cpp.

References PlayerStatus::bonus, NO_BONUS, and player_status.

Referenced by PneumaticPlatform::collision(), BicyclePlatform::collision(), do_duck(), do_jump(), do_standup(), draw(), handle_vertical_input(), init(), kill(), and move().

00448 {
00449   if(player_status->bonus == NO_BONUS)
00450     return false;
00451 
00452   return true;
00453 }

void Player::set_visible ( bool  visible  )  [virtual]

Set player visible or invisible.

Implements scripting::Player.

Definition at line 1013 of file player.cpp.

References COLGROUP_DISABLED, COLGROUP_MOVING, and MovingObject::set_group().

01014 {
01015   this->visible = visible;
01016   if( visible )
01017     set_group(COLGROUP_MOVING);
01018   else
01019     set_group(COLGROUP_DISABLED);
01020 }

bool Player::get_visible (  )  [virtual]

returns true if the player is currently visible (that is he was not set invisible by the set_visible method)

Implements scripting::Player.

Definition at line 1023 of file player.cpp.

References visible.

01024 {
01025   return visible;
01026 }

bool Player::on_ground (  ) 

Definition at line 441 of file player.cpp.

References on_ground_flag.

Referenced by apply_friction(), Wind::collision(), do_backflip(), do_duck(), do_jump(), draw(), handle_horizontal_input(), handle_input(), handle_vertical_input(), TitleScreen::make_tux_jump(), and update().

00442 {
00443   return on_ground_flag;
00444 }

Portable* Player::get_grabbed_object (  )  const [inline]

Definition at line 188 of file player.hpp.

References grabbed_object.

Referenced by PneumaticPlatform::collision(), BicyclePlatform::collision(), and Climbable::event().

00189   {
00190     return grabbed_object;
00191   }

void Player::stop_grabbing (  )  [inline]

Definition at line 192 of file player.hpp.

References grabbed_object.

Referenced by Bomb::explode().

00193   {
00194     grabbed_object = NULL;
00195   }

void Player::set_ghost_mode ( bool  enable  )  [virtual]

Switches ghost mode on/off.

Lets Tux float around and through solid objects.

Implements scripting::Player.

Definition at line 1431 of file player.cpp.

References climbing, COLGROUP_DISABLED, COLGROUP_MOVING, Physic::enable_gravity(), ghost_mode, log_debug, physic, MovingObject::set_group(), and stop_climbing().

Referenced by handle_input_ghost(), and kill().

01432 {
01433   if (ghost_mode == enable)
01434     return;
01435 
01436   if (climbing) stop_climbing(*climbing);
01437 
01438   if (enable) {
01439     ghost_mode = true;
01440     set_group(COLGROUP_DISABLED);
01441     physic.enable_gravity(false);
01442     log_debug << "You feel lightheaded. Use movement controls to float around, press ACTION to scare badguys." << std::endl;
01443   } else {
01444     ghost_mode = false;
01445     set_group(COLGROUP_MOVING);
01446     physic.enable_gravity(true);
01447     log_debug << "You feel solid again." << std::endl;
01448   }
01449 }

void Player::set_edit_mode ( bool  enable  ) 

Switches edit mode on/off.

In edit mode, Tux will enter ghost_mode instead of dying.

Definition at line 1452 of file player.cpp.

References edit_mode.

01453 {
01454   edit_mode = enable;
01455 }

bool Player::get_ghost_mode (  )  [inline, virtual]

Returns whether ghost mode is currently enabled.

Implements scripting::Player.

Definition at line 212 of file player.hpp.

References ghost_mode.

00212 { return ghost_mode; }

bool Player::adjust_height ( float  new_height  ) 

Changes height of bounding box.

Returns true if successful, false otherwise

Definition at line 299 of file player.cpp.

References MovingObject::bbox, Sector::current(), Rectf::get_height(), Rectf::get_width(), Rectf::move(), Rectf::p1, Rectf::set_height(), MovingObject::set_pos(), and MovingObject::set_size().

Referenced by do_duck(), do_standup(), kill(), and set_bonus().

00300 {
00301   Rectf bbox2 = bbox;
00302   bbox2.move(Vector(0, bbox.get_height() - new_height));
00303   bbox2.set_height(new_height);
00304 
00305 
00306   if(new_height > bbox.get_height()) {
00307     Rectf additional_space = bbox2;
00308     additional_space.set_height(new_height - bbox.get_height());
00309     if(!Sector::current()->is_free_of_statics(additional_space, this, true))
00310       return false;
00311   }
00312 
00313   // adjust bbox accordingly
00314   // note that we use members of moving_object for this, so we can run this during CD, too
00315   set_pos(bbox2.p1);
00316   set_size(bbox2.get_width(), bbox2.get_height());
00317   return true;
00318 }

void Player::trigger_sequence ( std::string  sequence_name  )  [virtual]

Orders the current GameSession to start a sequence.

Implements scripting::Player.

Definition at line 321 of file player.cpp.

References backflip_direction, backflipping, climbing, Currenton< GameSession >::current(), GameSession::start_sequence(), and stop_climbing().

Referenced by SequenceTrigger::event().

00322 {
00323   if (climbing) stop_climbing(*climbing);
00324   backflipping = false;
00325   backflip_direction = 0;
00326   GameSession::current()->start_sequence(sequence_name);
00327 }

void Player::start_climbing ( Climbable climbable  ) 

Requests that the player start climbing the given Climbable.

Definition at line 1458 of file player.cpp.

References climbing, Physic::enable_gravity(), physic, Physic::set_acceleration(), and Physic::set_velocity().

Referenced by Climbable::event().

01459 {
01460   if (climbing == &climbable) return;
01461 
01462   climbing = &climbable;
01463   physic.enable_gravity(false);
01464   physic.set_velocity(0, 0);
01465   physic.set_acceleration(0, 0);
01466 }

void Player::stop_climbing ( Climbable climbable  ) 

Requests that the player stop climbing the given Climbable.

Definition at line 1469 of file player.cpp.

References climbing, controller, dir, do_jump(), Physic::enable_gravity(), grabbed_object, Controller::hold(), Controller::JUMP, on_ground_flag, physic, Physic::set_acceleration(), Physic::set_velocity(), Portable::ungrab(), and Controller::UP.

Referenced by deactivate(), Climbable::event(), handle_input_climbing(), kill(), move(), set_bonus(), set_ghost_mode(), trigger_sequence(), try_grab(), Climbable::update(), Climbable::~Climbable(), and ~Player().

01470 {
01471   if (!climbing) return;
01472 
01473   climbing = 0;
01474 
01475   if (grabbed_object) {    
01476     grabbed_object->ungrab(*this, dir);
01477     grabbed_object = NULL;
01478   }
01479 
01480   physic.enable_gravity(true);
01481   physic.set_velocity(0, 0);
01482   physic.set_acceleration(0, 0);
01483 
01484   if ((controller->hold(Controller::JUMP)) || (controller->hold(Controller::UP))) {
01485     on_ground_flag = true;
01486     // TODO: This won't help. Why?
01487     do_jump(-300);
01488   }
01489 }

Physic& Player::get_physic (  )  [inline]

Definition at line 235 of file player.hpp.

References physic.

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

00235 { return physic; }

void Player::handle_input (  )  [private]

Definition at line 734 of file player.cpp.

References Controller::ACTION, Sector::add_bullet(), AUTO, backflipping, MovingObject::bbox, PlayerStatus::bonus, can_jump, climbing, controller, Sector::current(), MovingObject::dest, dir, do_duck(), do_standup(), Controller::DOWN, DOWN, FIRE_BONUS, Rectf::get_height(), Rectf::get_left(), MovingObject::get_pos(), Rectf::get_right(), Rectf::get_top(), Physic::get_velocity_x(), Rectf::get_width(), ghost_mode, grabbed_object, handle_horizontal_input(), handle_input_climbing(), handle_input_ghost(), handle_vertical_input(), Controller::hold(), ICE_BONUS, jumping, LEFT, log_debug, on_ground(), Rectf::p1, Rectf::p2, Controller::PEEK_DOWN, Controller::PEEK_LEFT, Controller::PEEK_RIGHT, Controller::PEEK_UP, peekingX, peekingY, physic, player_status, Controller::pressed(), Controller::released(), RIGHT, SHOOTING_TIME, shooting_timer, Timer::start(), try_grab(), Controller::UP, UP, Vector::x, and Vector::y.

Referenced by update().

00735 {
00736   if (ghost_mode) {
00737     handle_input_ghost();
00738     return;
00739   }
00740   if (climbing) {
00741     handle_input_climbing();
00742     return;
00743   }
00744 
00745   /* Peeking */
00746   if( controller->released( Controller::PEEK_LEFT ) || controller->released( Controller::PEEK_RIGHT ) ) {
00747     peekingX = AUTO;
00748   }
00749   if( controller->released( Controller::PEEK_UP ) || controller->released( Controller::PEEK_DOWN ) ) {
00750     peekingY = AUTO;
00751   }
00752   if( controller->pressed( Controller::PEEK_LEFT ) ) {
00753     peekingX = LEFT;
00754   }
00755   if( controller->pressed( Controller::PEEK_RIGHT ) ) {
00756     peekingX = RIGHT;
00757   }
00758   if(!backflipping && !jumping && on_ground()) {
00759     if( controller->pressed( Controller::PEEK_UP ) ) {
00760       peekingY = UP;
00761     } else if( controller->pressed( Controller::PEEK_DOWN ) ) {
00762       peekingY = DOWN;
00763     }
00764   }
00765 
00766   /* Handle horizontal movement: */
00767   if (!backflipping) handle_horizontal_input();
00768 
00769   /* Jump/jumping? */
00770   if (on_ground())
00771     can_jump = true;
00772 
00773   /* Handle vertical movement: */
00774   handle_vertical_input();
00775 
00776   /* Shoot! */
00777   if (controller->pressed(Controller::ACTION) && (player_status->bonus == FIRE_BONUS || player_status->bonus == ICE_BONUS)) {
00778     if(Sector::current()->add_bullet(
00779          get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2)
00780                       : Vector(32, bbox.get_height()/2)),
00781          player_status,
00782          physic.get_velocity_x(), dir))
00783       shooting_timer.start(SHOOTING_TIME);
00784   }
00785 
00786   /* Duck or Standup! */
00787   if (controller->hold(Controller::DOWN)) {
00788     do_duck();
00789   } else {
00790     do_standup();
00791   }
00792 
00793   /* grabbing */
00794   try_grab();
00795 
00796   if(!controller->hold(Controller::ACTION) && grabbed_object) {
00797     MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
00798     if(moving_object) {
00799       // move the grabbed object a bit away from tux
00800       Rectf grabbed_bbox = moving_object->get_bbox();
00801       Rectf dest;
00802       dest.p2.y = bbox.get_top() + bbox.get_height()*0.66666;
00803       dest.p1.y = dest.p2.y - grabbed_bbox.get_height();
00804       if(dir == LEFT) {
00805         dest.p2.x = bbox.get_left() - 1;
00806         dest.p1.x = dest.p2.x - grabbed_bbox.get_width();
00807       } else {
00808         dest.p1.x = bbox.get_right() + 1;
00809         dest.p2.x = dest.p1.x + grabbed_bbox.get_width();
00810       }
00811       if(Sector::current()->is_free_of_movingstatics(dest)) {
00812         moving_object->set_pos(dest.p1);
00813         if(controller->hold(Controller::UP)) {
00814           grabbed_object->ungrab(*this, UP);
00815         } else {
00816           grabbed_object->ungrab(*this, dir);
00817         }
00818         grabbed_object = NULL;
00819       }
00820     } else {
00821       log_debug << "Non MovingObject grabbed?!?" << std::endl;
00822     }
00823   }
00824 }

void Player::handle_input_ghost (  )  [private]

input handling while in ghost mode

Definition at line 884 of file player.cpp.

References Controller::ACTION, controller, dir, Controller::DOWN, Controller::hold(), Controller::JUMP, LEFT, Controller::LEFT, MAX_RUN_XM, physic, RIGHT, Controller::RIGHT, Physic::set_acceleration(), set_ghost_mode(), Physic::set_velocity(), and Controller::UP.

Referenced by handle_input().

00885 {
00886   float vx = 0;
00887   float vy = 0;
00888   if (controller->hold(Controller::LEFT)) {
00889     dir = LEFT;
00890     vx -= MAX_RUN_XM * 2;
00891   }
00892   if (controller->hold(Controller::RIGHT)) {
00893     dir = RIGHT;
00894     vx += MAX_RUN_XM * 2;
00895   }
00896   if ((controller->hold(Controller::UP)) || (controller->hold(Controller::JUMP))) {
00897     vy -= MAX_RUN_XM * 2;
00898   }
00899   if (controller->hold(Controller::DOWN)) {
00900     vy += MAX_RUN_XM * 2;
00901   }
00902   if (controller->hold(Controller::ACTION)) {
00903     set_ghost_mode(false);
00904   }
00905   physic.set_velocity(vx, vy);
00906   physic.set_acceleration(0, 0);
00907 }

void Player::handle_input_climbing (  )  [private]

input handling while climbing

Definition at line 1492 of file player.cpp.

References Controller::ACTION, can_jump, climbing, controller, dir, Controller::DOWN, Controller::hold(), Controller::JUMP, LEFT, Controller::LEFT, log_warning, MAX_CLIMB_XM, MAX_CLIMB_YM, physic, RIGHT, Controller::RIGHT, Physic::set_acceleration(), Physic::set_velocity(), stop_climbing(), and Controller::UP.

Referenced by handle_input().

01493 {
01494   if (!climbing) {
01495     log_warning << "handle_input_climbing called with climbing set to 0. Input handling skipped" << std::endl;
01496     return;
01497   }
01498 
01499   float vx = 0;
01500   float vy = 0;
01501   if (controller->hold(Controller::LEFT)) {
01502     dir = LEFT;
01503     vx -= MAX_CLIMB_XM;
01504   }
01505   if (controller->hold(Controller::RIGHT)) {
01506     dir = RIGHT;
01507     vx += MAX_CLIMB_XM;
01508   }
01509   if (controller->hold(Controller::UP)) {
01510     vy -= MAX_CLIMB_YM;
01511   }
01512   if (controller->hold(Controller::DOWN)) {
01513     vy += MAX_CLIMB_YM;
01514   }
01515   if (controller->hold(Controller::JUMP)) {
01516     if (can_jump) {
01517       stop_climbing(*climbing);
01518       return;
01519     }  
01520   } else {
01521     can_jump = true;
01522   }
01523   if (controller->hold(Controller::ACTION)) {
01524     stop_climbing(*climbing);
01525     return;
01526   }
01527   physic.set_velocity(vx, vy);
01528   physic.set_acceleration(0, 0);
01529 }

void Player::init (  )  [private]

Definition at line 189 of file player.cpp.

References AUTO, backflip_direction, backflipping, BIG_TUX_HEIGHT, can_jump, climbing, deactivated, dead, dir, does_buttjump, duck, dying, fall_mode, grabbed_object, growing, ice_this_frame, is_big(), jump_early_apex, jumping, last_ground_y, old_dir, ON_GROUND, on_ground_flag, on_ice, peekingX, peekingY, physic, Physic::reset(), RIGHT, MovingObject::set_size(), SMALL_TUX_HEIGHT, speedlimit, swimming, TUX_WIDTH, visible, wants_buttjump, and winning.

Referenced by Player().

00190 {
00191   if(is_big())
00192     set_size(TUX_WIDTH, BIG_TUX_HEIGHT);
00193   else
00194     set_size(TUX_WIDTH, SMALL_TUX_HEIGHT);
00195 
00196   dir = RIGHT;
00197   old_dir = dir;
00198   duck = false;
00199   dead = false;
00200 
00201   dying = false;
00202   winning = false;
00203   peekingX = AUTO;
00204   peekingY = AUTO;
00205   last_ground_y = 0;
00206   fall_mode = ON_GROUND;
00207   jumping = false;
00208   jump_early_apex = false;
00209   can_jump = true;
00210   wants_buttjump = false;
00211   does_buttjump = false;
00212   growing = false;
00213   deactivated = false;
00214   backflipping = false;
00215   backflip_direction = 0;
00216   visible = true;
00217   swimming = false;
00218   on_ice = false;
00219   ice_this_frame = false;
00220   speedlimit = 0; //no special limit
00221 
00222   on_ground_flag = false;
00223   grabbed_object = NULL;
00224 
00225   climbing = 0;
00226 
00227   physic.reset();
00228 }

void Player::handle_horizontal_input (  )  [private]

Definition at line 472 of file player.cpp.

References Sector::add_object(), apply_friction(), controller, Sector::current(), dir, duck, Physic::get_acceleration_x(), Physic::get_acceleration_y(), MovingObject::get_bbox(), Physic::get_velocity_x(), Physic::get_velocity_y(), grabbed_object, Controller::hold(), ICE_ACCELERATION_MULTIPLIER, Portable::is_hampering(), LAYER_OBJECTS, LEFT, Controller::LEFT, MAX_RUN_XM, MAX_WALK_XM, old_dir, on_ground(), on_ice, physic, SoundManager::play(), RIGHT, Controller::RIGHT, RUN_ACCELERATION_X, Physic::set_acceleration(), Physic::set_velocity(), SKID_TIME, SKID_XM, skidding_timer, sound_manager, speedlimit, Timer::start(), Timer::started(), WALK_ACCELERATION_X, and WALK_SPEED.

Referenced by handle_input().

00473 {
00474   float vx = physic.get_velocity_x();
00475   float vy = physic.get_velocity_y();
00476   float ax = physic.get_acceleration_x();
00477   float ay = physic.get_acceleration_y();
00478 
00479   float dirsign = 0;
00480   if(!duck || physic.get_velocity_y() != 0) {
00481     if(controller->hold(Controller::LEFT) && !controller->hold(Controller::RIGHT)) {
00482       old_dir = dir;
00483       dir = LEFT;
00484       dirsign = -1;
00485     } else if(!controller->hold(Controller::LEFT)
00486               && controller->hold(Controller::RIGHT)) {
00487       old_dir = dir;
00488       dir = RIGHT;
00489       dirsign = 1;
00490     }
00491   }
00492 
00493   // do not run if we're holding something which slows us down
00494   if ( grabbed_object && grabbed_object->is_hampering() ) {
00495     ax = dirsign * WALK_ACCELERATION_X;
00496     // limit speed
00497     if(vx >= MAX_WALK_XM && dirsign > 0) {
00498       vx = MAX_WALK_XM;
00499       ax = 0;
00500     } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
00501       vx = -MAX_WALK_XM;
00502       ax = 0;
00503     }
00504   } else {
00505     if( vx * dirsign < MAX_WALK_XM ) {
00506       ax = dirsign * WALK_ACCELERATION_X;
00507     } else {
00508       ax = dirsign * RUN_ACCELERATION_X;
00509     }
00510     // limit speed
00511     if(vx >= MAX_RUN_XM && dirsign > 0) {
00512       vx = MAX_RUN_XM;
00513       ax = 0;
00514     } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
00515       vx = -MAX_RUN_XM;
00516       ax = 0;
00517     }
00518   }
00519 
00520   // we can reach WALK_SPEED without any acceleration
00521   if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
00522     vx = dirsign * WALK_SPEED;
00523   }
00524 
00525   //Check speedlimit.
00526   if( speedlimit > 0 &&  vx * dirsign >= speedlimit ) {
00527     vx = dirsign * speedlimit;
00528     ax = 0;
00529   }
00530 
00531   // changing directions?
00532   if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
00533     // let's skid!
00534     if(fabs(vx)>SKID_XM && !skidding_timer.started()) {
00535       skidding_timer.start(SKID_TIME);
00536       sound_manager->play("sounds/skid.wav");
00537       // dust some particles
00538       Sector::current()->add_object(
00539         new Particles(
00540           Vector(dir == RIGHT ? get_bbox().p2.x : get_bbox().p1.x, get_bbox().p2.y),
00541           dir == RIGHT ? 270+20 : 90-40, dir == RIGHT ? 270+40 : 90-20,
00542           Vector(280, -260), Vector(0, 300), 3, Color(.4f, .4f, .4f), 3, .8f,
00543           LAYER_OBJECTS+1));
00544 
00545       ax *= 2.5;
00546     } else {
00547       ax *= 2;
00548     }
00549   }
00550 
00551   if(on_ice) {
00552     ax *= ICE_ACCELERATION_MULTIPLIER;
00553   }
00554 
00555   physic.set_velocity(vx, vy);
00556   physic.set_acceleration(ax, ay);
00557 
00558   // we get slower when not pressing any keys
00559   if(dirsign == 0) {
00560     apply_friction();
00561   }
00562 
00563 }

void Player::handle_vertical_input (  )  [private]

Definition at line 674 of file player.cpp.

References backflipping, BUTTJUMP_MIN_VELOCITY_Y, can_jump, controller, do_backflip(), do_jump(), do_jump_apex(), does_buttjump, Controller::DOWN, duck, early_jump_apex(), Physic::get_velocity_x(), Physic::get_velocity_y(), Controller::hold(), is_big(), Controller::JUMP, jump_button_timer, jump_early_apex, JUMP_GRACE_TIME, jumping, Controller::LEFT, MAX_WALK_XM, on_ground(), physic, Controller::pressed(), Controller::RIGHT, Physic::set_acceleration_y(), Physic::set_velocity_y(), Timer::start(), Timer::started(), Timer::stop(), swimming, Controller::UP, and wants_buttjump.

Referenced by handle_input().

00675 {
00676   // Press jump key
00677   if(controller->pressed(Controller::JUMP)) jump_button_timer.start(JUMP_GRACE_TIME);
00678   if(controller->hold(Controller::JUMP) && jump_button_timer.started() && can_jump) {
00679     jump_button_timer.stop();
00680     if (duck) {
00681       // when running, only jump a little bit; else do a backflip
00682       if ((physic.get_velocity_x() != 0) || 
00683           (controller->hold(Controller::LEFT)) || 
00684           (controller->hold(Controller::RIGHT))) 
00685       {
00686         do_jump(-300);
00687       }
00688       else 
00689       {
00690         do_backflip();
00691       }
00692     } else {
00693       // jump a bit higher if we are running; else do a normal jump
00694       if (fabs(physic.get_velocity_x()) > MAX_WALK_XM) do_jump(-580); else do_jump(-520);
00695     }
00696   }
00697   // Let go of jump key
00698   else if(!controller->hold(Controller::JUMP)) {
00699     if (!backflipping && jumping && physic.get_velocity_y() < 0) {
00700       jumping = false;
00701       early_jump_apex();
00702     }
00703   }
00704 
00705   if(jump_early_apex && physic.get_velocity_y() >= 0) {
00706     do_jump_apex();
00707   }
00708 
00709   /* In case the player has pressed Down while in a certain range of air,
00710      enable butt jump action */
00711   if (controller->hold(Controller::DOWN) && !duck && is_big() && !on_ground()) {
00712     wants_buttjump = true;
00713     if (physic.get_velocity_y() >= BUTTJUMP_MIN_VELOCITY_Y) does_buttjump = true;
00714   }
00715 
00716   /* When Down is not held anymore, disable butt jump */
00717   if(!controller->hold(Controller::DOWN)) {
00718     wants_buttjump = false;
00719     does_buttjump = false;
00720   }
00721 
00722   // swimming
00723   physic.set_acceleration_y(0);
00724 #ifdef SWIMMING
00725   if (swimming) {
00726     if (controller->hold(Controller::UP) || controller->hold(Controller::JUMP))
00727       physic.set_acceleration_y(-2000);
00728     physic.set_velocity_y(physic.get_velocity_y() * 0.94);
00729   }
00730 #endif
00731 }

void Player::activate (  )  [private, virtual]

Give control back to user/scripting.

Implements scripting::Player.

Definition at line 1418 of file player.cpp.

References deactivated.

01419 {
01420   if (!deactivated)
01421     return;
01422   deactivated = false;
01423 }

void Player::deactivate (  )  [private, virtual]

Deactivate user/scripting input for Tux.

Implements scripting::Player.

Definition at line 1405 of file player.cpp.

References climbing, deactivated, physic, Physic::set_acceleration_x(), Physic::set_acceleration_y(), Physic::set_velocity_x(), Physic::set_velocity_y(), and stop_climbing().

01406 {
01407   if (deactivated)
01408     return;
01409   deactivated = true;
01410   physic.set_velocity_x(0);
01411   physic.set_velocity_y(0);
01412   physic.set_acceleration_x(0);
01413   physic.set_acceleration_y(0);
01414   if (climbing) stop_climbing(*climbing);
01415 }

void Player::walk ( float  speed  )  [private, virtual]

Make Tux walk.

Implements scripting::Player.

Definition at line 1425 of file player.cpp.

References physic, and Physic::set_velocity_x().

01426 {
01427   physic.set_velocity_x(speed);
01428 }

void Player::do_jump_apex (  )  [private]

Definition at line 664 of file player.cpp.

References jump_early_apex, physic, and Physic::set_gravity_modifier().

Referenced by handle_vertical_input().

00665 {
00666   if (jump_early_apex)
00667   {
00668     jump_early_apex = false;
00669     physic.set_gravity_modifier(1.0f);
00670   }
00671 }

void Player::early_jump_apex (  )  [private]

Definition at line 654 of file player.cpp.

References jump_early_apex, JUMP_EARLY_APEX_FACTOR, physic, and Physic::set_gravity_modifier().

Referenced by handle_vertical_input().

00655 {
00656   if (!jump_early_apex)
00657   {
00658     jump_early_apex = true;
00659     physic.set_gravity_modifier(JUMP_EARLY_APEX_FACTOR);
00660   }
00661 }

void Player::apply_friction (  )  [private]

slows Tux down a little, based on where he's standing

Definition at line 456 of file player.cpp.

References Physic::get_velocity_x(), ICE_FRICTION_MULTIPLIER, NORMAL_FRICTION_MULTIPLIER, on_ground(), on_ice, physic, Physic::set_acceleration_x(), Physic::set_velocity_x(), WALK_ACCELERATION_X, and WALK_SPEED.

Referenced by handle_horizontal_input(), and update().

00457 {
00458   if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) {
00459     physic.set_velocity_x(0);
00460     physic.set_acceleration_x(0);
00461   } else {
00462     float friction = WALK_ACCELERATION_X * (on_ice ? ICE_FRICTION_MULTIPLIER : NORMAL_FRICTION_MULTIPLIER);
00463     if(physic.get_velocity_x() < 0) {
00464       physic.set_acceleration_x(friction);
00465     } else if(physic.get_velocity_x() > 0) {
00466       physic.set_acceleration_x(-friction);
00467     } // no friction for physic.get_velocity_x() == 0
00468   }
00469 }

void Player::position_grabbed_object (  ) 

Definition at line 827 of file player.cpp.

References dir, MovingObject::get_bbox(), Rectf::get_height(), Rectf::get_width(), Portable::grab(), grabbed_object, LEFT, Vector::x, and Vector::y.

Referenced by try_grab(), and update().

00828 {
00829   MovingObject* moving_object = dynamic_cast<MovingObject*>(grabbed_object);
00830   assert(moving_object);
00831 
00832   // Position where we will hold the lower-inner corner
00833   Vector pos(get_bbox().get_left() + get_bbox().get_width()/2,
00834       get_bbox().get_top() + get_bbox().get_height()*0.66666);
00835 
00836   // Adjust to find the grabbed object's upper-left corner
00837   if (dir == LEFT)
00838     pos.x -= moving_object->get_bbox().get_width();
00839   pos.y -= moving_object->get_bbox().get_height();
00840 
00841   grabbed_object->grab(*this, pos, dir);
00842 }

void Player::try_grab (  ) 

Definition at line 845 of file player.cpp.

References Controller::ACTION, MovingObject::bbox, climbing, COLGROUP_DISABLED, Rectf::contains(), controller, Sector::current(), dir, duck, MovingObject::get_bbox(), Rectf::get_bottom(), MovingObject::get_group(), Rectf::get_left(), Rectf::get_right(), grabbed_object, Controller::hold(), LEFT, position_grabbed_object(), and stop_climbing().

Referenced by collision(), and handle_input().

00846 {
00847   if(controller->hold(Controller::ACTION) && !grabbed_object
00848      && !duck) {
00849     Sector* sector = Sector::current();
00850     Vector pos;
00851     if(dir == LEFT) {
00852       pos = Vector(bbox.get_left() - 5, bbox.get_bottom() - 16);
00853     } else {
00854       pos = Vector(bbox.get_right() + 5, bbox.get_bottom() - 16);
00855     }
00856 
00857     for(Sector::Portables::iterator i = sector->portables.begin();
00858         i != sector->portables.end(); ++i) {
00859       Portable* portable = *i;
00860       if(!portable->is_portable())
00861         continue;
00862 
00863       // make sure the Portable is a MovingObject
00864       MovingObject* moving_object = dynamic_cast<MovingObject*> (portable);
00865       assert(moving_object);
00866       if(moving_object == NULL)
00867         continue;
00868 
00869       // make sure the Portable isn't currently non-solid
00870       if(moving_object->get_group() == COLGROUP_DISABLED) continue;
00871 
00872       // check if we are within reach
00873       if(moving_object->get_bbox().contains(pos)) {
00874         if (climbing) stop_climbing(*climbing);
00875         grabbed_object = portable;
00876         position_grabbed_object();
00877         break;
00878       }
00879     }
00880   }
00881 }

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


Member Data Documentation

bool Player::deactivated [private]

Definition at line 260 of file player.hpp.

Referenced by activate(), deactivate(), init(), kill(), and update().

Controller* Player::controller [private]

Definition at line 262 of file player.hpp.

Referenced by bounce(), collision(), get_controller(), handle_horizontal_input(), handle_input(), handle_input_climbing(), handle_input_ghost(), handle_vertical_input(), Player(), set_controller(), stop_climbing(), try_grab(), and use_scripting_controller().

std::auto_ptr<CodeController> Player::scripting_controller [private]

This controller is used when the Player is controlled via scripting.

Definition at line 263 of file player.hpp.

Referenced by do_scripting_controller(), Player(), and use_scripting_controller().

PlayerStatus* Player::player_status [private]

Definition at line 264 of file player.hpp.

Referenced by add_bonus(), add_coins(), draw(), get_coins(), get_status(), handle_input(), is_big(), kill(), and set_bonus().

bool Player::duck [private]

Definition at line 265 of file player.hpp.

Referenced by do_backflip(), do_duck(), do_standup(), draw(), handle_horizontal_input(), handle_vertical_input(), init(), kill(), move(), and try_grab().

bool Player::dead [private]

Definition at line 266 of file player.hpp.

Referenced by init(), is_dead(), and update().

bool Player::dying [private]

Definition at line 269 of file player.hpp.

Referenced by draw(), init(), is_dying(), kill(), and update().

bool Player::winning [private]

Definition at line 270 of file player.hpp.

Referenced by init(), is_winning(), and set_winning().

bool Player::backflipping [private]

Definition at line 271 of file player.hpp.

Referenced by do_backflip(), do_standup(), draw(), handle_input(), handle_vertical_input(), init(), kill(), move(), trigger_sequence(), and update().

int Player::backflip_direction [private]

Definition at line 272 of file player.hpp.

Referenced by do_backflip(), init(), trigger_sequence(), and update().

Direction Player::peekingX [private]

Definition at line 273 of file player.hpp.

Referenced by handle_input(), init(), and peeking_direction_x().

Direction Player::peekingY [private]

Definition at line 274 of file player.hpp.

Referenced by handle_input(), init(), and peeking_direction_y().

bool Player::swimming [private]

Definition at line 275 of file player.hpp.

Referenced by collision_tile(), handle_vertical_input(), init(), and update().

float Player::speedlimit [private]

Definition at line 276 of file player.hpp.

Referenced by get_speedlimit(), handle_horizontal_input(), init(), and set_speedlimit().

Controller* Player::scripting_controller_old [private]

Saves the old controller while the scripting_controller is used.

Definition at line 277 of file player.hpp.

Referenced by use_scripting_controller().

bool Player::jump_early_apex [private]

Definition at line 278 of file player.hpp.

Referenced by do_jump_apex(), early_jump_apex(), handle_vertical_input(), and init().

bool Player::on_ice [private]

Definition at line 279 of file player.hpp.

Referenced by apply_friction(), collision_tile(), handle_horizontal_input(), init(), and update().

bool Player::ice_this_frame [private]

Definition at line 280 of file player.hpp.

Referenced by collision_tile(), init(), and update().

Direction Player::dir

Definition at line 283 of file player.hpp.

Referenced by do_backflip(), draw(), handle_horizontal_input(), handle_input(), handle_input_climbing(), handle_input_ghost(), init(), position_grabbed_object(), set_bonus(), stop_climbing(), try_grab(), update(), and Camera::update_scroll_normal().

Direction Player::old_dir

Definition at line 284 of file player.hpp.

Referenced by handle_horizontal_input(), and init().

float Player::last_ground_y

Definition at line 286 of file player.hpp.

Referenced by init(), move(), update(), and Camera::update_scroll_normal().

FallMode Player::fall_mode

Definition at line 287 of file player.hpp.

Referenced by init(), update(), and Camera::update_scroll_normal().

bool Player::on_ground_flag

Definition at line 289 of file player.hpp.

Referenced by collision_solid(), do_jump(), init(), on_ground(), stop_climbing(), and update().

bool Player::jumping

Definition at line 290 of file player.hpp.

Referenced by do_jump(), handle_input(), handle_vertical_input(), init(), and update().

bool Player::can_jump

Definition at line 291 of file player.hpp.

Referenced by do_jump(), handle_input(), handle_input_climbing(), handle_vertical_input(), and init().

Timer Player::jump_button_timer

started when player presses the jump button; runs until Tux jumps or JUMP_GRACE_TIME runs out

Definition at line 292 of file player.hpp.

Referenced by handle_vertical_input().

bool Player::wants_buttjump

Definition at line 293 of file player.hpp.

Referenced by draw(), handle_vertical_input(), and init().

bool Player::does_buttjump

Definition at line 294 of file player.hpp.

Referenced by Brick::collision(), BonusBlock::collision(), collision_solid(), Snail::collision_squished(), MrIceBlock::collision_squished(), do_duck(), draw(), handle_vertical_input(), init(), and set_bonus().

Timer Player::invincible_timer

Definition at line 296 of file player.hpp.

Referenced by collision(), is_invincible(), kill(), make_invincible(), set_winning(), GameSession::update(), and update().

Timer Player::skidding_timer

Definition at line 297 of file player.hpp.

Referenced by draw(), and handle_horizontal_input().

Timer Player::safe_timer

Definition at line 298 of file player.hpp.

Referenced by collision(), draw(), and kill().

Timer Player::kick_timer

Definition at line 299 of file player.hpp.

Referenced by draw(), and kick().

Timer Player::shooting_timer

Definition at line 300 of file player.hpp.

Referenced by handle_input().

Timer Player::dying_timer

Definition at line 301 of file player.hpp.

Referenced by kill(), GameSession::on_escape_press(), and update().

bool Player::growing

Definition at line 302 of file player.hpp.

Referenced by do_duck(), draw(), init(), kill(), set_bonus(), and update().

Timer Player::backflip_timer

Definition at line 303 of file player.hpp.

Referenced by do_backflip(), and update().

Physic Player::physic

Definition at line 305 of file player.hpp.

Referenced by add_velocity(), apply_friction(), bounce(), collision_solid(), deactivate(), do_duck(), do_jump(), do_jump_apex(), draw(), early_jump_apex(), get_physic(), get_velocity(), handle_horizontal_input(), handle_input(), handle_input_climbing(), handle_input_ghost(), handle_vertical_input(), init(), kill(), move(), set_ghost_mode(), start_climbing(), stop_climbing(), update(), and walk().

bool Player::visible

Definition at line 307 of file player.hpp.

Referenced by draw(), get_visible(), and init().

Portable* Player::grabbed_object

Definition at line 309 of file player.hpp.

Referenced by get_grabbed_object(), handle_horizontal_input(), handle_input(), init(), position_grabbed_object(), stop_climbing(), stop_grabbing(), try_grab(), and update().

SpritePtr Player::sprite

The main sprite representing Tux.

Definition at line 311 of file player.hpp.

Referenced by draw(), Player(), set_bonus(), and update().

SurfacePtr Player::airarrow

arrow indicating Tux' position when he's above the camera

Definition at line 313 of file player.hpp.

Referenced by draw(), and Player().

Vector Player::floor_normal

Definition at line 315 of file player.hpp.

Referenced by collision_solid(), and update().

bool Player::ghost_mode

indicates if Tux should float around and through solid objects

Definition at line 319 of file player.hpp.

Referenced by check_bounds(), get_ghost_mode(), handle_input(), and set_ghost_mode().

bool Player::edit_mode

indicates if Tux should switch to ghost mode rather than dying

Definition at line 320 of file player.hpp.

Referenced by kill(), and set_edit_mode().

Timer Player::unduck_hurt_timer

if Tux wants to stand up again after ducking and cannot, this timer is started

Definition at line 322 of file player.hpp.

Referenced by do_duck(), and do_standup().

Timer Player::idle_timer

Definition at line 324 of file player.hpp.

Referenced by draw(), and Player().

unsigned int Player::idle_stage

Definition at line 325 of file player.hpp.

Referenced by draw().

Climbable* Player::climbing

Climbable object we are currently climbing, null if none.

Definition at line 327 of file player.hpp.

Referenced by deactivate(), draw(), handle_input(), handle_input_climbing(), init(), kill(), move(), set_bonus(), set_ghost_mode(), start_climbing(), stop_climbing(), trigger_sequence(), try_grab(), and ~Player().


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