Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wind: Affect Tux on ground + Fancy Particles Option #1493

Merged
merged 11 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added data/images/particles/wind.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions data/images/particles/wind.sprite
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(supertux-sprite
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please check the indentation of this file and fix it (because if we merge it now, this won't happen)

Oh, and add [ci skip] after your commit message so that we don't waste unnecessary integration cycles.

(action
(name "default")
(hitbox 0 0 63 3)
(loops 1)
(fps 15)
(images "wind3.png"
"wind2.png"
"wind.png"
"wind.png"
"wind2.png"
"wind3.png")
)
(action
(name "flip")
(hitbox 0 0 3 63)
(loops 1)
(fps 15)
(images "windup3.png"
"windup2.png"
"windup.png"
"windup.png"
"windup2.png"
"windup3.png")
)
)
Binary file added data/images/particles/wind2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/particles/wind3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/particles/windup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/particles/windup2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/particles/windup3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 43 additions & 15 deletions src/object/wind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "math/random.hpp"
#include "object/particles.hpp"
#include "object/player.hpp"
#include "object/sprite_particle.hpp"
#include "sprite/sprite.hpp"
#include "sprite/sprite_manager.hpp"
#include "supertux/sector.hpp"
#include "util/reader_mapping.hpp"
#include "video/drawing_context.hpp"
Expand All @@ -33,7 +36,8 @@ Wind::Wind(const ReaderMapping& reader) :
acceleration(),
new_size(),
dt_sec(0),
affects_badguys()
affects_badguys(),
fancy_wind()
{
float w,h;
reader.get("x", m_col.m_bbox.get_left(), 0.0f);
Expand All @@ -50,6 +54,8 @@ Wind::Wind(const ReaderMapping& reader) :
reader.get("acceleration", acceleration, 100.0f);

reader.get("affects-badguys", affects_badguys, false);

reader.get("fancy-wind", fancy_wind, false);

set_group(COLGROUP_TOUCHABLE);
}
Expand All @@ -69,8 +75,9 @@ Wind::get_settings()
result.add_float(_("Acceleration"), &acceleration, "acceleration");
result.add_bool(_("Blowing"), &blowing, "blowing", true);
result.add_bool(_("Affects Badguys"), &affects_badguys, "affects-badguys", false);
result.add_bool(_("Fancy Particles"), &fancy_wind, "fancy-wind", false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about what others might think, but I consider the name "Fancy Particles" to not be verbose enough.


result.reorder({"blowing", "speed-x", "speed-y", "acceleration", "affects-badguys", "region", "name", "x", "y"});
result.reorder({"blowing", "speed-x", "speed-y", "acceleration", "affects-badguys", "fancy-wind", "region", "name", "x", "y"});

return result;
}
Expand All @@ -83,13 +90,22 @@ Wind::update(float dt_sec_)
if (!blowing) return;
if (m_col.m_bbox.get_width() <= 16 || m_col.m_bbox.get_height() <= 16) return;

// TODO: nicer, configurable particles for wind?
if (graphicsRandom.rand(0, 100) < 20) {
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));
Vector pspeed = Vector(graphicsRandom.randf(speed.x-20, speed.x+20), graphicsRandom.randf(speed.y-20, speed.y+20));

// TODO: Rotate sprite rather than just use 2 different actions
// Approx. 1 particle per tile
if (graphicsRandom.randf(0.f, 100.f) < (m_col.m_bbox.get_width() / 32.f) * (m_col.m_bbox.get_height() / 32.f))
{
// emit a particle
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));
Vector pspeed = Vector(speed.x, speed.y);
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f,
LAYER_BACKGROUNDTILES+1);
if (fancy_wind)
{
Sector::get().add<SpriteParticle>("images/particles/wind.sprite", (abs(speed.x) > abs(speed.y)) ? "default" : "flip", ppos, ANCHOR_MIDDLE, pspeed, Vector(0, 0), LAYER_BACKGROUNDTILES+1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if maybe you should move the (abs(speed.x) > abs(speed.y)) ? "default" : "flip" into its own variable. The line is quite long. Also, add spaces around the +

Yes, sorry for being mean and stricter than necessary, but that's just me being a good code reviewer. No hard feelings.

}
else
{
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f, LAYER_BACKGROUNDTILES+1);
}
}
}

Expand All @@ -108,17 +124,29 @@ Wind::collision(GameObject& other, const CollisionHit& )
if (!blowing) return ABORT_MOVE;

auto player = dynamic_cast<Player*> (&other);
if (player) {
if (!player->on_ground()) {
if (player)
{
if (!player->on_ground())
{
player->add_velocity(speed * acceleration * dt_sec, speed);
}
else
{
if (player->get_controller().hold(Control::RIGHT) || player->get_controller().hold(Control::LEFT))
{
player->add_velocity(Vector(speed.x, 0) * acceleration * dt_sec, speed);
}
else
{
//When on ground, get blown slightly differently, but the max speed is less than it would be otherwise seen as we take "friction" into account
player->add_velocity((Vector(speed.x, 0) * 0.1f) * (acceleration+1), (Vector(speed.x, speed.y) * 0.5f));
}
}
}

auto badguy = dynamic_cast<BadGuy*> (&other);
if (badguy && this->affects_badguys) {
if (badguy->can_be_affected_by_wind()) {
badguy->add_wind_velocity(speed * acceleration * dt_sec, speed);
}
if (badguy && this->affects_badguys && badguy->can_be_affected_by_wind())
{
badguy->add_wind_velocity(speed * acceleration * dt_sec, speed);
}

return ABORT_MOVE;
Expand Down
1 change: 1 addition & 0 deletions src/object/wind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Wind final :
float dt_sec; /**< stores last dt_sec gotten at update() */

bool affects_badguys; /**< whether the wind can affect badguys */
bool fancy_wind;

private:
Wind(const Wind&) = delete;
Expand Down