Skip to content

Commit 0a84620

Browse files
Rework shard behavior (#3170)
* Rework shard behavior * Decrease time the shards are active * Fadeout shards when becoming inactive Fixes #3134
1 parent c210829 commit 0a84620

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/object/shard.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
#include "supertux/sector.hpp"
2525
#include "util/reader_mapping.hpp"
2626

27+
constexpr float STICKING_TIME = 0.7f;
28+
constexpr float FADEOUT_TIME = 0.3f;
29+
2730
Shard::Shard(const ReaderMapping& reader) :
2831
StickyObject(reader, "images/creatures/crystallo/shard.sprite", LAYER_TILES - 2, COLGROUP_MOVING),
2932
m_physic(),
30-
m_stick_timer()
33+
m_stick_timer(),
34+
m_fadeout_timer()
3135
{
3236
m_physic.enable_gravity(true);
3337
SoundManager::current()->preload("sounds/crystallo-shardhit.ogg");
@@ -36,7 +40,8 @@ Shard::Shard(const ReaderMapping& reader) :
3640
Shard::Shard(const Vector& pos, const Vector& velocity, const std::string& sprite) :
3741
StickyObject(pos, sprite, LAYER_TILES - 2, COLGROUP_MOVING),
3842
m_physic(),
39-
m_stick_timer()
43+
m_stick_timer(),
44+
m_fadeout_timer()
4045
{
4146
m_physic.enable_gravity(true);
4247
m_physic.set_velocity(velocity);
@@ -51,8 +56,14 @@ Shard::update(float dt_sec)
5156

5257
if (m_physic.get_velocity() != Vector(0.f, 0.f) && !m_sticking)
5358
m_sprite->set_angle(math::degrees(math::angle(Vector(m_physic.get_velocity_x(), m_physic.get_velocity_y()))));
59+
5460
if (m_stick_timer.check())
61+
m_fadeout_timer.start(FADEOUT_TIME);
62+
63+
if (m_fadeout_timer.check())
5564
remove_me();
65+
else if (m_fadeout_timer.started())
66+
m_sprite->set_alpha(1.0f - m_fadeout_timer.get_progress());
5667

5768
m_col.set_movement(m_physic.get_movement(dt_sec));
5869

@@ -65,16 +76,22 @@ Shard::collision_solid(const CollisionHit& hit)
6576
m_physic.set_velocity(0.f, 0.f);
6677
m_physic.set_acceleration(0.f, 0.f);
6778
m_physic.enable_gravity(hit.bottom);
79+
m_sticking = true;
80+
6881
if (!m_stick_timer.started())
6982
{
70-
m_stick_timer.start(5.f);
83+
m_stick_timer.start(STICKING_TIME);
7184
SoundManager::current()->play("sounds/crystallo-shardhit.ogg", get_pos());
7285
}
7386
}
7487

7588
HitResponse
7689
Shard::collision(MovingObject& other, const CollisionHit&)
7790
{
91+
// Do not hurt anyone while fading out
92+
if (m_fadeout_timer.started())
93+
return ABORT_MOVE;
94+
7895
// ignore collisions with other shards
7996
auto shard = dynamic_cast<Shard*>(&other);
8097
if (&other == shard)

src/object/shard.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Shard final : public StickyObject
4141

4242
private:
4343
Timer m_stick_timer;
44+
Timer m_fadeout_timer;
4445

4546
private:
4647
Shard(const Shard&) = delete;

0 commit comments

Comments
 (0)