24
24
#include " supertux/sector.hpp"
25
25
#include " util/reader_mapping.hpp"
26
26
27
+ constexpr float STICKING_TIME = 0 .7f ;
28
+ constexpr float FADEOUT_TIME = 0 .3f ;
29
+
27
30
Shard::Shard (const ReaderMapping& reader) :
28
31
StickyObject(reader, " images/creatures/crystallo/shard.sprite" , LAYER_TILES - 2 , COLGROUP_MOVING),
29
32
m_physic(),
30
- m_stick_timer()
33
+ m_stick_timer(),
34
+ m_fadeout_timer()
31
35
{
32
36
m_physic.enable_gravity (true );
33
37
SoundManager::current ()->preload (" sounds/crystallo-shardhit.ogg" );
@@ -36,7 +40,8 @@ Shard::Shard(const ReaderMapping& reader) :
36
40
Shard::Shard (const Vector& pos, const Vector& velocity, const std::string& sprite) :
37
41
StickyObject(pos, sprite, LAYER_TILES - 2 , COLGROUP_MOVING),
38
42
m_physic(),
39
- m_stick_timer()
43
+ m_stick_timer(),
44
+ m_fadeout_timer()
40
45
{
41
46
m_physic.enable_gravity (true );
42
47
m_physic.set_velocity (velocity);
@@ -51,8 +56,14 @@ Shard::update(float dt_sec)
51
56
52
57
if (m_physic.get_velocity () != Vector (0 .f , 0 .f ) && !m_sticking)
53
58
m_sprite->set_angle (math::degrees (math::angle (Vector (m_physic.get_velocity_x (), m_physic.get_velocity_y ()))));
59
+
54
60
if (m_stick_timer.check ())
61
+ m_fadeout_timer.start (FADEOUT_TIME);
62
+
63
+ if (m_fadeout_timer.check ())
55
64
remove_me ();
65
+ else if (m_fadeout_timer.started ())
66
+ m_sprite->set_alpha (1 .0f - m_fadeout_timer.get_progress ());
56
67
57
68
m_col.set_movement (m_physic.get_movement (dt_sec));
58
69
@@ -65,16 +76,22 @@ Shard::collision_solid(const CollisionHit& hit)
65
76
m_physic.set_velocity (0 .f , 0 .f );
66
77
m_physic.set_acceleration (0 .f , 0 .f );
67
78
m_physic.enable_gravity (hit.bottom );
79
+ m_sticking = true ;
80
+
68
81
if (!m_stick_timer.started ())
69
82
{
70
- m_stick_timer.start (5 . f );
83
+ m_stick_timer.start (STICKING_TIME );
71
84
SoundManager::current ()->play (" sounds/crystallo-shardhit.ogg" , get_pos ());
72
85
}
73
86
}
74
87
75
88
HitResponse
76
89
Shard::collision (MovingObject& other, const CollisionHit&)
77
90
{
91
+ // Do not hurt anyone while fading out
92
+ if (m_fadeout_timer.started ())
93
+ return ABORT_MOVE;
94
+
78
95
// ignore collisions with other shards
79
96
auto shard = dynamic_cast <Shard*>(&other);
80
97
if (&other == shard)
0 commit comments