18 #ifndef HEADER_SUPERTUX_OBJECT_CAMERA_HPP 19 #define HEADER_SUPERTUX_OBJECT_CAMERA_HPP 23 #include "math/anchor_point.hpp" 24 #include "math/size.hpp" 25 #include "math/vector.hpp" 26 #include "object/path_object.hpp" 27 #include "supertux/game_object.hpp" 28 #include "supertux/timer.hpp" 44 static void register_class(ssq::VM& vm);
49 NORMAL, MANUAL, AUTOSCROLL, SCROLLTO
53 Camera(
const std::string& name);
59 virtual void update(
float dt_sec)
override;
65 static std::string class_name() {
return "camera"; }
66 virtual std::string get_class_name()
const override {
return class_name(); }
67 virtual std::string get_exposed_class_name()
const override {
return "Camera"; }
68 static std::string display_name() {
return _(
"Camera"); }
73 virtual void after_editor_set()
override;
76 void check_state()
override;
78 virtual const std::string get_icon_path()
const override {
return "images/engine/editor/camera.png"; }
81 Rectf get_rect()
const;
87 void reset(
const Vector& tuxpos);
91 void set_translation(
const Vector& translation) { m_translation = translation; }
92 void set_translation_centered(
const Vector& translation);
94 void keep_in_bounds(
const Rectf& bounds);
97 void shake(
float duration,
float x,
float y);
101 void stop_earthquake();
105 void scroll_to(
const Vector& goal,
float scrolltime);
106 void move(
const Vector& offset);
119 void set_mode(Mode mode_) { m_mode = mode_; }
121 Mode get_mode()
const {
return m_mode; }
124 float get_current_scale()
const {
return m_enfore_minimum_scale ? std::min(m_minimum_scale, m_scale) : m_scale; }
130 void ease_scale(
float scale,
float time, easing ease, AnchorPoint anchor = AnchorPoint::ANCHOR_MIDDLE);
139 void set_pos(
float x,
float y);
146 void move(
float x,
float y);
152 void set_mode(
const std::string& mode);
160 void scroll_to(
float x,
float y,
float scrolltime);
181 void scale(
float scale,
float time);
198 void ease_scale(
float scale,
float time,
const std::string& ease);
208 void ease_scale_anchor(
float scale,
float time,
int anchor,
const std::string& ease);
231 void keep_in_bounds(Vector& vector);
233 void update_scroll_normal(
float dt_sec);
234 void update_scroll_normal_multiplayer(
float dt_sec);
235 void update_scroll_autoscroll(
float dt_sec);
236 void update_scroll_to(
float dt_sec);
237 void update_scale(
float dt_sec);
239 void update_earthquake();
241 Vector get_scale_anchor_target()
const;
250 Vector m_translation;
253 Vector m_lookahead_pos;
255 Vector m_cached_translation;
260 float m_shakedepth_x;
261 float m_shakedepth_y;
265 float m_earthquake_strength,
267 m_earthquake_last_offset;
268 Timer m_earthquake_delay_timer;
271 Vector m_scroll_from;
272 Vector m_scroll_goal;
273 float m_scroll_to_pos;
280 m_scale_time_remaining;
281 Vector m_scale_origin_translation,
282 m_scale_target_translation;
283 easing m_scale_easing;
284 AnchorPoint m_scale_anchor;
288 float m_minimum_scale;
289 bool m_enfore_minimum_scale;
void start_earthquake(float strength, float delay)
Shake the camera vertically with a specified average strength, at a certain minimal delay...
Definition: camera.cpp:252
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user's locale.
Definition: camera.hpp:69
float get_screen_width() const
Gets the current width of the screen.
Definition: camera.cpp:834
float get_x() const
Gets the X coordinate of the top-left corner of the screen.
Definition: camera.cpp:846
A walker that travels along a path.
Definition: path_walker.hpp:31
void set_scale_anchor(float scale, int anchor)
Sets the scale factor and the target position anchor.
Definition: camera.cpp:804
void scale(float scale, float time)
Fades to a specified scale factor in ""time"" seconds.
Definition: camera.cpp:810
virtual bool is_singleton() const override
If true only a single object of this type is allowed in a given GameObjectManager.
Definition: camera.hpp:62
const Vector & get_position() const
get the coordinates of the point directly in the top left of this camera
Definition: camera.cpp:865
virtual bool is_saveable() const override
Indicates if the object will be saved.
Definition: camera.cpp:884
void save_state() override
Save/check the current state of the object.
Definition: camera.cpp:197
Vector get_center() const
get the coordinates of the point directly in the center of this camera
Definition: camera.cpp:858
void set_pos(float x, float y)
Moves the camera to the specified absolute position.
Definition: camera.cpp:769
void set_scale(float scale)
Sets the scale factor.
Definition: camera.cpp:798
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: camera.hpp:70
void shake(float duration, float x, float y)
shake camera in a direction 1 time
Definition: camera.cpp:243
float get_target_scale() const
get the scale towards which the camera is moving
Definition: camera.hpp:127
void ease_scale(float scale, float time, easing ease, AnchorPoint anchor=AnchorPoint::ANCHOR_MIDDLE)
smoothly slide the scale and anchor position of the camera towards a new value
Definition: camera.cpp:748
Definition: object_settings.hpp:39
float get_y() const
Gets the Y coordinate of the top-left corner of the screen.
Definition: camera.cpp:852
const Sizef & get_screen_size() const
get the width and height of the screen
Definition: camera.cpp:871
void scale_anchor(float scale, float time, int anchor)
Fades to a specified scale factor and target position anchor in ""time"" seconds. ...
Definition: camera.cpp:816
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
float get_screen_height() const
Gets the current height of the screen.
Definition: camera.cpp:840
float get_current_scale() const
get the exact scale at this exact moment
Definition: camera.hpp:124
virtual void draw(DrawingContext &) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: camera.cpp:302
const Vector get_translation() const
return camera position
Definition: camera.cpp:211
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it's state.
Definition: camera.cpp:314
A base class for all objects that contain, or make use of a path.
Definition: path_object.hpp:36
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 scroll_to(const Vector &goal, float scrolltime)
scroll the upper left edge of the camera in scrolltime seconds to the position goal ...
Definition: camera.cpp:282
Simple timer designed to be used in the update functions of objects.
Definition: timer.hpp:24
A ""Camera"" that was given a name can be manipulated by scripts.
Definition: camera.hpp:40
Definition: reader_mapping.hpp:32
void reset(const Vector &tuxpos)
reset camera position
Definition: camera.cpp:230
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void ease_scale_anchor(float scale, float time, int anchor, const std::string &ease)
Fades to a specified scale factor and target position anchor in ""time"" seconds with easing (smooth ...
Definition: camera.cpp:828