Skip to content

Commit b6dc8d7

Browse files
authored
Wind: Add current subtype and fix particle orientation (#3270)
* Wind: Add current subtype and fix particle orientation * Wind: I forgot to delete his TODO lol * Wind: fix float to double conversion * Wind: code style
1 parent 52f2ea8 commit b6dc8d7

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

src/object/sprite_particle.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
SpriteParticle::SpriteParticle(const std::string& sprite_name, const std::string& action,
2828
const Vector& position_, AnchorPoint anchor, const Vector& velocity_, const Vector& acceleration_,
29-
int drawing_layer_, bool notimeout, Color color_) :
29+
int drawing_layer_, bool notimeout, Color color_, float angle) :
3030
SpriteParticle(SpriteManager::current()->create(sprite_name), action,
3131
position_, anchor, velocity_, acceleration_,
3232
drawing_layer_, notimeout, color_)
@@ -46,11 +46,12 @@ SpriteParticle::SpriteParticle(const std::string& sprite_name, const std::string
4646
}
4747
no_time_out = notimeout;
4848
sprite->set_color(color_);
49+
sprite->set_angle(angle);
4950
}
5051

5152
SpriteParticle::SpriteParticle(SpritePtr sprite_, const std::string& action,
5253
const Vector& position_, AnchorPoint anchor, const Vector& velocity_, const Vector& acceleration_,
53-
int drawing_layer_, bool notimeout, Color color_) :
54+
int drawing_layer_, bool notimeout, Color color_, float angle) :
5455
sprite(std::move(sprite_)),
5556
position(position_),
5657
velocity(velocity_),
@@ -64,6 +65,7 @@ SpriteParticle::SpriteParticle(SpritePtr sprite_, const std::string& action,
6465
sprite->set_action(action, 1);
6566
sprite->set_animation_loops(1); //TODO: this is necessary because set_action will not set "loops" when "action" is the default action
6667
sprite->set_color(color_);
68+
sprite->set_angle(angle);
6769

6870
position -= get_anchor_pos(sprite->get_current_hitbox(), anchor);
6971
no_time_out = notimeout;

src/object/sprite_particle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ class SpriteParticle final : public GameObject
3232
SpriteParticle(SpritePtr sprite, const std::string& action,
3333
const Vector& position, AnchorPoint anchor,
3434
const Vector& velocity, const Vector& acceleration,
35-
int drawing_layer = LAYER_OBJECTS-1, bool notimeout = false, Color color = Color::WHITE);
35+
int drawing_layer = LAYER_OBJECTS - 1, bool notimeout = false, Color color = Color::WHITE, float angle = 0);
3636
SpriteParticle(const std::string& sprite_name, const std::string& action,
3737
const Vector& position, AnchorPoint anchor,
3838
const Vector& velocity, const Vector& acceleration,
39-
int drawing_layer = LAYER_OBJECTS-1, bool notimeout = false, Color color = Color::WHITE);
39+
int drawing_layer = LAYER_OBJECTS - 1, bool notimeout = false, Color color = Color::WHITE, float angle = 0);
4040
virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(SpriteParticle)); }
4141
~SpriteParticle() override;
4242

src/object/wind.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Wind::Wind(const ReaderMapping& reader) :
4747
particles_enabled(true)
4848
{
4949
float w,h;
50+
parse_type(reader);
5051
reader.get("x", m_col.m_bbox.get_left(), 0.0f);
5152
reader.get("y", m_col.m_bbox.get_top(), 0.0f);
5253
reader.get("width", w, 32.0f);
@@ -96,6 +97,15 @@ Wind::get_settings()
9697
return result;
9798
}
9899

100+
GameObjectTypes
101+
Wind::get_types() const
102+
{
103+
return {
104+
{ "wind", _("Wind") },
105+
{ "current", _("Current") }
106+
};
107+
}
108+
99109
void
100110
Wind::update(float dt_sec_)
101111
{
@@ -107,19 +117,26 @@ Wind::update(float dt_sec_)
107117
Vector ppos = Vector(graphicsRandom.randf(m_col.m_bbox.get_left() + 8, m_col.m_bbox.get_right() - 8), graphicsRandom.randf(m_col.m_bbox.get_top() + 8, m_col.m_bbox.get_bottom() - 8));
108118
Vector pspeed = Vector(graphicsRandom.randf(speed.x - 20, speed.x + 20), graphicsRandom.randf(speed.y - 20, speed.y + 20));
109119

110-
// TODO: Rotate sprite rather than just use 2 different actions
111120
// Approx. 1 particle per tile
112121
if (graphicsRandom.randf(0.f, 100.f) < (m_col.m_bbox.get_width() / 32.f) * (m_col.m_bbox.get_height() / 32.f))
113122
{
114123
// Emit a particle
115-
if (fancy_wind)
124+
if (fancy_wind)
116125
{
117-
Sector::get().add<SpriteParticle>("images/particles/wind.sprite", (std::abs(speed.x) > std::abs(speed.y)) ? "default" : "flip", ppos, ANCHOR_MIDDLE, pspeed, Vector(0, 0), m_layer);
118-
}
119-
else
126+
const float angle = std::atan2(speed.y, speed.x) * float(180.0 / M_PI);
127+
switch (m_type) {
128+
case WIND: // Normal wind
129+
Sector::get().add<SpriteParticle>("images/particles/wind.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, Vector(0, 0), m_layer, false, Color::WHITE, angle);
130+
break;
131+
case CURRENT: // Current variant
132+
Sector::get().add<SpriteParticle>("images/particles/water_piece1.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, Vector(0, 0), m_layer, false, Color::WHITE, angle);
133+
break;
134+
}
135+
}
136+
else
120137
{
121-
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0, 0), 1, Color(.4f, .4f, .4f), 3, .1f, m_layer);
122-
}
138+
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0, 0), 1, Color(.4f, .4f, .4f), 3, .1f, m_layer);
139+
}
123140
}
124141
}
125142

src/object/wind.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class Wind final : public MovingObject
4545
virtual GameObjectClasses get_class_types() const override { return MovingObject::get_class_types().add(typeid(Wind)); }
4646

4747
virtual ObjectSettings get_settings() override;
48-
48+
virtual GameObjectTypes get_types() const override;
49+
4950
virtual void on_flip(float height) override;
5051

5152
/**
@@ -85,6 +86,11 @@ class Wind final : public MovingObject
8586
bool fancy_wind;
8687
bool particles_enabled;
8788

89+
enum Type {
90+
WIND,
91+
CURRENT,
92+
};
93+
8894
private:
8995
Wind(const Wind&) = delete;
9096
Wind& operator=(const Wind&) = delete;

0 commit comments

Comments
 (0)