17 #ifndef HEADER_SUPERTUX_OBJECT_PLAYER_HPP 18 #define HEADER_SUPERTUX_OBJECT_PLAYER_HPP 20 #include "sprite/sprite_ptr.hpp" 21 #include "supertux/direction.hpp" 22 #include "supertux/moving_object.hpp" 23 #include "supertux/object_remove_listener.hpp" 24 #include "supertux/physic.hpp" 25 #include "supertux/player_status.hpp" 26 #include "supertux/sequence.hpp" 27 #include "supertux/timer.hpp" 28 #include "video/layer.hpp" 29 #include "video/surface_ptr.hpp" 38 extern const float TUX_INVINCIBLE_TIME_WARNING;
50 static void register_class(ssq::VM& vm);
53 enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING };
59 GrabListener(
Player& player) : m_player(player)
62 virtual void object_removed(
GameObject*
object)
override {
63 m_player.ungrab_object(
object);
70 GrabListener(
const GrabListener&) =
delete;
71 GrabListener& operator=(
const GrabListener&) =
delete;
75 static Color get_player_color(
int id);
81 virtual void update(
float dt_sec)
override;
86 virtual void on_flip(
float height)
override;
90 virtual std::string get_exposed_class_name()
const override {
return "Player"; }
94 int get_id()
const {
return m_id; }
97 virtual int get_layer()
const override {
return LAYER_OBJECTS + 1; }
99 void set_controller(
const Controller* controller);
102 bool is_winning()
const {
return m_winning; }
105 void set_speedlimit(
float newlimit);
106 float get_speedlimit()
const;
108 const Controller& get_controller()
const {
return *m_controller; }
133 void make_temporarily_safe(
float safe_time);
135 bool is_invincible()
const {
return m_invincible_timer.started(); }
136 bool is_dying()
const {
return m_dying; }
138 Direction peeking_direction_x()
const {
return m_peekingX; }
139 Direction peeking_direction_y()
const {
return m_peekingY; }
146 void kill(
bool completely);
148 void set_pos(
const Vector& vector)
override;
155 bool add_bonus(
const std::string& bonus);
161 bool set_bonus(
const std::string& bonus);
162 #ifdef DOXYGEN_SCRIPTING 167 std::string get_bonus()
const;
189 bool add_bonus(BonusType type,
bool animate =
false);
192 bool set_bonus(BonusType type,
bool animate =
false,
bool increment_powerup_counter =
true);
193 BonusType get_bonus()
const;
195 std::string bonus_to_string()
const;
197 PlayerStatus& get_status()
const {
return m_player_status; }
252 void add_velocity(
const Vector& velocity,
const Vector& end_speed);
274 void bounce(
BadGuy& badguy);
275 void override_velocity() { m_velocity_override =
true; }
277 bool is_dead()
const {
return m_dead; }
278 bool is_big()
const {
return get_bonus() != NO_BONUS; }
279 bool is_stone()
const {
return m_stone; }
280 bool is_sliding()
const {
return m_sliding; }
281 bool is_swimming()
const {
return m_swimming; }
282 bool is_swimboosting()
const {
return m_swimboosting; }
283 bool is_water_jumping()
const {
return m_water_jump; }
284 bool is_skidding()
const {
return m_skidding_timer.started(); }
285 float get_swimming_angle()
const {
return m_swimming_angle; }
301 bool on_ground()
const;
302 void set_on_ground(
bool flag);
304 Portable* get_grabbed_object()
const {
return m_grabbed_object; }
305 void stop_grabbing() { ungrab_object(); }
328 bool adjust_height(
float new_height,
float bottom_offset = 0);
353 Physic& get_physic() {
return m_physic; }
393 void walk(
float speed);
400 void stop_backflipping();
402 void position_grabbed_object(
bool teleport =
false);
408 void multiplayer_prepare_spawn();
410 void set_ending_direction(
int direction) { m_ending_direction = direction; }
411 int get_ending_direction()
const {
return m_ending_direction; }
413 const std::vector<Key*>& get_collected_keys()
const {
return m_collected_keys; }
414 void add_collected_key(
Key* key);
415 void remove_collected_key(
Key* key);
421 void handle_input_ghost();
422 void handle_input_climbing();
423 void handle_input_rolling();
425 void handle_input_swimming();
427 void handle_horizontal_input();
428 void handle_vertical_input();
431 void set_pos_reset(
const Vector& vector);
434 void early_jump_apex();
437 void swim(
float pointx,
float pointy,
bool boost);
439 BonusType string_to_bonus(
const std::string& bonus)
const;
442 void apply_friction();
450 void ungrab_object(
GameObject* gameobject =
nullptr);
455 void multiplayer_respawn();
457 void stop_rolling(
bool violent =
true);
461 std::unique_ptr<UID> m_target;
465 std::unique_ptr<CodeController> m_scripting_controller;
473 int m_backflip_direction;
474 Direction m_peekingX;
475 Direction m_peekingY;
483 bool m_on_right_wall;
484 bool m_in_walljump_tile;
488 bool m_velocity_override;
490 bool m_jump_early_apex;
492 bool m_ice_this_frame;
494 SpritePtr m_multiplayer_arrow;
498 std::unique_ptr<FadeHelper> m_tag_fade;
509 float m_last_ground_y;
510 FallMode m_fall_mode;
513 bool m_on_ground_flag;
516 Timer m_jump_button_timer;
517 Timer m_coyote_timer;
518 bool m_wants_buttjump;
519 bool m_buttjump_stomp;
522 bool m_does_buttjump;
523 Timer m_invincible_timer;
526 Timer m_skidding_timer;
528 bool m_is_intentionally_safe;
530 Timer m_buttjump_timer;
536 Timer m_second_growup_sound_timer;
538 Timer m_backflip_timer;
545 std::unique_ptr<ObjectRemoveListener> m_grabbed_object_remove_listener;
546 bool m_released_object;
550 float m_swimming_angle;
551 float m_swimming_accel_modifier;
554 SurfacePtr m_airarrow;
556 Vector m_floor_normal;
560 Timer m_unduck_hurt_timer;
563 unsigned int m_idle_stage;
567 int m_ending_direction;
568 std::vector<Key*> m_collected_keys;
570 float m_last_sliding_angle;
571 float m_current_sliding_angle;
572 float m_target_sliding_angle;
573 Timer m_sliding_rotation_timer;
574 bool m_is_slidejump_falling;
575 bool m_was_crawling_before_slide;
void do_duck()
Makes Tux duck down, if possible.
Definition: player.cpp:1250
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: player.cpp:2378
This class keeps player status between different game sessions (for example when switching maps in th...
Definition: player_status.hpp:39
Base class for moving sprites that can hurt the Player.
Definition: badguy.hpp:38
virtual bool has_object_manager_priority() const override
Indicates if the object should be added at the beginning of the object list.
Definition: player.hpp:89
Definition: controller.hpp:57
void activate()
Give control back to user/scripting.
Definition: player.cpp:2613
void set_velocity(float x, float y)
Sets the velocity of the player to a programmable/variable speed.
Definition: player.cpp:2595
void do_cheer()
Play cheer animation.
Definition: player.cpp:1242
void set_dir(bool right)
Face Tux in the proper direction.
Definition: player.cpp:2657
void add_velocity(const Vector &velocity)
Adds velocity to the player (be careful when using this)
Definition: player.cpp:2558
void use_scripting_controller(bool enable)
Uses a scriptable controller for all user input (or restores controls).
Definition: player.cpp:306
void make_invincible()
Make Tux invincible for a short amount of time.
Definition: player.cpp:2393
bool track_state() const override
Indicates if the object's state should be tracked.
Definition: player.hpp:417
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: player.cpp:1990
bool adjust_height(float new_height, float bottom_offset=0)
Changes height of bounding box.
Definition: player.cpp:347
Physics engine.
Definition: physic.hpp:27
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: player.hpp:92
void set_visible(bool visible)
Definition: player.cpp:1966
bool has_grabbed(const std::string &name) const
Returns whether the player is carrying a certain object.
Definition: player.cpp:2866
Vector get_velocity() const
Returns the current velocity of the player.
Definition: player.cpp:2577
Definition: object_remove_listener.hpp:22
Definition: sequence.hpp:33
void start_climbing(Climbable &climbable)
Requests that the player start climbing the given Climbable.
Definition: player.cpp:2692
float get_velocity_x() const
Returns Tux’s velocity in X direction.
Definition: player.cpp:2583
virtual bool is_singleton() const override
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: player.hpp:88
An object that inherits from this object is considered "portable" and can be carried around by the pl...
Definition: portable.hpp:29
void move_to_sector(Sector &other)
Move the player to a different sector, including any objects that it points to, or references...
Definition: player.cpp:329
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it's state.
Definition: player.cpp:390
Represents one of (potentially) multiple, separate parts of a Level.
Definition: sector.hpp:61
void add_coins(int count)
Gives the player a number of coins.
Definition: player.cpp:1812
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: player.hpp:87
bool get_visible() const
Definition: player.cpp:1972
bool get_input_held(const std::string &input)
Gets whether the current input on the keyboard/controller/touchpad is being held. ...
Definition: player.cpp:2639
void do_backflip()
Makes Tux do a backflip, if possible.
Definition: player.cpp:1318
void trigger_sequence(const std::string &sequence_name)
Orders the current ""GameSession"" to start a sequence.
Definition: player.cpp:369
virtual void collision_solid(const CollisionHit &hit) override
this function is called when the object collided with something solid
Definition: player.cpp:2279
Definition: climbable.hpp:28
void do_standup()
Makes Tux stand back up, if possible.
Definition: player.cpp:1276
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
bool add_bonus(const std::string &bonus)
Gives Tux the specified bonus unless Tux’s current bonus is superior.
Definition: player.cpp:1869
void sideways_push(float delta)
Boosts Tux in a certain direction, sideways.
Definition: player.cpp:2880
virtual HitResponse collision(GameObject &other, const CollisionHit &hit) override
this function is called when the object collided with any other object
Definition: player.cpp:2339
int get_coins() const
Returns the number of coins the player currently has.
Definition: player.cpp:1818
Base class for all dynamic/moving game objects.
Definition: moving_object.hpp:35
virtual void remove_me() override
schedules this object to be removed at the end of the frame
Definition: player.cpp:2386
void kill(bool completely)
Hurts Tux.
Definition: player.cpp:2409
void deactivate()
Deactivate user/scripting input for Tux.
Definition: player.cpp:2621
This is a dummy controller that doesn't react to any user input but should be controlled by code...
Definition: codecontroller.hpp:24
float get_velocity_y() const
Returns Tux’s velocity in Y direction.
Definition: player.cpp:2589
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: moving_object.hpp:49
bool get_input_released(const std::string &input)
Gets whether the current input on the keyboard/controller/touchpad has been released.
Definition: player.cpp:2645
bool get_input_pressed(const std::string &input)
Gets whether the current input on the keyboard/controller/touchpad has been pressed.
Definition: player.cpp:2633
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
void do_jump(float yspeed)
Makes Tux jump in the air, if possible.
Definition: player.cpp:1334
void set_winning()
Level solved.
Definition: player.cpp:297
bool set_bonus(const std::string &bonus)
Gives Tux the specified bonus.
Definition: player.cpp:1875
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
std::string get_action() const
Gets the player's current action/animation.
Definition: player.cpp:1984
void set_ghost_mode(bool enable)
Switches ghost mode on/off.
Definition: player.cpp:2663
void stop_climbing(Climbable &climbable)
Requests that the player stop climbing the given Climbable.
Definition: player.cpp:2710
void walk(float speed)
Makes Tux walk.
Definition: player.cpp:2651
void kick()
Start kick animation.
Definition: player.cpp:1978
This module contains methods controlling the player.
Definition: player.hpp:47
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void do_scripting_controller(const std::string &control, bool pressed)
Instructs the scriptable controller to press or release a button.
Definition: player.cpp:321
This class collects data about a collision.
Definition: collision_hit.hpp:44
bool get_ghost_mode() const
Returns whether ghost mode is currently enabled.
Definition: player.cpp:2686
virtual void collision_tile(uint32_t tile_attributes) override
called when tiles with special attributes have been touched
Definition: player.cpp:2253