17 #ifndef HEADER_SUPERTUX_OBJECT_CUSTOM_PARTICLE_SYSTEM_HPP 18 #define HEADER_SUPERTUX_OBJECT_CUSTOM_PARTICLE_SYSTEM_HPP 20 #include "object/particlesystem_interactive.hpp" 22 #include "math/easing.hpp" 23 #include "math/vector.hpp" 24 #include "object/particle_zone.hpp" 25 #include "video/surface.hpp" 26 #include "video/surface_ptr.hpp" 39 static void register_class(ssq::VM& vm);
48 void reinit_textures();
49 virtual void update(
float dt_sec)
override;
51 static std::string class_name() {
return "particles-custom"; }
52 virtual std::string get_class_name()
const override {
return class_name(); }
53 virtual std::string get_exposed_class_name()
const override {
return "CustomParticleSystem"; }
54 static std::string display_name() {
return _(
"Custom Particles"); }
60 virtual const std::string get_icon_path()
const override {
61 return "images/engine/editor/particle.png";
82 void add_particle(
float lifetime,
float x,
float y);
83 void spawn_particles(
float lifetime);
85 std::vector<ParticleZone::ZoneDetails> get_zones()
const;
87 float get_abs_x()
const;
88 float get_abs_y()
const;
90 float texture_sum_odds;
91 float time_last_remaining;
95 void ease_value(
float* value,
float target,
float time, easing func);
109 void spawn_particles(
int amount,
bool instantly);
213 void ease_delay(
float delay,
float time,
const std::string& easing);
238 void ease_lifetime(
float lifetime,
float time,
const std::string& easing);
288 void ease_birth_time(
float birth_time,
float time,
const std::string& easing);
338 void ease_death_time(
float death_time,
float time,
const std::string& easing);
388 void ease_speed_x(
float speed_x,
float time,
const std::string& easing);
413 void ease_speed_y(
float speed_y,
float time,
const std::string& easing);
538 void ease_friction_x(
float friction_x,
float time,
const std::string& easing);
563 void ease_friction_y(
float friction_y,
float time,
const std::string& easing);
613 void ease_rotation(
float rotation,
float time,
const std::string& easing);
741 std::vector<ease_request> script_easings;
743 enum class RotationMode {
749 enum class FadeMode {
755 enum class CollisionMode {
765 enum class OffscreenMode {
771 class SpriteProperties final
783 color(1.f, 1.f, 1.f, 1.f),
784 texture(Surface::from_file(
"images/engine/editor/particle.png")),
791 SpriteProperties(
const SurfacePtr& surface) :
793 color(1.f, 1.f, 1.f, 1.f),
801 SpriteProperties(
const SpriteProperties& sp,
float alpha) :
802 likeliness(sp.likeliness),
803 color(sp.color.red, sp.color.green, sp.color.blue, sp.color.alpha * alpha),
806 hb_scale(sp.hb_scale),
807 hb_offset(sp.hb_offset)
811 inline bool operator==(
const SpriteProperties& sp)
813 return this->likeliness == sp.likeliness
814 && this->color == sp.color
815 && this->texture == sp.texture
816 && this->scale == sp.scale
817 && this->hb_scale == sp.hb_scale
818 && this->hb_offset == sp.hb_offset;
820 inline bool operator!=(
const SpriteProperties& sp)
822 return !operator==(sp);
826 SpriteProperties get_random_texture()
const;
828 class CustomParticle :
public Particle 831 SpriteProperties original_props, props;
832 float lifetime, birth_time, death_time,
833 total_birth, total_death;
834 FadeMode birth_mode, death_mode;
835 EasingMode birth_easing, death_easing;
836 bool ready_for_deletion;
837 float speedX, speedY,
839 frictionX, frictionY;
840 float feather_factor;
841 float angle_speed, angle_acc,
843 RotationMode angle_mode;
844 CollisionMode collision_mode;
845 OffscreenMode offscreen_mode;
846 bool has_been_on_screen;
847 bool has_been_in_life_zone;
848 bool last_life_zone_required_instakill;
863 ready_for_deletion(
false),
877 has_been_on_screen(),
878 has_been_in_life_zone(
false),
879 last_life_zone_required_instakill(
false),
884 std::vector<SpriteProperties> m_textures;
885 std::vector<std::unique_ptr<CustomParticle> > custom_particles;
887 std::string m_particle_main_texture;
900 float m_particle_lifetime;
904 float m_particle_lifetime_variation;
908 float m_particle_birth_time;
912 float m_particle_birth_time_variation;
916 float m_particle_death_time;
920 float m_particle_death_time_variation;
922 FadeMode m_particle_birth_mode,
923 m_particle_death_mode;
924 EasingMode m_particle_birth_easing,
925 m_particle_death_easing;
930 float m_particle_speed_x;
934 float m_particle_speed_y;
938 float m_particle_speed_variation_x;
942 float m_particle_speed_variation_y;
946 float m_particle_acceleration_x;
950 float m_particle_acceleration_y;
954 float m_particle_friction_x;
958 float m_particle_friction_y;
962 float m_particle_feather_factor;
966 float m_particle_rotation;
970 float m_particle_rotation_variation;
974 float m_particle_rotation_speed;
978 float m_particle_rotation_speed_variation;
982 float m_particle_rotation_acceleration;
986 float m_particle_rotation_decceleration;
988 RotationMode m_particle_rotation_mode;
989 CollisionMode m_particle_collision_mode;
990 OffscreenMode m_particle_offscreen_mode;
1006 std::vector<SpriteProperties> m_textures;
1007 std::string m_particle_main_texture;
1010 float m_particle_lifetime;
1011 float m_particle_lifetime_variation;
1012 float m_particle_birth_time,
1013 m_particle_birth_time_variation,
1014 m_particle_death_time,
1015 m_particle_death_time_variation;
1016 FadeMode m_particle_birth_mode,
1017 m_particle_death_mode;
1018 EasingMode m_particle_birth_easing,
1019 m_particle_death_easing;
1020 float m_particle_speed_x,
1022 m_particle_speed_variation_x,
1023 m_particle_speed_variation_y,
1024 m_particle_acceleration_x,
1025 m_particle_acceleration_y,
1026 m_particle_friction_x,
1027 m_particle_friction_y;
1028 float m_particle_feather_factor;
1029 float m_particle_rotation,
1030 m_particle_rotation_variation,
1031 m_particle_rotation_speed,
1032 m_particle_rotation_speed_variation,
1033 m_particle_rotation_acceleration,
1034 m_particle_rotation_decceleration;
1035 RotationMode m_particle_rotation_mode;
1036 CollisionMode m_particle_collision_mode;
1037 OffscreenMode m_particle_offscreen_mode;
1038 bool m_cover_screen;
1042 m_particle_main_texture(),
1045 m_particle_lifetime(5.f),
1046 m_particle_lifetime_variation(0.f),
1047 m_particle_birth_time(0.f),
1048 m_particle_birth_time_variation(0.f),
1049 m_particle_death_time(0.f),
1050 m_particle_death_time_variation(0.f),
1051 m_particle_birth_mode(),
1052 m_particle_death_mode(),
1053 m_particle_birth_easing(),
1054 m_particle_death_easing(),
1055 m_particle_speed_x(0.f),
1056 m_particle_speed_y(0.f),
1057 m_particle_speed_variation_x(0.f),
1058 m_particle_speed_variation_y(0.f),
1059 m_particle_acceleration_x(0.f),
1060 m_particle_acceleration_y(0.f),
1061 m_particle_friction_x(0.f),
1062 m_particle_friction_y(0.f),
1063 m_particle_feather_factor(0.f),
1064 m_particle_rotation(0.f),
1065 m_particle_rotation_variation(0.f),
1066 m_particle_rotation_speed(0.f),
1067 m_particle_rotation_speed_variation(0.f),
1068 m_particle_rotation_acceleration(0.f),
1069 m_particle_rotation_decceleration(0.f),
1070 m_particle_rotation_mode(),
1071 m_particle_collision_mode(),
1072 m_particle_offscreen_mode(),
1073 m_cover_screen(
true)
1078 std::unique_ptr<ParticleProps> get_props()
const 1080 std::unique_ptr<ParticleProps> props = std::make_unique<ParticleProps>();
1082 for (
auto& texture : m_textures)
1083 props->m_textures.push_back(texture);
1084 props->m_particle_main_texture = m_particle_main_texture;
1085 props->m_max_amount = m_max_amount;
1086 props->m_delay = m_delay;
1087 props->m_particle_lifetime = m_particle_lifetime;
1088 props->m_particle_lifetime_variation = m_particle_lifetime_variation;
1089 props->m_particle_birth_time = m_particle_birth_time;
1090 props->m_particle_birth_time_variation = m_particle_birth_time_variation;
1091 props->m_particle_death_time = m_particle_death_time;
1092 props->m_particle_death_time_variation = m_particle_death_time_variation;
1093 props->m_particle_birth_mode = m_particle_birth_mode;
1094 props->m_particle_death_mode = m_particle_death_mode;
1095 props->m_particle_birth_easing = m_particle_birth_easing;
1096 props->m_particle_death_easing = m_particle_death_easing;
1097 props->m_particle_speed_x = m_particle_speed_x;
1098 props->m_particle_speed_y = m_particle_speed_y;
1099 props->m_particle_speed_variation_x = m_particle_speed_variation_x;
1100 props->m_particle_speed_variation_y = m_particle_speed_variation_y;
1101 props->m_particle_acceleration_x = m_particle_acceleration_x;
1102 props->m_particle_acceleration_y = m_particle_acceleration_y;
1103 props->m_particle_friction_x = m_particle_friction_x;
1104 props->m_particle_friction_y = m_particle_friction_y;
1105 props->m_particle_feather_factor = m_particle_feather_factor;
1106 props->m_particle_rotation = m_particle_rotation;
1107 props->m_particle_rotation_variation = m_particle_rotation_variation;
1108 props->m_particle_rotation_speed = m_particle_rotation_speed;
1109 props->m_particle_rotation_speed_variation = m_particle_rotation_speed_variation;
1110 props->m_particle_rotation_acceleration = m_particle_rotation_acceleration;
1111 props->m_particle_rotation_decceleration = m_particle_rotation_decceleration;
1112 props->m_particle_rotation_mode = m_particle_rotation_mode;
1113 props->m_particle_collision_mode = m_particle_collision_mode;
1114 props->m_particle_offscreen_mode = m_particle_offscreen_mode;
1115 props->m_cover_screen = m_cover_screen;
1123 for (
auto& texture : props->m_textures)
1124 m_textures.push_back(texture);
1125 m_particle_main_texture = props->m_particle_main_texture;
1126 m_max_amount = props->m_max_amount;
1127 m_delay = props->m_delay;
1128 m_particle_lifetime = props->m_particle_lifetime;
1129 m_particle_lifetime_variation = props->m_particle_lifetime_variation;
1130 m_particle_birth_time = props->m_particle_birth_time;
1131 m_particle_birth_time_variation = props->m_particle_birth_time_variation;
1132 m_particle_death_time = props->m_particle_death_time;
1133 m_particle_death_time_variation = props->m_particle_death_time_variation;
1134 m_particle_birth_mode = props->m_particle_birth_mode;
1135 m_particle_death_mode = props->m_particle_death_mode;
1136 m_particle_birth_easing = props->m_particle_birth_easing;
1137 m_particle_death_easing = props->m_particle_death_easing;
1138 m_particle_speed_x = props->m_particle_speed_x;
1139 m_particle_speed_y = props->m_particle_speed_y;
1140 m_particle_speed_variation_x = props->m_particle_speed_variation_x;
1141 m_particle_speed_variation_y = props->m_particle_speed_variation_y;
1142 m_particle_acceleration_x = props->m_particle_acceleration_x;
1143 m_particle_acceleration_y = props->m_particle_acceleration_y;
1144 m_particle_friction_x = props->m_particle_friction_x;
1145 m_particle_friction_y = props->m_particle_friction_y;
1146 m_particle_feather_factor = props->m_particle_feather_factor;
1147 m_particle_rotation = props->m_particle_rotation;
1148 m_particle_rotation_variation = props->m_particle_rotation_variation;
1149 m_particle_rotation_speed = props->m_particle_rotation_speed;
1150 m_particle_rotation_speed_variation = props->m_particle_rotation_speed_variation;
1151 m_particle_rotation_acceleration = props->m_particle_rotation_acceleration;
1152 m_particle_rotation_decceleration = props->m_particle_rotation_decceleration;
1153 m_particle_rotation_mode = props->m_particle_rotation_mode;
1154 m_particle_collision_mode = props->m_particle_collision_mode;
1155 m_particle_offscreen_mode = props->m_particle_offscreen_mode;
1156 m_cover_screen = props->m_cover_screen;
float get_rotation_acceleration() const
Definition: custom_particle_system.cpp:2014
void ease_acceleration_y(float acceleration_y, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1808
Definition: particle_editor.hpp:38
float get_feather_factor() const
Definition: custom_particle_system.cpp:1874
void set_birth_mode(const std::string &mode)
Definition: custom_particle_system.cpp:1308
Definition: custom_particle_system.hpp:1003
void fade_speed_variation_x(float speed_variation_x, float time)
Definition: custom_particle_system.cpp:1718
void ease_rotation(float rotation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1920
float get_rotation_variation() const
Definition: custom_particle_system.cpp:1930
void ease_speed_variation_y(float speed_variation_y, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1752
This is an alternative class for particle systems.
Definition: particlesystem_interactive.hpp:39
void fade_lifetime(float lifetime, float time)
Definition: custom_particle_system.cpp:1493
float get_acceleration_y() const
Definition: custom_particle_system.cpp:1790
void fade_delay(float delay, float time)
Definition: custom_particle_system.cpp:1465
void set_rotation_speed_variation(float rotation_speed_variation)
Definition: custom_particle_system.cpp:1992
void set_rotation_variation(float rotation_variation)
Definition: custom_particle_system.cpp:1936
void ease_rotation_speed_variation(float rotation_speed_variation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:2004
float get_speed_x() const
Definition: custom_particle_system.cpp:1650
void set_speed_y(float speed_y)
Definition: custom_particle_system.cpp:1684
void fade_death_time(float death_time, float time)
Definition: custom_particle_system.cpp:1605
float get_birth_time() const
Definition: custom_particle_system.cpp:1537
float get_delay() const
Definition: custom_particle_system.cpp:1453
float get_birth_time_variation() const
Definition: custom_particle_system.cpp:1565
void fade_rotation_variation(float rotation_variation, float time)
Definition: custom_particle_system.cpp:1942
void set_max_amount(int amount)
Definition: custom_particle_system.cpp:1274
void fade_acceleration_y(float acceleration_y, float time)
Definition: custom_particle_system.cpp:1802
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it's state.
Definition: custom_particle_system.cpp:537
void fade_friction_y(float friction_y, float time)
Definition: custom_particle_system.cpp:1858
void set_speed_variation_y(float speed_variation_y)
Definition: custom_particle_system.cpp:1740
void fade_lifetime_variation(float lifetime_variation, float time)
Definition: custom_particle_system.cpp:1521
float get_speed_variation_x() const
Definition: custom_particle_system.cpp:1706
float get_rotation_speed_variation() const
Definition: custom_particle_system.cpp:1986
float get_speed_y() const
Definition: custom_particle_system.cpp:1678
Definition: particlesystem.hpp:86
float get_rotation_speed() const
Definition: custom_particle_system.cpp:1958
void set_offscreen_mode(const std::string &mode)
Definition: custom_particle_system.cpp:1436
float get_death_time_variation() const
Definition: custom_particle_system.cpp:1622
void fade_birth_time_variation(float birth_time_variation, float time)
Definition: custom_particle_system.cpp:1577
std::string get_offscreen_mode() const
Returns "Never", "OnlyOnExit", "Always".
Definition: custom_particle_system.cpp:1420
void set_speed_variation_x(float speed_variation_x)
Definition: custom_particle_system.cpp:1712
std::string get_death_mode() const
Returns "None", "Fade", "Shrink".
Definition: custom_particle_system.cpp:1321
void ease_rotation_decceleration(float rotation_decceleration, float time, const std::string &easing)
Definition: custom_particle_system.cpp:2060
Definition: object_settings.hpp:39
void fade_rotation_speed(float rotation_speed, float time)
Definition: custom_particle_system.cpp:1970
void fade_speed_x(float speed_x, float time)
Definition: custom_particle_system.cpp:1662
void set_birth_time_variation(float birth_time_variation)
Definition: custom_particle_system.cpp:1571
void set_acceleration_x(float acceleration_x)
Definition: custom_particle_system.cpp:1768
void fade_feather_factor(float feather_factor, float time)
Definition: custom_particle_system.cpp:1886
A ""CustomParticleSystem"" that was given a name can be controlled by scripts.
Definition: custom_particle_system.hpp:34
Definition: collision.cpp:24
void set_delay(float delay)
Definition: custom_particle_system.cpp:1459
std::string get_collision_mode() const
Returns "Ignore", "Stick", "StickForever", "BounceHeavy", "BounceLight", "Destroy".
Definition: custom_particle_system.cpp:1379
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: particlesystem_interactive.hpp:50
void set_birth_time(float birth_time)
Definition: custom_particle_system.cpp:1543
float get_friction_y() const
Definition: custom_particle_system.cpp:1846
void fade_acceleration_x(float acceleration_x, float time)
Definition: custom_particle_system.cpp:1774
void set_acceleration_y(float acceleration_y)
Definition: custom_particle_system.cpp:1796
void set_friction_x(float friction_x)
Definition: custom_particle_system.cpp:1824
void set_lifetime(float lifetime)
Definition: custom_particle_system.cpp:1487
void ease_death_time_variation(float death_time_variation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1640
void set_rotation(float rotation)
Definition: custom_particle_system.cpp:1908
void ease_rotation_acceleration(float rotation_acceleration, float time, const std::string &easing)
Definition: custom_particle_system.cpp:2032
float get_lifetime_variation() const
Definition: custom_particle_system.cpp:1509
void ease_birth_time(float birth_time, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1555
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: custom_particle_system.hpp:56
void ease_lifetime_variation(float lifetime_variation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1527
void set_rotation_mode(const std::string &mode)
Definition: custom_particle_system.cpp:1366
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user's locale.
Definition: custom_particle_system.hpp:55
void fade_death_time_variation(float death_time_variation, float time)
Definition: custom_particle_system.cpp:1634
int get_max_amount() const
Definition: custom_particle_system.cpp:1268
void ease_friction_x(float friction_x, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1836
void fade_speed_y(float speed_y, float time)
Definition: custom_particle_system.cpp:1690
void set_lifetime_variation(float lifetime_variation)
Definition: custom_particle_system.cpp:1515
float get_friction_x() const
Definition: custom_particle_system.cpp:1818
void set_rotation_decceleration(float rotation_decceleration)
Definition: custom_particle_system.cpp:2048
void ease_birth_time_variation(float birth_time_variation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1583
void fade_rotation(float rotation, float time)
Definition: custom_particle_system.cpp:1914
void set_death_mode(const std::string &mode)
Definition: custom_particle_system.cpp:1337
float get_death_time() const
Definition: custom_particle_system.cpp:1593
void set_speed_x(float speed_x)
Definition: custom_particle_system.cpp:1656
void ease_speed_variation_x(float speed_variation_x, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1724
void ease_rotation_variation(float rotation_variation, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1948
void ease_speed_x(float speed_x, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1668
float get_rotation() const
Definition: custom_particle_system.cpp:1902
void clear()
Instantly removes all particles of that type on the screen.
Definition: custom_particle_system.cpp:1228
void set_cover_screen(bool cover)
Definition: custom_particle_system.cpp:1286
float get_rotation_decceleration() const
Definition: custom_particle_system.cpp:2042
void ease_rotation_speed(float rotation_speed, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1976
void ease_friction_y(float friction_y, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1864
void fade_rotation_acceleration(float rotation_acceleration, float time)
Definition: custom_particle_system.cpp:2026
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
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: custom_particle_system.cpp:852
void ease_acceleration_x(float acceleration_x, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1780
void fade_rotation_decceleration(float rotation_decceleration, float time)
Definition: custom_particle_system.cpp:2054
void set_friction_y(float friction_y)
Definition: custom_particle_system.cpp:1852
void ease_delay(float delay, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1471
std::string get_rotation_mode() const
Returns "Fixed", "Facing", "Wiggling".
Definition: custom_particle_system.cpp:1350
void ease_death_time(float death_time, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1611
bool get_cover_screen() const
Definition: custom_particle_system.cpp:1280
std::string get_birth_mode() const
Returns "None", "Fade", "Shrink".
Definition: custom_particle_system.cpp:1292
void ease_feather_factor(float feather_factor, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1892
float get_acceleration_x() const
Definition: custom_particle_system.cpp:1762
void set_death_time_variation(float death_time_variation)
Definition: custom_particle_system.cpp:1628
void ease_speed_y(float speed_y, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1696
void fade_speed_variation_y(float speed_variation_y, float time)
Definition: custom_particle_system.cpp:1746
void fade_rotation_speed_variation(float rotation_speed_variation, float time)
Definition: custom_particle_system.cpp:1998
virtual void save(Writer &writer) override
This function saves the object.
Definition: custom_particle_system.cpp:397
Definition: reader_mapping.hpp:32
void set_collision_mode(const std::string &mode)
Definition: custom_particle_system.cpp:1401
float get_lifetime() const
Definition: custom_particle_system.cpp:1481
void set_rotation_speed(float rotation_speed)
Definition: custom_particle_system.cpp:1964
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
void fade_friction_x(float friction_x, float time)
Definition: custom_particle_system.cpp:1830
void fade_birth_time(float birth_time, float time)
Definition: custom_particle_system.cpp:1549
void set_death_time(float death_time)
Definition: custom_particle_system.cpp:1599
Definition: writer.cpp:23
void set_rotation_acceleration(float rotation_acceleration)
Definition: custom_particle_system.cpp:2020
float get_speed_variation_y() const
Definition: custom_particle_system.cpp:1734
This class collects data about a collision.
Definition: collision_hit.hpp:44
void set_feather_factor(float feather_factor)
Definition: custom_particle_system.cpp:1880
void ease_lifetime(float lifetime, float time, const std::string &easing)
Definition: custom_particle_system.cpp:1499