supertux
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Player Class Referencefinal

This module contains methods controlling the player. More...

#include <player.hpp>

Inheritance diagram for Player:
Inheritance graph
[legend]
Collaboration diagram for Player:
Collaboration graph
[legend]

Public Types

enum  FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }
 

Public Member Functions

 Player (PlayerStatus &player_status, const std::string &name, int player_id)
 
virtual void update (float dt_sec) override
 This function is called once per frame and allows the object to update it's state. More...
 
virtual void draw (DrawingContext &context) override
 The GameObject should draw itself onto the provided DrawingContext if this function is called. More...
 
virtual void collision_solid (const CollisionHit &hit) override
 this function is called when the object collided with something solid
 
virtual HitResponse collision (GameObject &other, const CollisionHit &hit) override
 this function is called when the object collided with any other object
 
virtual void collision_tile (uint32_t tile_attributes) override
 called when tiles with special attributes have been touched
 
virtual void on_flip (float height) override
 When level is flipped vertically.
 
virtual bool is_saveable () const override
 Indicates if the object will be saved. More...
 
virtual bool is_singleton () const override
 If true only a single object of this type is allowed in a given GameObjectManager.
 
virtual bool has_object_manager_priority () const override
 Indicates if the object should be added at the beginning of the object list. More...
 
virtual std::string get_exposed_class_name () const override
 
virtual void remove_me () override
 schedules this object to be removed at the end of the frame
 
virtual GameObjectClasses get_class_types () const override
 List notable classes in inheritance hierarchy of class. More...
 
int get_id () const
 
void set_id (int id)
 
virtual int get_layer () const override
 
void set_controller (const Controller *controller)
 
void set_winning ()
 Level solved. More...
 
bool is_winning () const
 
void set_speedlimit (float newlimit)
 
float get_speedlimit () const
 
const Controllerget_controller () const
 
void use_scripting_controller (bool enable)
 Uses a scriptable controller for all user input (or restores controls). More...
 
void do_scripting_controller (const std::string &control, bool pressed)
 Instructs the scriptable controller to press or release a button. More...
 
void move_to_sector (Sector &other)
 Move the player to a different sector, including any objects that it points to, or references. More...
 
void make_invincible ()
 Make Tux invincible for a short amount of time.
 
void make_temporarily_safe (float safe_time)
 
bool is_invincible () const
 
bool is_dying () const
 
Direction peeking_direction_x () const
 
Direction peeking_direction_y () const
 
void kill (bool completely)
 Hurts Tux. More...
 
void set_pos (const Vector &vector) override
 
bool add_bonus (const std::string &bonus)
 Gives Tux the specified bonus unless Tux’s current bonus is superior. More...
 
bool set_bonus (const std::string &bonus)
 Gives Tux the specified bonus. More...
 
void add_coins (int count)
 Gives the player a number of coins. More...
 
int get_coins () const
 Returns the number of coins the player currently has.
 
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 More...
 
bool set_bonus (BonusType type, bool animate=false, bool increment_powerup_counter=true)
 like add_bonus, but can also downgrade the bonus items carried
 
BonusType get_bonus () const
 
std::string bonus_to_string () const
 
PlayerStatusget_status () const
 
void kick ()
 Start kick animation.
 
std::string get_action () const
 Gets the player's current action/animation.
 
void do_cheer ()
 Play cheer animation. More...
 
void do_duck ()
 Makes Tux duck down, if possible. More...
 
void do_standup ()
 Makes Tux stand back up, if possible.
 
void do_standup (bool force_standup)
 Makes Tux stand back up, if possible.
 
void do_backflip ()
 Makes Tux do a backflip, if possible.
 
void do_jump (float yspeed)
 Makes Tux jump in the air, if possible. More...
 
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 () const
 Returns the current velocity of the player.
 
float get_velocity_x () const
 Returns Tux’s velocity in X direction.
 
float get_velocity_y () const
 Returns Tux’s velocity in Y direction.
 
void set_velocity (float x, float y)
 Sets the velocity of the player to a programmable/variable speed. More...
 
void bounce (BadGuy &badguy)
 
void override_velocity ()
 
bool is_dead () const
 
bool is_big () const
 
bool is_stone () const
 
bool is_sliding () const
 
bool is_swimming () const
 
bool is_swimboosting () const
 
bool is_water_jumping () const
 
bool is_skidding () const
 
float get_swimming_angle () const
 
void set_visible (bool visible)
 
bool get_visible () const
 
bool on_ground () const
 
void set_on_ground (bool flag)
 
Portableget_grabbed_object () const
 
void stop_grabbing ()
 
bool has_grabbed (const std::string &name) const
 Returns whether the player is carrying a certain object. More...
 
void set_ghost_mode (bool enable)
 Switches ghost mode on/off. More...
 
bool get_ghost_mode () const
 Returns whether ghost mode is currently enabled.
 
bool adjust_height (float new_height, float bottom_offset=0)
 Changes height of bounding box. More...
 
void trigger_sequence (const std::string &sequence_name)
 Orders the current ""GameSession"" to start a sequence. More...
 
void trigger_sequence (const std::string &sequence_name, const SequenceData *data)
 Orders the current GameSession to start a sequence. More...
 
void trigger_sequence (Sequence seq, const SequenceData *data=nullptr)
 Orders the current GameSession to start a sequence. More...
 
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 activate ()
 Give control back to user/scripting.
 
void deactivate ()
 Deactivate user/scripting input for Tux. More...
 
bool get_input_pressed (const std::string &input)
 Gets whether the current input on the keyboard/controller/touchpad has been pressed. More...
 
bool get_input_held (const std::string &input)
 Gets whether the current input on the keyboard/controller/touchpad is being held. More...
 
bool get_input_released (const std::string &input)
 Gets whether the current input on the keyboard/controller/touchpad has been released. More...
 
void walk (float speed)
 Makes Tux walk. More...
 
void set_dir (bool right)
 Face Tux in the proper direction. More...
 
void stop_backflipping ()
 
void position_grabbed_object (bool teleport=false)
 
bool try_grab ()
 
void sideways_push (float delta)
 Boosts Tux in a certain direction, sideways. More...
 
void multiplayer_prepare_spawn ()
 
void set_ending_direction (int direction)
 
int get_ending_direction () const
 
const std::vector< Key * > & get_collected_keys () const
 
void add_collected_key (Key *key)
 
void remove_collected_key (Key *key)
 
bool track_state () const override
 Indicates if the object's state should be tracked. More...
 
- Public Member Functions inherited from MovingObject
 MovingObject (const ReaderMapping &reader)
 
virtual bool collides (GameObject &, const CollisionHit &) const override
 when 2 objects collided, we will first call the collision functions of both objects that can decide on how to react to the collision. More...
 
virtual void move_to (const Vector &pos)
 
virtual void move (const Vector &dist)
 
virtual bool listener_is_valid () const override
 
Vector get_pos () const
 
const Rectfget_bbox () const
 
const Vector & get_movement () const
 
CollisionGroup get_group () const
 
CollisionObjectget_collision_object ()
 
const CollisionObjectget_collision_object () const
 
void set_parent_dispenser (Dispenser *dispenser)
 
Dispenserget_parent_dispenser () const
 
virtual std::string get_class_name () const override
 
virtual ObjectSettings get_settings () override
 
virtual void editor_select () override
 The user clicked on the object in the editor and selected it.
 
float get_x () const
 Returns the object's X coordinate.
 
float get_y () const
 Returns the object's Y coordinate.
 
void set_pos (float x, float y)
 Sets the position of the object. More...
 
void move (float x, float y)
 Moves the object by ""x"" units to the right and ""y"" down, relative to its current position. More...
 
float get_width () const
 Returns the object's hitbox width.
 
float get_height () const
 Returns the object's hitbox height.
 
- Public Member Functions inherited from GameObject
 GameObject (const std::string &name)
 
 GameObject (const ReaderMapping &reader)
 
virtual void finish_construction ()
 Called after all objects have been added to the Sector and the Sector is fully constructed. More...
 
UID get_uid () const
 
virtual void save (Writer &writer)
 This function saves the object. More...
 
std::string save ()
 
virtual std::string get_display_name () const
 Returns the display name of the object, translated to the user's locale.
 
virtual std::vector< std::string > get_patches () const
 Version checking/updating, patch information.
 
virtual void update_version ()
 
int get_version () const
 Returns the current version of the object.
 
int get_latest_version () const
 Returns the latest version of the object.
 
bool is_up_to_date () const
 Checks whether the object's current version is equal to its latest one.
 
virtual bool has_variable_size () const
 Does this object have variable size (secret area trigger, wind, etc.)
 
virtual bool has_settings () const
 Indicates if get_settings() is implemented. More...
 
virtual GameObjectTypes get_types () const
 Get all types of the object, if available. More...
 
int get_type () const
 Returns the type index of the object.
 
virtual void after_editor_set ()
 
bool is_valid () const
 returns true if the object is not scheduled to be removed yet
 
void add_remove_listener (ObjectRemoveListener *listener)
 registers a remove listener which will be called if the object gets removed/destroyed
 
void del_remove_listener (ObjectRemoveListener *listener)
 unregisters a remove listener, so it will no longer be called if the object gets removed/destroyed
 
void set_name (const std::string &name)
 
const std::string & get_name () const
 Returns the name of the object.
 
virtual const std::string get_icon_path () const
 
virtual void stop_looping_sounds ()
 stops all looping sounds
 
virtual void play_looping_sounds ()
 continues all looping sounds
 
template<typename T >
T * get_component ()
 
void add_component (std::unique_ptr< GameObjectComponent > component)
 
void remove_component (GameObjectComponent *component)
 
virtual void save_state ()
 Save/check the current state of the object. More...
 
virtual void check_state ()
 
virtual void editor_delete ()
 The editor requested the deletion of the object.
 
virtual void editor_deselect ()
 The object got deselected.
 
virtual void editor_update ()
 Called each frame in the editor, used to keep linked objects together (e.g. More...
 
GameObjectManagerget_parent () const
 

Static Public Member Functions

static void register_class (ssq::VM &vm)
 
static Color get_player_color (int id)
 
- Static Public Member Functions inherited from MovingObject
static void register_class (ssq::VM &vm)
 
static std::string class_name ()
 
- Static Public Member Functions inherited from GameObject
static void register_class (ssq::VM &vm)
 

Public Attributes

Direction m_dir
 
float m_last_ground_y
 
FallMode m_fall_mode
 
bool m_does_buttjump
 
Timer m_invincible_timer
 
Timer m_dying_timer
 

Additional Inherited Members

- Protected Types inherited from GameObject
enum  TypeChange { INITIAL = -1 }
 When the type has been changed from the editor. More...
 
- Protected Member Functions inherited from MovingObject
void set_group (CollisionGroup group)
 
- Protected Member Functions inherited from GameObject
void parse_type (const ReaderMapping &reader)
 Parse object type. More...
 
virtual void on_type_change (int old_type)
 
int type_id_to_value (const std::string &id) const
 Conversion between type ID and value. More...
 
std::string type_value_to_id (int value) const
 
- Protected Attributes inherited from MovingObject
CollisionObject m_col
 
Dispenserm_parent_dispenser
 
- Protected Attributes inherited from GameObject
std::string m_name
 a name for the gameobject, this is mostly a hint for scripts and for debugging, don't rely on names being set or being unique
 
int m_type
 Type of the GameObject. More...
 
std::vector< std::unique_ptr< FadeHelper > > m_fade_helpers
 Fade Helpers are for easing/fading script functions.
 
bool m_track_undo
 Track the following creation/deletion of this object for undo. More...
 

Detailed Description

This module contains methods controlling the player.

(No, SuperTux doesn't use mind control. ""Player"" refers to the type of the player object.) The first player can be accessed using ""Tux"", or ""sector.Tux"" from the console. All following players (2nd, 3rd, etc...) can be accessed by ""Tux{index}"". For example, to access the 2nd player, use ""Tux1"" (or ""sector.Tux1"" from the console).

Member Function Documentation

◆ add_bonus() [1/2]

bool Player::add_bonus ( const std::string &  bonus)

Gives Tux the specified bonus unless Tux’s current bonus is superior.

Parameters
string$bonusCan be "grow", "fireflower", "iceflower", "airflower" or "earthflower" at the moment.

◆ add_bonus() [2/2]

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)

◆ add_coins()

void Player::add_coins ( int  count)

Gives the player a number of coins.

${SRG_TABLENEWPARAGRAPH} If count is a negative amount of coins, that number of coins will be taken from the player (until the number of coins the player has is 0, when it will stop changing).

Parameters
int$count

◆ adjust_height()

bool Player::adjust_height ( float  new_height,
float  bottom_offset = 0 
)

Changes height of bounding box.

Returns true if successful, false otherwise

◆ deactivate()

void Player::deactivate ( )

Deactivate user/scripting input for Tux.

Carried items like trampolines won't be dropped.

◆ do_cheer()

void Player::do_cheer ( )

Play cheer animation.

${SRG_TABLENEWPARAGRAPH} This might need some space and behave in an unpredictable way. It's best to use this at level end.

◆ do_duck()

void Player::do_duck ( )

Makes Tux duck down, if possible.

Won't last long, as long as input is enabled.

◆ do_jump()

void Player::do_jump ( float  yspeed)

Makes Tux jump in the air, if possible.

Parameters
float$yspeedSensible values are negative - unless we want to jump into the ground of course.

◆ do_scripting_controller()

void Player::do_scripting_controller ( const std::string &  control,
bool  pressed 
)

Instructs the scriptable controller to press or release a button.

Parameters
string$controlCan be “left”, “right”, “up”, “down”, “jump”, “action”, “start”, “escape”, “menu-select”, “menu-select-space”, “menu-back”, “remove”, “cheat-menu”, “debug-menu”, “console”, “peek-left”, “peek-right”, “peek-up” or “peek-down”.
bool$pressed

◆ draw()

void Player::draw ( DrawingContext context)
overridevirtual

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

Implements GameObject.

◆ get_class_types()

virtual GameObjectClasses Player::get_class_types ( ) const
inlineoverridevirtual

List notable classes in inheritance hierarchy of class.

This makes it possible to efficiently look up all objects deriving from a particular intermediate class

Reimplemented from MovingObject.

◆ get_input_held()

bool Player::get_input_held ( const std::string &  input)

Gets whether the current input on the keyboard/controller/touchpad is being held.

Parameters
string$inputValid values are listed above.

◆ get_input_pressed()

bool Player::get_input_pressed ( const std::string &  input)

Gets whether the current input on the keyboard/controller/touchpad has been pressed.

Parameters
string$inputCan be “left”, “right”, “up”, “down”, “jump”, “action”, “start”, “escape”, “menu-select”, “menu-select-space”, “menu-back”, “remove”, “cheat-menu”, “debug-menu”, “console”, “peek-left”, “peek-right”, “peek-up” or “peek-down”.

◆ get_input_released()

bool Player::get_input_released ( const std::string &  input)

Gets whether the current input on the keyboard/controller/touchpad has been released.

Parameters
string$inputValid values are listed above.

◆ get_visible()

bool Player::get_visible ( ) const

Deprecated:
Returns ""true"" if Tux is currently visible (has not been set invisible by the ""set_visible()"" method).

◆ has_grabbed()

bool Player::has_grabbed ( const std::string &  name) const

Returns whether the player is carrying a certain object.

Parameters
string$nameName of the portable object to check for.

◆ has_object_manager_priority()

virtual bool Player::has_object_manager_priority ( ) const
inlineoverridevirtual

Indicates if the object should be added at the beginning of the object list.

Reimplemented from GameObject.

◆ is_saveable()

virtual bool Player::is_saveable ( ) const
inlineoverridevirtual

Indicates if the object will be saved.

If false, the object will be skipped on saving and can't be cloned in the editor.

Reimplemented from GameObject.

◆ kill()

void Player::kill ( bool  completely)

Hurts Tux.

Parameters
bool$completelyIf true, he will be killed even if he had "grow" or a superior bonus.

◆ move_to_sector()

void Player::move_to_sector ( Sector other)

Move the player to a different sector, including any objects that it points to, or references.

◆ set_bonus()

bool Player::set_bonus ( const std::string &  bonus)

Gives Tux the specified bonus.

Parameters
string$bonusCan be "grow", "fireflower", "iceflower", "airflower" or "earthflower" at the moment.

◆ set_dir()

void Player::set_dir ( bool  right)

Face Tux in the proper direction.

Parameters
bool$rightSet to ""true"" to make Tux face right, ""false"" to face left.

◆ set_ghost_mode()

void Player::set_ghost_mode ( bool  enable)

Switches ghost mode on/off.

Lets Tux float around and through solid objects.

Parameters
bool$enable

◆ set_velocity()

void Player::set_velocity ( float  x,
float  y 
)

Sets the velocity of the player to a programmable/variable speed.

Parameters
float$xThe speed Tux will move on the x axis.
float$yThe speed Tux will move on the y axis.

◆ set_visible()

void Player::set_visible ( bool  visible)

Deprecated:
Set Tux visible or invisible.
Parameters
bool$visible

◆ set_winning()

void Player::set_winning ( )

Level solved.

Don't kill Tux any more.

◆ sideways_push()

void Player::sideways_push ( float  delta)

Boosts Tux in a certain direction, sideways.

Useful for bumpers/walljumping.

◆ track_state()

bool Player::track_state ( ) const
inlineoverridevirtual

Indicates if the object's state should be tracked.

If false, load_state() and save_state() calls would not do anything.

Reimplemented from GameObject.

◆ trigger_sequence() [1/3]

void Player::trigger_sequence ( const std::string &  sequence_name)

Orders the current ""GameSession"" to start a sequence.

Parameters
string$sequence_nameOne of “stoptux”, “endsequence” or “fireworks”.

◆ trigger_sequence() [2/3]

void Player::trigger_sequence ( const std::string &  sequence_name,
const SequenceData data 
)

Orders the current GameSession to start a sequence.

Parameters
sequence_nameName of the sequence to start
dataCustom additional sequence data

◆ trigger_sequence() [3/3]

void Player::trigger_sequence ( Sequence  seq,
const SequenceData data = nullptr 
)

Orders the current GameSession to start a sequence.

Parameters
sequenceSequence to start
dataCustom additional sequence data

◆ update()

void Player::update ( float  dt_sec)
overridevirtual

This function is called once per frame and allows the object to update it's state.

The dt_sec is the time that has passed 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). This function is not called in the Editor.

Implements GameObject.

◆ use_scripting_controller()

void Player::use_scripting_controller ( bool  enable)

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

Parameters
bool$enable

◆ walk()

void Player::walk ( float  speed)

Makes Tux walk.

Parameters
float$speed

The documentation for this class was generated from the following files: